diff --git a/.svglintrc.mjs b/.svglintrc.mjs index 85fbd6cc..4733e2a2 100644 --- a/.svglintrc.mjs +++ b/.svglintrc.mjs @@ -3,6 +3,7 @@ import path from 'node:path'; import { getDirnameFromImportMeta, htmlFriendlyToTitle, + collator, } from './scripts/utils.js'; import svgpath from 'svgpath'; import svgPathBbox from 'svg-path-bbox'; @@ -46,7 +47,7 @@ const sortObjectByKey = (obj) => { const sortObjectByValue = (obj) => { return Object.keys(obj) - .sort((a, b) => ('' + obj[a]).localeCompare(obj[b])) + .sort((a, b) => collator.compare(obj[a], obj[b])) .reduce((r, k) => Object.assign(r, { [k]: obj[k] }), {}); }; diff --git a/scripts/build/package.js b/scripts/build/package.js index bfd4ece3..9c781b4e 100644 --- a/scripts/build/package.js +++ b/scripts/build/package.js @@ -18,6 +18,7 @@ import { slugToVariableName, getIconsData, getDirnameFromImportMeta, + collator, } from '../utils.js'; const __dirname = getDirnameFromImportMeta(import.meta.url); @@ -98,7 +99,8 @@ const build = async () => { const iconsBarrelJs = []; const iconsBarrelMjs = []; - buildIcons.forEach(({ icon, iconObject, iconExportName }) => { + buildIcons.sort((a, b) => collator.compare(a.icon.title, b.icon.title)); + buildIcons.forEach(({ iconObject, iconExportName }) => { iconsBarrelDts.push(`export const ${iconExportName}:I;`); iconsBarrelJs.push(`${iconExportName}:${iconObject},`); iconsBarrelMjs.push(`export const ${iconExportName}=${iconObject}`); diff --git a/scripts/lint/ourlint.js b/scripts/lint/ourlint.js index 677775a4..39d48ea7 100644 --- a/scripts/lint/ourlint.js +++ b/scripts/lint/ourlint.js @@ -6,7 +6,7 @@ */ import fakeDiff from 'fake-diff'; -import { getIconsDataString, normalizeNewlines } from '../utils.js'; +import { getIconsDataString, normalizeNewlines, collator } from '../utils.js'; /** * Contains our tests so they can be isolated from each other. @@ -18,12 +18,12 @@ const TESTS = { const collector = (invalidEntries, icon, index, array) => { if (index > 0) { const prev = array[index - 1]; - const compare = icon.title.localeCompare(prev.title); - if (compare < 0) { + const comparison = collator.compare(icon.title, prev.title); + if (comparison < 0) { invalidEntries.push(icon); - } else if (compare === 0) { + } else if (comparison === 0) { if (prev.slug) { - if (!icon.slug || icon.slug.localeCompare(prev.slug) < 0) { + if (!icon.slug || collator.compare(icon.slug, prev.slug) < 0) { invalidEntries.push(icon); } } diff --git a/scripts/utils.js b/scripts/utils.js index db0fed58..7ffae8a9 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -153,3 +153,13 @@ export const getThirdPartyExtensions = async (readmePath) => }, }; }); + +/** + * `Intl.Collator` object ready to be used for icon titles sorting. + * @type {Intl.Collator} + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator + **/ +export const collator = new Intl.Collator('en', { + usage: 'search', + caseFirst: 'upper', +});