mirror of
https://github.com/iconify/iconify.git
synced 2024-11-09 23:00:56 +00:00
chore: extract reusable getPossibleIconNames
This commit is contained in:
parent
220bb35428
commit
a91922ccac
@ -2,6 +2,7 @@ import { AutoInstall, CustomIconLoader, ExternalPkgName } from './types';
|
||||
import { loadCollectionFromFS } from './fs';
|
||||
import { searchForIcon } from './modern';
|
||||
import { warnOnce } from './warn';
|
||||
import { getPossibleIconNames } from './utils';
|
||||
|
||||
/**
|
||||
* Creates a CustomIconLoader collection from an external package collection.
|
||||
@ -57,13 +58,11 @@ function createCustomIconLoader(
|
||||
// copy/paste from ./node-loader.ts
|
||||
let result: string | undefined;
|
||||
if (iconSet) {
|
||||
// possible icon names
|
||||
const ids = [
|
||||
icon,
|
||||
icon.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(),
|
||||
icon.replace(/([a-z])(\d+)/g, '$1-$2'),
|
||||
];
|
||||
result = await searchForIcon(iconSet, collection, ids);
|
||||
result = await searchForIcon(
|
||||
iconSet,
|
||||
collection,
|
||||
getPossibleIconNames(icon)
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -3,6 +3,7 @@ import { searchForIcon } from './modern';
|
||||
import { loadCollectionFromFS } from './fs';
|
||||
import { warnOnce } from './warn';
|
||||
import { loadIcon } from './loader';
|
||||
import { getPossibleIconNames } from './utils';
|
||||
|
||||
export const loadNodeIcon: UniversalIconLoader = async (
|
||||
collection,
|
||||
@ -19,13 +20,12 @@ export const loadNodeIcon: UniversalIconLoader = async (
|
||||
options?.autoInstall
|
||||
);
|
||||
if (iconSet) {
|
||||
// possible icon names
|
||||
const ids = [
|
||||
icon,
|
||||
icon.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(),
|
||||
icon.replace(/([a-z])(\d+)/g, '$1-$2'),
|
||||
];
|
||||
result = await searchForIcon(iconSet, collection, ids, options);
|
||||
result = await searchForIcon(
|
||||
iconSet,
|
||||
collection,
|
||||
getPossibleIconNames(icon),
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
if (!result && options?.warn) {
|
||||
|
@ -114,3 +114,11 @@ export async function mergeIconProps(
|
||||
|
||||
return svg;
|
||||
}
|
||||
|
||||
export function getPossibleIconNames(icon: string): string[] {
|
||||
return [
|
||||
icon,
|
||||
icon.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(),
|
||||
icon.replace(/([a-z])(\d+)/g, '$1-$2'),
|
||||
];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user