// fetch-and-parse-android-releases.mjs
import * as cheerio from 'cheerio';
import fetch from 'node-fetch';
import { fileURLToPath } from 'node:url';
const versionCodeBlacklist = [ 'CUR_DEVELOPMENT' ];
const WIKI_URL = 'https://en.wikipedia.org/wiki/Android_version_history';
const ANDROID_VC_URL = 'https://developer.android.com/reference/android/os/Build.VERSION_CODES';
const norm = (/** @type {string} */ s) => (s ?? '').trim().replace(/\s+/g, ' ');
const trimAndNormDash = (/** @type {string} */ s) => s.replace(/\s*[\u002d\u2013\u2014](\s*N\/A)?\s*/ig, '-');
const stripSupportPrefix = (/** @type {string} */ s) => s.replace(/^(un)?supported:\s*/ig, '');
const handleCsvEmptyString = (/** @type {string} */ s) => /^-?$/.test(s) ? '""' : s;
/**
* @param {AndroidReleaseCsv} o
* @returns {AndroidReleaseCsv}
*/
function quoteIfNeeded(o) {
Object.keys(o).forEach((k) => {
if (typeof o[k] === 'string') {
o[k] = handleCsvEmptyString(o[k]);
}
});
return o;
}
/**
* Remove style, script, and sup.reference elements before getting text.
* zh-CN: 获取文本前, 先移除 style, script 及 sup.reference.
*
* @param {Cheerio} cell
* @returns {string}
*/
function cleanCell(cell) {
const cloned = cell.clone();
cloned.find('style,script,sup.reference,span.sr-only').remove();
return cloned.text().trim().replace(/\s+/g, ' ');
}
/**
* Fetch official VERSION_CODE and API_LEVEL from Android documentation.
* zh-CN: 抓取官方 VERSION_CODE 与 API_LEVEL.
*
* @example Map
* @returns {Promise