mirror of
https://github.com/Mibew/simple-icons.git
synced 2025-01-31 22:34:45 +03:00
Resolve all possible TODO comments (#11119)
This commit is contained in:
parent
236f5fc715
commit
512e4cbf4a
@ -41,6 +41,14 @@ const iconObjectTemplateFile = path.resolve(
|
|||||||
'icon-object.js.template',
|
'icon-object.js.template',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merged type from icon data and icon JS object needed to build by reference
|
||||||
|
* to not decrease performance in the build process.
|
||||||
|
* @typedef {import('../../types.js').SimpleIcon & import('../../sdk.d.ts').IconData} IconDataAndObject
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @type {IconDataAndObject[]} */
|
||||||
|
// @ts-ignore
|
||||||
const icons = await getIconsData();
|
const icons = await getIconsData();
|
||||||
const iconObjectTemplate = await fs.readFile(iconObjectTemplateFile, UTF8);
|
const iconObjectTemplate = await fs.readFile(iconObjectTemplateFile, UTF8);
|
||||||
|
|
||||||
@ -64,8 +72,11 @@ const licenseToObject = (license) => {
|
|||||||
return license;
|
return license;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Find a way to type this object without decreasing performance
|
/**
|
||||||
// @ts-ignore
|
* Converts an icon object to a JavaScript object.
|
||||||
|
* @param {IconDataAndObject} icon The icon object
|
||||||
|
* @returns {string} The JavaScript object
|
||||||
|
*/
|
||||||
const iconToJsObject = (icon) => {
|
const iconToJsObject = (icon) => {
|
||||||
return util.format(
|
return util.format(
|
||||||
iconObjectTemplate,
|
iconObjectTemplate,
|
||||||
@ -106,10 +117,7 @@ const build = async () => {
|
|||||||
icons.map(async (icon) => {
|
icons.map(async (icon) => {
|
||||||
const filename = getIconSlug(icon);
|
const filename = getIconSlug(icon);
|
||||||
const svgFilepath = path.resolve(iconsDirectory, `${filename}.svg`);
|
const svgFilepath = path.resolve(iconsDirectory, `${filename}.svg`);
|
||||||
// TODO: Find a way to type these objects without decreasing performance
|
|
||||||
// @ts-ignore
|
|
||||||
icon.svg = await fs.readFile(svgFilepath, UTF8);
|
icon.svg = await fs.readFile(svgFilepath, UTF8);
|
||||||
// @ts-ignore
|
|
||||||
icon.path = svgToPath(icon.svg);
|
icon.path = svgToPath(icon.svg);
|
||||||
icon.slug = filename;
|
icon.slug = filename;
|
||||||
const iconObject = iconToJsObject(icon);
|
const iconObject = iconToJsObject(icon);
|
||||||
|
@ -98,19 +98,21 @@ const TESTS = {
|
|||||||
|
|
||||||
const allUrlFields = [
|
const allUrlFields = [
|
||||||
...new Set(
|
...new Set(
|
||||||
data.icons
|
data.icons.flatMap((icon) => {
|
||||||
.flatMap((icon) => {
|
/** @type {string[]} */
|
||||||
// TODO: `Omit` is not working smoothly here
|
const license =
|
||||||
const license =
|
icon.license !== undefined && Object.hasOwn(icon.license, 'url')
|
||||||
// @ts-ignore
|
? [
|
||||||
icon.license && icon.license.url
|
// TODO: `hasOwn` is not currently supported by TS.
|
||||||
? // @ts-ignore
|
// See https://github.com/microsoft/TypeScript/issues/44253
|
||||||
[icon.license.url]
|
/** @type {string} */
|
||||||
: [];
|
// @ts-ignore
|
||||||
return [icon.source, icon.guidelines, ...license];
|
icon.license.url,
|
||||||
})
|
]
|
||||||
|
: [];
|
||||||
.filter(Boolean),
|
const guidelines = icon.guidelines ? [icon.guidelines] : [];
|
||||||
|
return [icon.source, ...guidelines, ...license];
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -163,6 +163,14 @@ const maybeShortenedWithEllipsis = (string_) => {
|
|||||||
return string_.length > 20 ? `${string_.slice(0, 20)}...` : string_;
|
return string_.length > 20 ? `${string_.slice(0, 20)}...` : string_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a string is a number.
|
||||||
|
* @param {string} string_ The string to check.
|
||||||
|
* @returns {boolean} Whether the string is a number.
|
||||||
|
*/
|
||||||
|
const isNumber = (string_) =>
|
||||||
|
[...string_].every((character) => '0123456789'.includes(character));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Memoize a function which accepts a single argument.
|
* Memoize a function which accepts a single argument.
|
||||||
* A second argument can be passed to be used as key.
|
* A second argument can be passed to be used as key.
|
||||||
@ -367,7 +375,7 @@ const config = {
|
|||||||
} else {
|
} else {
|
||||||
// Encode all non ascii characters plus "'&<> (XML named entities)
|
// Encode all non ascii characters plus "'&<> (XML named entities)
|
||||||
/** @type {number} */
|
/** @type {number} */
|
||||||
// @ts-ignore Coerce to number
|
// @ts-ignore
|
||||||
const charDecimalCode = iconTitleText.codePointAt(i);
|
const charDecimalCode = iconTitleText.codePointAt(i);
|
||||||
|
|
||||||
if (charDecimalCode > 127) {
|
if (charDecimalCode > 127) {
|
||||||
@ -398,12 +406,10 @@ const config = {
|
|||||||
|
|
||||||
// Check if there are some other encoded characters in decimal notation
|
// Check if there are some other encoded characters in decimal notation
|
||||||
// which shouldn't be encoded
|
// which shouldn't be encoded
|
||||||
for (const match of encodingMatches.filter((m) => {
|
const numberMatches = encodingMatches.filter(
|
||||||
// TODO: this fails using `Number.isNaN`, investigate
|
(m) => m[2] !== undefined && isNumber(m[2]),
|
||||||
// @ts-ignore
|
);
|
||||||
// eslint-disable-next-line unicorn/prefer-number-properties
|
for (const match of numberMatches) {
|
||||||
return !isNaN(m[2]);
|
|
||||||
})) {
|
|
||||||
const decimalNumber = Number.parseInt(match[2], 10);
|
const decimalNumber = Number.parseInt(match[2], 10);
|
||||||
if (decimalNumber > 127) {
|
if (decimalNumber > 127) {
|
||||||
continue;
|
continue;
|
||||||
@ -514,7 +520,7 @@ const config = {
|
|||||||
const segments = getIconPathSegments(iconPath);
|
const segments = getIconPathSegments(iconPath);
|
||||||
|
|
||||||
/** @type {import('svg-path-segments').Segment[]} */
|
/** @type {import('svg-path-segments').Segment[]} */
|
||||||
// TODO: svgpath does not includes the segment property on the interface,
|
// TODO: svgpath does not includes the `segments` property on the interface,
|
||||||
// see https://github.com/fontello/svgpath/pull/67/files
|
// see https://github.com/fontello/svgpath/pull/67/files
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const absSegments = svgpath(iconPath).abs().unshort().segments;
|
const absSegments = svgpath(iconPath).abs().unshort().segments;
|
||||||
|
@ -64,7 +64,6 @@ export const testIcon = (icon, subject, slug) => {
|
|||||||
if (icon.license) {
|
if (icon.license) {
|
||||||
assert.equal(subject.license?.type, icon.license.type);
|
assert.equal(subject.license?.type, icon.license.type);
|
||||||
if (icon.license.type === 'custom') {
|
if (icon.license.type === 'custom') {
|
||||||
// TODO: `Omit` not working smoothly here
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
assert.equal(subject.license.url, icon.license.url);
|
assert.equal(subject.license.url, icon.license.url);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user