mirror of https://github.com/iconify/api.git
feat: add icon set info to filter for full package
This commit is contained in:
parent
5513ed23e7
commit
ace0b7114a
|
|
@ -39,7 +39,7 @@ export const fullPackageImporter = createIconSetsPackageImporter(
|
|||
),
|
||||
{
|
||||
// Filter icon sets. Returns true if icon set should be included, false if not
|
||||
filter: (prefix) => {
|
||||
filter: (prefix, info) => {
|
||||
return true;
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@ import type { ImportedData } from '../../types/importers/common';
|
|||
import type { BaseFullImporter } from '../../types/importers/full';
|
||||
import { createBaseImporter } from './base';
|
||||
import { IconSetJSONOptions, importIconSetFromJSON } from '../common/icon-set-json';
|
||||
import type { IconifyInfo } from '@iconify/types';
|
||||
|
||||
interface IconSetsPackageImporterOptions extends IconSetJSONOptions {
|
||||
// Icon set filter
|
||||
filter?: (prefix: string) => boolean;
|
||||
filter?: (prefix: string, info: IconifyInfo) => boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -23,8 +24,9 @@ export function createIconSetsPackageImporter<Downloader extends BaseDownloader<
|
|||
// Load collections list
|
||||
obj._loadCollectionsListFromDirectory = async (path: string) => {
|
||||
let prefixes: string[];
|
||||
let data: Record<string, IconifyInfo>;
|
||||
try {
|
||||
const data = JSON.parse(await readFile(path + '/collections.json', 'utf8')) as Record<string, unknown>;
|
||||
data = JSON.parse(await readFile(path + '/collections.json', 'utf8')) as Record<string, IconifyInfo>;
|
||||
prefixes = Object.keys(data).filter((prefix) => matchIconName.test(prefix));
|
||||
|
||||
if (!(prefixes instanceof Array)) {
|
||||
|
|
@ -39,7 +41,7 @@ export function createIconSetsPackageImporter<Downloader extends BaseDownloader<
|
|||
// Filter keys
|
||||
const filter = options?.filter;
|
||||
if (filter) {
|
||||
prefixes = prefixes.filter(filter);
|
||||
prefixes = prefixes.filter((prefix) => filter(prefix, data[prefix]));
|
||||
}
|
||||
return prefixes;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue