2
0
mirror of https://github.com/iconify/iconify.git synced 2024-11-10 07:11:00 +00:00

chore: add transform callback on getCustomIcon

This commit is contained in:
Joaquín Sánchez Jiménez 2021-12-11 23:58:33 +01:00
parent e5a8e3a5e1
commit c799926749

View File

@ -1,3 +1,4 @@
import type { Awaitable } from '@antfu/utils';
import createDebugger from 'debug';
import type { CustomIconLoader, InlineCollection } from './types';
@ -7,7 +8,7 @@ export async function getCustomIcon(
custom: CustomIconLoader | InlineCollection,
collection: string,
icon: string,
scale = 1
transform?: (svg: string) => Awaitable<string>
): Promise<string | undefined> {
let result: string | undefined | null;
@ -27,6 +28,6 @@ export async function getCustomIcon(
if (!result.startsWith('<svg ')) {
console.warn(`Custom icon "${icon}" in "${collection}" is not a valid SVG`);
}
return result.replace('<svg ', `<svg height="${scale}em" width="${scale}em" `);
return transform ? await transform(result) : result
}
}