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 { loadCollectionFromFS } from './fs';
|
||||||
import { searchForIcon } from './modern';
|
import { searchForIcon } from './modern';
|
||||||
import { warnOnce } from './warn';
|
import { warnOnce } from './warn';
|
||||||
|
import { getPossibleIconNames } from './utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a CustomIconLoader collection from an external package collection.
|
* Creates a CustomIconLoader collection from an external package collection.
|
||||||
@ -57,13 +58,11 @@ function createCustomIconLoader(
|
|||||||
// copy/paste from ./node-loader.ts
|
// copy/paste from ./node-loader.ts
|
||||||
let result: string | undefined;
|
let result: string | undefined;
|
||||||
if (iconSet) {
|
if (iconSet) {
|
||||||
// possible icon names
|
result = await searchForIcon(
|
||||||
const ids = [
|
iconSet,
|
||||||
icon,
|
collection,
|
||||||
icon.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(),
|
getPossibleIconNames(icon)
|
||||||
icon.replace(/([a-z])(\d+)/g, '$1-$2'),
|
);
|
||||||
];
|
|
||||||
result = await searchForIcon(iconSet, collection, ids);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -3,6 +3,7 @@ import { searchForIcon } from './modern';
|
|||||||
import { loadCollectionFromFS } from './fs';
|
import { loadCollectionFromFS } from './fs';
|
||||||
import { warnOnce } from './warn';
|
import { warnOnce } from './warn';
|
||||||
import { loadIcon } from './loader';
|
import { loadIcon } from './loader';
|
||||||
|
import { getPossibleIconNames } from './utils';
|
||||||
|
|
||||||
export const loadNodeIcon: UniversalIconLoader = async (
|
export const loadNodeIcon: UniversalIconLoader = async (
|
||||||
collection,
|
collection,
|
||||||
@ -19,13 +20,12 @@ export const loadNodeIcon: UniversalIconLoader = async (
|
|||||||
options?.autoInstall
|
options?.autoInstall
|
||||||
);
|
);
|
||||||
if (iconSet) {
|
if (iconSet) {
|
||||||
// possible icon names
|
result = await searchForIcon(
|
||||||
const ids = [
|
iconSet,
|
||||||
icon,
|
collection,
|
||||||
icon.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(),
|
getPossibleIconNames(icon),
|
||||||
icon.replace(/([a-z])(\d+)/g, '$1-$2'),
|
options
|
||||||
];
|
);
|
||||||
result = await searchForIcon(iconSet, collection, ids, options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result && options?.warn) {
|
if (!result && options?.warn) {
|
||||||
|
@ -114,3 +114,11 @@ export async function mergeIconProps(
|
|||||||
|
|
||||||
return svg;
|
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