svg-id
v1.0.4
Published
utils functions : rename file, replace id in svg in order to be uuid, replace occurence
Downloads
22
Readme
ez replace
utils functions to rename, replace with fs library
Installation
npm i svg-id
Usage
// in index
import { readdirSync } from 'fs';
import { resolve } from 'path';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import { replaceX, renameFile, replaceSVGID1, replaceSvgIds } from 'svg-id';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Get path to files directory
const filesDirPath = resolve(__dirname, "path/of/folder");
// Get an array of the files inside the folder
const files = readdirSync(filesDirPath);
// find all occurence of regex and replace with last argument
replaceX(files, imageDirPath, /eg/g, 'toto');
// rename in folder all files like this -> toto-1.svg, toto-2.svg ect
renameFile('svg', 'toto', files, filesDirPath);
// replace this id (SVGID_1) give by illustrator on svgs export
replaceSVGID1(files, filesDirPath);
// clean and make unique id of defaut svgs illustrator's export like : id="a" xlink:href="#a" fill="url(#a)"
replaceSVGIds(files, filesDirPath);
// then run your script