Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(cli): experimental icon sets — keep the library prefix on a name that starts with a digit (#10895)

Joeyc0327e060d77
diff --git a/.changeset/icon-sets-digit-export-names.md b/.changeset/icon-sets-digit-export-names.md
new file mode 100644
index 0000000000..52b6f7c836
--- /dev/null
+++ b/.changeset/icon-sets-digit-export-names.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[experimental] Icon sets: an icon whose name would start with a digit once the library prefix comes off, such as a library's `fa0`, now keeps that prefix: it gets id `fa-0` and is exported as `Fa0Icon` (`fa500px` becomes `Fa500pxIcon`). The CLI wrote `0Icon` before, which is not a valid JavaScript name, so the generated module did not parse. An id you give that starts with a digit, with no prefix to keep, is refused with a message that asks for an id that starts with a letter. Only `experimental icon new-set --from` and `experimental icon add` change; a set they write now passes `integration check`.
+@josephfarina
diff --git a/docs/specs/AST-084-icon-sets/spec.md b/docs/specs/AST-084-icon-sets/spec.md
index 05b8eeb5ac..9abc73b766 100644
--- a/docs/specs/AST-084-icon-sets/spec.md
+++ b/docs/specs/AST-084-icon-sets/spec.md
@@ -293,7 +293,11 @@ icon, and the CLI verifies it, writes the files, and checks the set.
an icon exported under several names is recorded once, its other names
as words; `…Provider` and `…Context` components
are never icons; and `--exclude` adds exports that are not icons to the
- data file's `exclude`, which every refresh honors. From an installed
+ data file's `exclude`, which every refresh honors. An icon whose id
+ would start with a digit once the shared prefix comes off keeps the
+ prefix (`fa0` is id `fa-0`, exported as `Fa0Icon`), and an id that
+ starts with a digit with no prefix to keep is refused with
+ `ERR_INVALID_ARGUMENT`. From an installed
package it records `source` (the library and version), copies the
library's license notices into the set, and takes the library's license
for the descriptor; when the library ships none and the set and package
diff --git a/packages/cli/api/icon/add/add.mjs b/packages/cli/api/icon/add/add.mjs
index 0bf0ec6bdd..19d26b861a 100644
--- a/packages/cli/api/icon/add/add.mjs
+++ b/packages/cli/api/icon/add/add.mjs
@@ -147,6 +147,15 @@ export async function iconAdd(exportName, options) {
);
}
}
+ // An export name cannot start with a digit, and an id the author gives has
+ // no library prefix to keep.
+ if (givenId != null && /^[0-9]/u.test(givenId)) {
+ throw new AstryxError(
+ `The icon id "${givenId}" starts with a digit, and an export name cannot. Pass --id with an id that starts with a letter.`,
+ undefined,
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
+ );
+ }
if (all) {
return authoring(() => addVariantForAll({cwd, from, selector, variant}));
}
diff --git a/packages/cli/api/icon/iconAdd.doc.mjs b/packages/cli/api/icon/iconAdd.doc.mjs
index 5b2fdd5f44..83d21bee0f 100644
--- a/packages/cli/api/icon/iconAdd.doc.mjs
+++ b/packages/cli/api/icon/iconAdd.doc.mjs
@@ -119,7 +119,7 @@ export const doc = {
},
{
code: 'ERR_INVALID_ARGUMENT',
- when: "the export is data rather than a component, a new definition is named like an Astryx one, or the variant is not one the set declares, is the look each icon's own export already draws, or is no look word of a library whose export names encode looks",
+ when: "the export is data rather than a component, a new definition is named like an Astryx one, or the variant is not one the set declares, is the look each icon's own export already draws, or is no look word of a library whose export names encode looks, or `id` starts with a digit",
},
{code: 'ERR_FILE_EXISTS', when: 'another icon already has the id'},
{
diff --git a/packages/cli/assets/docs/tree/icon-sets.doc.mjs b/packages/cli/assets/docs/tree/icon-sets.doc.mjs
index 5381b98c71..f24394111a 100644
--- a/packages/cli/assets/docs/tree/icon-sets.doc.mjs
+++ b/packages/cli/assets/docs/tree/icon-sets.doc.mjs
@@ -121,7 +121,7 @@ export const docs = {
},
{
type: 'prose',
- text: "Every component the library exports becomes an icon (an alias of one component is recorded once), named `<Name>Icon`, with an id from its name (`Squares2X2Icon` is `squares-2x2`: a dimension stays one word). `map` is filled only where a definition's name is an icon's id (`delete` → icon `delete`), and the receipt lists those entries under Mapped by name: a library can draw another meaning under the same name (one library's `delete` is a backspace key), so check each. An icon whose id is only one of a definition's words (`trash` for `delete`) may mean something else in this library, so the receipt lists it under Suggestions, with the `experimental icon map <definition> <icon>` command for each, and writes nothing for it: check the meaning, then run the ones that fit. Run it again after a library release to refresh the icons that library supplies; `map` entries whose icon still exists are kept, and the receipt names any icon the library dropped, any icon `--exclude` left out, and the `map` entries each took with it. Icons you added from your own files or another library are left as they are. Icons you added one file at a time from the same package (`--from <package>/dist/XIcon`) move to the root import when you refresh from the package root and the root exports the same icon; each keeps its id, export, `map` entries, variants, and words on that refresh and every later one, and the receipt lists it under `moved`. A library icon whose id or name a moved icon already has is left out. When another icon of the set already reads the same root export, the icon stays on its own file, and the receipt says why. An icon you already have is known by the library export it re-exports, so it keeps its export name exactly, its `map` entries, variants, and words, even when a newer CLI spells its id differently or your `--exclude` lets a library prefix come off new ids; the receipt lists each changed id under `renamed`. An id you chose that is not a spelling of the library name (`dismiss` for `XIcon`) is kept. A refresh with `--dry-run` writes nothing and prints the Mapped by name and Suggestions lists again; `--display-name` and `--description` on a refresh rewrite the descriptor. Variants added with `add --variant … --all` are kept too; run that `add` again to pick up icons the release added. `experimental icon --list` shows how many definitions the set maps.",
+ text: "Every component the library exports becomes an icon (an alias of one component is recorded once), named `<Name>Icon`, with an id from its name (`Squares2X2Icon` is `squares-2x2`: a dimension stays one word). An export name cannot start with a digit, so an icon whose id would start with one once the library prefix comes off keeps the prefix (`fa0` is id `fa-0`, exported as `Fa0Icon`), and an id you give with `--id` must start with a letter. `map` is filled only where a definition's name is an icon's id (`delete` → icon `delete`), and the receipt lists those entries under Mapped by name: a library can draw another meaning under the same name (one library's `delete` is a backspace key), so check each. An icon whose id is only one of a definition's words (`trash` for `delete`) may mean something else in this library, so the receipt lists it under Suggestions, with the `experimental icon map <definition> <icon>` command for each, and writes nothing for it: check the meaning, then run the ones that fit. Run it again after a library release to refresh the icons that library supplies; `map` entries whose icon still exists are kept, and the receipt names any icon the library dropped, any icon `--exclude` left out, and the `map` entries each took with it. Icons you added from your own files or another library are left as they are. Icons you added one file at a time from the same package (`--from <package>/dist/XIcon`) move to the root import when you refresh from the package root and the root exports the same icon; each keeps its id, export, `map` entries, variants, and words on that refresh and every later one, and the receipt lists it under `moved`. A library icon whose id or name a moved icon already has is left out. When another icon of the set already reads the same root export, the icon stays on its own file, and the receipt says why. An icon you already have is known by the library export it re-exports, so it keeps its export name exactly, its `map` entries, variants, and words, even when a newer CLI spells its id differently or your `--exclude` lets a library prefix come off new ids; the receipt lists each changed id under `renamed`. An id you chose that is not a spelling of the library name (`dismiss` for `XIcon`) is kept. A refresh with `--dry-run` writes nothing and prints the Mapped by name and Suggestions lists again; `--display-name` and `--description` on a refresh rewrite the descriptor. Variants added with `add --variant … --all` are kept too; run that `add` again to pick up icons the release added. `experimental icon --list` shows how many definitions the set maps.",
},
{
type: 'prose',
diff --git a/packages/cli/clients/cli/commands/icon-digit-names.test.mjs b/packages/cli/clients/cli/commands/icon-digit-names.test.mjs
new file mode 100644
index 0000000000..420208b449
--- /dev/null
+++ b/packages/cli/clients/cli/commands/icon-digit-names.test.mjs
@@ -0,0 +1,380 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Icon sets over library exports whose names start with a digit once
+ * the library prefix comes off (`fa0`, `Digit1Icon`): such an icon keeps the
+ * prefix, every export name the CLI writes is a valid JavaScript name, and
+ * the set passes the strict check. An id given with a leading digit is
+ * refused.
+ */
+
+import * as fs from 'node:fs';
+import * as os from 'node:os';
+import * as path from 'node:path';
+import {parse} from '@babel/parser';
+import {afterEach, beforeEach, describe, expect, it} from 'vitest';
+import {runCli} from '../../../test-utils/run-cli.mjs';
+import {ICON_NAMES} from '../../../authoring/doctypes/icon-set/icon-names.mjs';
+
+/** @type {string} */
+let tmp;
+/** @type {string} */
+let pkg;
+
+const IDENTIFIER_RE = /^[$A-Z_a-z][$\w]*$/u;
+
+/**
+ * Write a library under node_modules, with a license file.
+ * @param {string} name
+ * @param {string} source its index.js
+ */
+function writeLibrary(name, source) {
+ const lib = path.join(pkg, 'node_modules', ...name.split('/'));
+ fs.mkdirSync(lib, {recursive: true});
+ fs.writeFileSync(
+ path.join(lib, 'package.json'),
+ JSON.stringify({
+ name,
+ version: '1.0.0',
+ license: 'MIT',
+ type: 'module',
+ exports: {'.': './index.js'},
+ }),
+ );
+ fs.writeFileSync(path.join(lib, 'LICENSE'), 'MIT License\n');
+ fs.writeFileSync(path.join(lib, 'index.js'), source);
+}
+
+beforeEach(() => {
+ tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-icon-digits-'));
+ pkg = path.join(tmp, 'icons');
+ fs.mkdirSync(path.join(pkg, 'src'), {recursive: true});
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(
+ {
+ name: '@acme/icons',
+ version: '1.0.0',
+ license: 'MIT',
+ type: 'module',
+ exports: {'.': './index.js'},
+ dependencies: {
+ '@acme/glyph-data': '^1.0.0',
+ '@acme/digits': '^1.0.0',
+ '@acme/more-digits': '^1.0.0',
+ '@acme/both-digits': '^1.0.0',
+ '@acme/brand-data': '^1.0.0',
+ },
+ },
+ null,
+ 2,
+ ),
+ );
+ fs.writeFileSync(
+ path.join(pkg, 'src', 'adapt.js'),
+ 'export function adapt(data) { return () => null; }\n',
+ );
+ writeLibrary(
+ '@acme/glyph-data',
+ [
+ "export const fa0 = {prefix: 'fas', iconName: '0', icon: [320, 512, [], '30', 'M0 0']};",
+ "export const fa1 = {prefix: 'fas', iconName: '1', icon: [320, 512, [], '31', 'M0 1']};",
+ "export const fa42Group = {prefix: 'fab', iconName: '42-group', icon: [640, 512, [], 'e080', 'M0 2']};",
+ "export const fa500px = {prefix: 'fab', iconName: '500px', icon: [448, 512, [], 'f26e', 'M0 3']};",
+ "export const faXmark = {prefix: 'fas', iconName: 'xmark', icon: [384, 512, [], 'f00d', 'M1 1']};",
+ "export const faHouse = {prefix: 'fas', iconName: 'house', icon: [576, 512, [], 'f015', 'M2 2']};",
+ '',
+ ].join('\n'),
+ );
+ writeLibrary(
+ '@acme/digits',
+ [
+ 'export function Digit1Icon(props) { return null; }',
+ 'export function Digit2Icon(props) { return null; }',
+ '',
+ ].join('\n'),
+ );
+ writeLibrary(
+ '@acme/more-digits',
+ 'export function Digit1Icon(props) { return null; }\nexport function StarIcon(props) { return null; }\n',
+ );
+ writeLibrary(
+ '@acme/both-digits',
+ [
+ "export const fa0 = {prefix: 'fas', iconName: '0', icon: [320, 512, [], '30', 'M0 0']};",
+ "export const faDigit0 = {prefix: 'fas', iconName: 'digit-0', icon: [320, 512, [], 'e0a0', 'M0 1']};",
+ "export const faXmark = {prefix: 'fas', iconName: 'xmark', icon: [384, 512, [], 'f00d', 'M1 1']};",
+ '',
+ ].join('\n'),
+ );
+ writeLibrary(
+ '@acme/brand-data',
+ [
+ "export const si1password = {title: '1Password', path: 'M0 0'};",
+ "export const siGithub = {title: 'GitHub', path: 'M0 1'};",
+ '',
+ ].join('\n'),
+ );
+});
+afterEach(() => {
+ fs.rmSync(tmp, {recursive: true, force: true});
+});
+
+/** @param {string[]} args */
+async function json(args) {
+ const res = await runCli([...args, '--json'], pkg);
+ return {code: res.code, body: JSON.parse(res.stdout)};
+}
+
+/** @param {string} set @param {string} ext */
+const setFile = (set, ext) => path.join(pkg, 'icon-sets', set, `${set}.${ext}`);
+
+/** @param {string} set */
+const dataOf = set =>
+ JSON.parse(fs.readFileSync(setFile(set, 'icons.json'), 'utf-8'));
+
+/**
+ * Every export name the set writes: the data file's exports and variants,
+ * and each name the generated module and its declaration file declare. Both
+ * files must parse.
+ * @param {string} set
+ */
+function writtenNames(set) {
+ const data = dataOf(set);
+ const names = data.icons.flatMap((/** @type {any} */ icon) => [
+ icon.export,
+ ...(icon.variants ?? []).map((/** @type {any} */ each) => each.export),
+ ]);
+ for (const ext of ['generated.js', 'generated.d.ts']) {
+ const text = fs.readFileSync(setFile(set, ext), 'utf-8');
+ const ast = parse(text, {sourceType: 'module', plugins: ['typescript']});
+ for (const node of ast.program.body) {
+ if (node.type !== 'ExportNamedDeclaration') continue;
+ for (const specifier of node.specifiers) {
+ if (specifier.exported.type === 'Identifier') {
+ names.push(specifier.exported.name);
+ }
+ }
+ if (node.declaration?.type === 'VariableDeclaration') {
+ for (const each of node.declaration.declarations) {
+ if (each.id.type === 'Identifier') names.push(each.id.name);
+ }
+ }
+ }
+ }
+ return names;
+}
+
+/**
+ * Map every built-in definition to one icon, wire the entry, and run the
+ * strict check. Returns every issue it reports and every failure, without the skipped
+ * TypeScript work.
+ * @param {string} set
+ * @param {string} icon
+ */
+async function strictFailures(set, icon) {
+ const mapped = await json([
+ 'experimental',
+ 'icon',
+ 'map',
+ '--set',
+ set,
+ '--pairs',
+ ICON_NAMES.map(name => `${name}=${icon}`).join(','),
+ ]);
+ expect(mapped.code, JSON.stringify(mapped.body)).toBe(0);
+ fs.writeFileSync(
+ path.join(pkg, 'index.js'),
+ `export * from './icon-sets/${set}/${set}.generated.js';\n`,
+ );
+ const res = await runCli(['integration', 'check', '--strict', '--json'], pkg);
+ const {checks, failures} = JSON.parse(res.stdout).data;
+ return [
+ ...checks.flatMap(
+ (/** @type {any} */ each) => each.response?.data?.issues ?? [],
+ ),
+ ...failures,
+ ]
+ .filter(
+ (/** @type {{code: string}} */ each) => each.code !== 'doc_types_skipped',
+ )
+ .map(
+ (/** @type {{code: string, message: string}} */ each) =>
+ `${each.code}: ${each.message}`,
+ );
+}
+
+describe('library names that start with a digit once the prefix comes off', () => {
+ it('a library of icon data objects with digit glyphs (`fa0`) gets valid export names and passes the strict check', async () => {
+ const created = await json(['experimental', 'icon', 'new-set', 'solid']);
+ expect(created.code, JSON.stringify(created.body)).toBe(0);
+ const data = dataOf('solid');
+ data.adapter = {module: './src/adapt.js', export: 'adapt'};
+ fs.writeFileSync(setFile('solid', 'icons.json'), JSON.stringify(data));
+ const wrapped = await json([
+ 'experimental',
+ 'icon',
+ 'new-set',
+ 'solid',
+ '--from',
+ '@acme/glyph-data',
+ ]);
+ expect(wrapped.code, JSON.stringify(wrapped.body)).toBe(0);
+ expect(
+ dataOf('solid').icons.map((/** @type {any} */ i) => [i.id, i.export]),
+ ).toEqual([
+ ['fa-0', 'Fa0Icon'],
+ ['fa-1', 'Fa1Icon'],
+ ['fa-42-group', 'Fa42GroupIcon'],
+ ['fa-500px', 'Fa500pxIcon'],
+ ['house', 'HouseIcon'],
+ ['xmark', 'XmarkIcon'],
+ ]);
+ const names = writtenNames('solid');
+ expect(names).toContain('Fa0Icon');
+ expect(names).toContain('Fa500pxIcon');
+ expect(names.filter(name => !IDENTIFIER_RE.test(name))).toEqual([]);
+ expect(await strictFailures('solid', 'xmark')).toEqual([]);
+ });
+
+ it('a component library whose only shared word is `Digit` keeps it, and an id given with a leading digit is refused', async () => {
+ const created = await json([
+ 'experimental',
+ 'icon',
+ 'new-set',
+ 'digits',
+ '--from',
+ '@acme/digits',
+ ]);
+ expect(created.code, JSON.stringify(created.body)).toBe(0);
+ expect(
+ dataOf('digits').icons.map((/** @type {any} */ i) => [i.id, i.export]),
+ ).toEqual([
+ ['digit-1', 'Digit1Icon'],
+ ['digit-2', 'Digit2Icon'],
+ ]);
+ const before = fs.readFileSync(setFile('digits', 'icons.json'), 'utf-8');
+ const refused = await json([
+ 'experimental',
+ 'icon',
+ 'add',
+ 'Digit1Icon',
+ '--from',
+ '@acme/more-digits',
+ '--id',
+ '7',
+ '--definition',
+ 'close',
+ ]);
+ expect(refused.code).not.toBe(0);
+ expect(JSON.stringify(refused.body)).toContain(
+ 'The icon id \\"7\\" starts with a digit, and an export name cannot. Pass --id with an id that starts with a letter.',
+ );
+ expect(fs.readFileSync(setFile('digits', 'icons.json'), 'utf-8')).toBe(
+ before,
+ );
+ // An option pair the command refuses is reported first, as an option.
+ const pair = await json([
+ 'experimental',
+ 'icon',
+ 'add',
+ '--all',
+ '--variant',
+ 'solid',
+ '--from',
+ '@acme/more-digits',
+ '--id',
+ '7',
+ ]);
+ expect(pair.code).not.toBe(0);
+ expect(pair.body.code).toBe('ERR_INVALID_OPTION');
+ // A library name the set does not export yet is refused the same way.
+ const refusedFree = await json([
+ 'experimental',
+ 'icon',
+ 'add',
+ 'StarIcon',
+ '--from',
+ '@acme/more-digits',
+ '--id',
+ '7',
+ '--definition',
+ 'close',
+ ]);
+ expect(refusedFree.code).not.toBe(0);
+ expect(JSON.stringify(refusedFree.body)).toContain(
+ 'The icon id \\"7\\" starts with a digit, and an export name cannot. Pass --id with an id that starts with a letter.',
+ );
+ expect(fs.readFileSync(setFile('digits', 'icons.json'), 'utf-8')).toBe(
+ before,
+ );
+ const added = await json([
+ 'experimental',
+ 'icon',
+ 'add',
+ 'Digit1Icon',
+ '--from',
+ '@acme/more-digits',
+ '--id',
+ 'seven',
+ '--definition',
+ 'close',
+ ]);
+ expect(added.code, JSON.stringify(added.body)).toBe(0);
+ const names = writtenNames('digits');
+ expect(names).toContain('SevenIcon');
+ expect(names.filter(name => !IDENTIFIER_RE.test(name))).toEqual([]);
+ expect(await strictFailures('digits', 'digit-1')).toEqual([]);
+ });
+
+ it('a library that exports both `fa0` and `faDigit0` gives two icons with two export names', async () => {
+ const created = await json(['experimental', 'icon', 'new-set', 'both']);
+ expect(created.code, JSON.stringify(created.body)).toBe(0);
+ const data = dataOf('both');
+ data.adapter = {module: './src/adapt.js', export: 'adapt'};
+ fs.writeFileSync(setFile('both', 'icons.json'), JSON.stringify(data));
+ const wrapped = await json([
+ 'experimental',
+ 'icon',
+ 'new-set',
+ 'both',
+ '--from',
+ '@acme/both-digits',
+ ]);
+ expect(wrapped.code, JSON.stringify(wrapped.body)).toBe(0);
+ expect(
+ dataOf('both').icons.map((/** @type {any} */ i) => [i.id, i.export]),
+ ).toEqual([
+ ['digit-0', 'Digit0Icon'],
+ ['fa-0', 'Fa0Icon'],
+ ['xmark', 'XmarkIcon'],
+ ]);
+ const names = writtenNames('both');
+ expect(names.filter(name => !IDENTIFIER_RE.test(name))).toEqual([]);
+ expect(await strictFailures('both', 'xmark')).toEqual([]);
+ });
+
+ it('a brand library keeps its prefix only on the icon whose name starts with a digit (`si1password`)', async () => {
+ const created = await json(['experimental', 'icon', 'new-set', 'brands']);
+ expect(created.code, JSON.stringify(created.body)).toBe(0);
+ const data = dataOf('brands');
+ data.adapter = {module: './src/adapt.js', export: 'adapt'};
+ fs.writeFileSync(setFile('brands', 'icons.json'), JSON.stringify(data));
+ const wrapped = await json([
+ 'experimental',
+ 'icon',
+ 'new-set',
+ 'brands',
+ '--from',
+ '@acme/brand-data',
+ ]);
+ expect(wrapped.code, JSON.stringify(wrapped.body)).toBe(0);
+ expect(
+ dataOf('brands').icons.map((/** @type {any} */ i) => [i.id, i.export]),
+ ).toEqual([
+ ['github', 'GithubIcon'],
+ ['si-1password', 'Si1passwordIcon'],
+ ]);
+ expect(await strictFailures('brands', 'github')).toEqual([]);
+ });
+});
diff --git a/packages/cli/foundation/discovery/icon-set-writer.mjs b/packages/cli/foundation/discovery/icon-set-writer.mjs
index 67c3345e4c..fe287e5d15 100644
--- a/packages/cli/foundation/discovery/icon-set-writer.mjs
+++ b/packages/cli/foundation/discovery/icon-set-writer.mjs
@@ -100,10 +100,19 @@ export function iconIdOf(name) {
/**
* The name an icon set exports an icon as: PascalCase ending in `Icon`
- * (`Trash2` → `Trash2Icon`; `TrashIcon` stays).
+ * (`Trash2` → `Trash2Icon`; `TrashIcon` stays). A JavaScript name cannot
+ * start with a digit, so a name that starts with one is refused.
+ * {@link iconNaming} keeps a library prefix to prevent this (`fa0` →
+ * `Fa0Icon`).
* @param {string} name
*/
export function iconExportName(name) {
+ if (/^[0-9]/u.test(name)) {
+ throw new IconSetAuthoringError(
+ `The icon id "${iconIdOf(name)}" starts with a digit, and an export name cannot. Pass --id with an id that starts with a letter.`,
+ 'ERR_INVALID_ARGUMENT',
+ );
+ }
const pascal = name[0].toUpperCase() + name.slice(1);
return pascal.endsWith('Icon') ? pascal : `${pascal}Icon`;
}
@@ -690,7 +699,9 @@ export function libraryPrefix(names) {
/**
* An export's id and the name the set exports it as, with the library prefix
- * left out: `featherEye` with prefix `feather` is id `eye`, `EyeIcon`.
+ * left out: `featherEye` with prefix `feather` is id `eye`, `EyeIcon`. A
+ * name that would start with a digit keeps the prefix (`fa500px` is
+ * `fa-500px`, `Fa500pxIcon`).
* @param {string} name
* @param {string[]} prefix
* @returns {{id: string, name: string}}
@@ -698,9 +709,12 @@ export function libraryPrefix(names) {
export function iconNaming(name, prefix) {
const all = iconIdOf(name).split('-');
// Only a name that starts with the prefix, and has more after it, loses it.
+ // A name that would then start with a digit keeps the prefix: `fa0` is
+ // `fa-0`, `Fa0Icon`.
const strip =
all.length > prefix.length &&
- prefix.every((word, index) => all[index] === word);
+ prefix.every((word, index) => all[index] === word) &&
+ !/^[0-9]/u.test(all[prefix.length]);
if (!strip) prefix = [];
const words = all.slice(prefix.length);
const id = words.join('-');