2
0
mirror of https://github.com/iconify/iconify.git synced 2024-12-12 21:57:50 +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 committed by Vjacheslav Trushkin
parent 5cab683047
commit 5cb43cc2d2

View File

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