mirror of
https://github.com/iconify/iconify.git
synced 2025-02-14 09:30:21 +00:00
Fix listIcons and add disableCache for React with API
This commit is contained in:
parent
e00b7f1781
commit
84a73d0c22
@ -132,7 +132,7 @@ export type IconifyCacheType = 'local' | 'session' | 'all';
|
||||
/**
|
||||
* Toggle cache
|
||||
*/
|
||||
export function enableCache(storage: IconifyCacheType, value: boolean): void {
|
||||
function toggleCache(storage: IconifyCacheType, value: boolean): void {
|
||||
switch (storage) {
|
||||
case 'local':
|
||||
case 'session':
|
||||
@ -147,6 +147,14 @@ export function enableCache(storage: IconifyCacheType, value: boolean): void {
|
||||
}
|
||||
}
|
||||
|
||||
export function enableCache(storage: IconifyCacheType, value?: boolean): void {
|
||||
toggleCache(storage, typeof value === 'boolean' ? value : true);
|
||||
}
|
||||
|
||||
export function disableCache(storage: IconifyCacheType): void {
|
||||
toggleCache(storage, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get icon name
|
||||
*/
|
||||
@ -186,7 +194,7 @@ export const loadIcons: IconifyLoadIcons = API.loadIcons;
|
||||
* List available icons
|
||||
*/
|
||||
export function listIcons(provider?: string, prefix?: string): string[] {
|
||||
let icons = [];
|
||||
let allIcons = [];
|
||||
|
||||
// Get providers
|
||||
let providers: string[];
|
||||
@ -200,7 +208,7 @@ export function listIcons(provider?: string, prefix?: string): string[] {
|
||||
providers.forEach((provider) => {
|
||||
let prefixes: string[];
|
||||
|
||||
if (typeof prefix === 'string') {
|
||||
if (typeof provider === 'string' && typeof prefix === 'string') {
|
||||
prefixes = [prefix];
|
||||
} else {
|
||||
prefixes = listStoredPrefixes(provider);
|
||||
@ -208,18 +216,18 @@ export function listIcons(provider?: string, prefix?: string): string[] {
|
||||
|
||||
prefixes.forEach((prefix) => {
|
||||
const storage = getStorage(provider, prefix);
|
||||
let icons = Object.keys(storage.icons).map(
|
||||
const icons = Object.keys(storage.icons).map(
|
||||
(name) =>
|
||||
(provider !== '' ? '@' + provider + ':' : '') +
|
||||
prefix +
|
||||
':' +
|
||||
name
|
||||
);
|
||||
icons = icons.concat(icons);
|
||||
allIcons = allIcons.concat(icons);
|
||||
});
|
||||
});
|
||||
|
||||
return icons;
|
||||
return allIcons;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user