6.7.0 - Alpha6 - 重构 scrapers 工具并增加中英双语注释内容

This commit is contained in:
SuperMonster003
2025-09-24 16:01:46 +08:00
parent ef076d1cf8
commit c1ee107bc3
25 changed files with 1512 additions and 1072 deletions

View File

@@ -3,9 +3,41 @@
/**
* @param {number | null} bytes
* @param {number} [fractionDigits=2]
* @returns {string | null}
*/
export function bytes2GiB(bytes, fractionDigits = 2) {
if (bytes == null) return null;
const gib = bytes / 1024 ** 3;
return `${gib.toFixed(fractionDigits)} GiB`;
}
}
/**
* Constructs a URL with query parameters.<br>
* zh-CN: 使用查询参数构造 URL.
*
* @example
* // https://example.com?a=1&b=2
* url('https://example.com', { a: 1, b: 2 });
*
* @param {string} url
* @param {Object} query
* @returns {string}
*/
export function buildUrl(url, query) {
if (!query) return url;
const q = Object.entries(query)
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
.join('&');
return `${url}?${q}`;
}
/**
* @example
* "Up | Down ?" -> "Up \| Down \?"
*
* @param {string} string
* @returns {string}
*/
export function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|\[\]\\]/g, '\\$&');
}