A Node.js module to create SVG files of flexible width and height
<?xml version="2.0" encoding="UTF-8" standalone="yes"?>
<svg xmlns="http://www.w3.org/2000/svg" width="50px" height="50px">
<rect width="50px" height="50px"/>
</svg>
↓
<?xml version="2.0" encoding="UTF-8" standalone="yes"?>
<svg xmlns="http://www.w3.org/2000/svg">
<rect width="50px" height="50px"/>
</svg>
If width
and height
attributes of outermost svg elements are not specified, they are regarded as 100%
according to the SVG 2 Specification.
npm install flex-svg
const flexSvg = require('flex-svg');
svgData: string
Buffer
(SVG)
options: Object
(directly passed to the xml2js.Parser options and the xml2js.Builder options)
callback: Function
error: Error
if it fails to parse SVG, otherwise null
result: string
of SVG without width
and height
attributes
const {readFile} = require('fs');
const flexSvg = require('flex-svg');
readFile('path/to/file.svg', (readErr, data) => {
if (readErr) {
throw readErr;
}
flexSvg(data, (parseErr, result) => {
if (parseErr) {
throw parseErr;
}
console.log(result);
});
});
Return: Function
Create a Function
to which options are bound. This is more efficient way in the case when the program repeatedly runs flexSvg
function with the same options.
ISC License © 2017 - 2018 Shinnosuke Watanabe