Files

32 lines
861 B
TypeScript
Raw Permalink Normal View History

/// <reference types="node" />
import { basename } from 'path';
import { readSvg } from '@lucide/helpers';
2026-07-31 09:11:20 +02:00
import { type INode, parseSync } from 'svgson';
/**
* Build an object in the format: `{ <name>: <contents> }`.
* @param {string[]} svgFiles - A list of filenames.
* @param {Function} getSvg - A function that returns the contents of an SVG file given a filename.
* @returns {Object}
*/
2026-07-31 09:11:20 +02:00
export default function readSVGs(svgFiles: string[], iconsDirectory: string) {
const SVGReadPromises = svgFiles.map(async (svgFile) => {
const name = basename(svgFile, '.svg');
const contents = await readSvg(svgFile, iconsDirectory);
2026-07-31 09:11:20 +02:00
return {
name,
contents,
parsedSvg: parseSync(contents),
};
});
2026-07-31 09:11:20 +02:00
return Promise.all(SVGReadPromises);
}
2026-07-31 09:11:20 +02:00
export type SVGFile = {
name: string;
contents: string;
parsedSvg: INode;
};