remove fill, stroke attrs

pull/1/head
Atul Varma 2021-02-02 19:40:56 -05:00
rodzic 1a4c8adc41
commit e507f6311d
3 zmienionych plików z 22 dodań i 2 usunięć

Wyświetl plik

@ -5,14 +5,25 @@ import cheerio from "cheerio";
const MY_DIR = __dirname;
const SVG_DIR = path.join(MY_DIR, "..", "svg");
function removeAttr(attr: string, $: cheerio.Root, g: cheerio.Cheerio) {
const items = g.find(`[${attr}]`);
items.each(function (this: any, i, el) {
$((this)).removeAttr(attr);
});
}
export function build() {
const filenames = fs.readdirSync(SVG_DIR);
for (let filename of filenames) {
if (path.extname(filename) === ".svg") {
const svg = fs.readFileSync(path.join(SVG_DIR, filename), {
const svgMarkup = fs.readFileSync(path.join(SVG_DIR, filename), {
encoding: "utf-8",
});
console.log(filename, svg);
const $ = cheerio.load(svgMarkup);
const g = $("svg > g");
removeAttr('fill', $, g);
removeAttr('stroke', $, g);
console.log(filename, g.html());
}
}
}

8
package-lock.json wygenerowano
Wyświetl plik

@ -944,6 +944,14 @@
"to-fast-properties": "^2.0.0"
}
},
"@types/cheerio": {
"version": "0.22.23",
"resolved": "https://registry.npmjs.org/@types/cheerio/-/cheerio-0.22.23.tgz",
"integrity": "sha512-QfHLujVMlGqcS/ePSf3Oe5hK3H8wi/yN2JYuxSB1U10VvW1fO3K8C+mURQesFYS1Hn7lspOsTT75SKq/XtydQg==",
"requires": {
"@types/node": "*"
}
},
"@types/node": {
"version": "14.14.22",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.22.tgz",

Wyświetl plik

@ -13,6 +13,7 @@
"@babel/preset-env": "^7.12.11",
"@babel/preset-typescript": "^7.12.7",
"@babel/register": "^7.12.10",
"@types/cheerio": "^0.22.23",
"@types/node": "^14.14.22",
"cheerio": "^1.0.0-rc.5",
"prettier": "^2.2.1",