This module provides a helper class for reading and optimizing multiple SVG files located in the same directory (subdirectories are allowed). It returns their names based on path and file content and generates optimized content with glyphs.
npm install @coremyslo/icon-generatorThis module provides a helper class for reading and optimizing multiple SVG files located in the same directory (subdirectories are allowed). It returns their names based on path and file content and generates optimized content with glyphs.
``shell`
$ yarn add @coremyslo/icon-generator
typescript
import { IconGenerator } from "@coremyslo/svg-to-icon";// adds all icons from the directory to internal
iconGenerator.icons but doesn't read them
const iconGenerator = new IconGenerator(path.join(__dirname, "/assets"));// reads and optimizes all icons from directory specified in constructor
await iconGenerator.read();
// reads and optimizes only icons in a specific subdirectory
await iconGenerator.read(path.join(__dirname, "/assets/icons"));
// reads and optimizes only the icon for a specific file.
await iconGenerator.read(path.join(__dirname, "/assets/icons/icon-home.svg"));
// returns a list of icons as a Map
console.log(iconGenerator.icons)
`API
$3
* sourceDirPath: string - Absolute path to the directory with icons.
* options - An optional object with parameters:
* case: "snake" | "pascal" | "camel" | "kebab" | "header" | "constant" - Optional, kebab by default. Defines the case for icon name. See case package for details.
* optimize: boolean; - Optional, true by default. Defines whether the icons should be optimized after reading or not.$3
Asynchronous. Reads and optimizes all SVG files in directory passed in the constructor or subdirectory of file passed as an argument.$3
Asynchronous. Reads and optimizes icon.$3
Deletes icon from the internal icons` Map by name or path.