Package Exports
- svgson
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (svgson) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
svgson 
SVGJSON is a simple tool to transform svg files and Strings into Object or JSON.
Useful to manipulate
SVGwithjs, to store in noSQL databses...
How to use
$ [sudo] npm install -g svgson$ svgson [options] <keywords>Options
-h, --help output usage information
-V, --version output the version number
-i, --input [input] Specifies input folder or file.
Default current folder
-o, --output [output] Specifies output file. Default ./svgson.json
-t, --title Add title from svg filename
-P, --prefix <prefix> Remove prefix from title
-S, --suffix <suffix> Remove suffix from title
-k, --key [key] Specifies a key where include all paths
-a, --attrs <attrs> Custom Attributes: key=value, key=value...
-p, --pretty Prettyfied JSON
-s, --svgo Optimize SVG with SVGO
Examples
inputcurrent folder |outputsvgson.json file$ svgsoninput/svgs folder |outputmy-svgs.json file$ svgson --input svgs --output my-svgs.jsoninputmyfile.svg file |outputmy-file.json file$ svgson -i myfile.svg -o my-file.jsonComplex example
input/svgs folderoutputsvgson.json file- adds
titlefrom each file and removesicon-prefix - prettifies JSON output
- group all paths into the key
myPaths - adds
{ author: me, foo: bar }custom attributes per file - optimize output with svgo
$ svgson -i ./svgs --title --prefix icon- --pretty --key myPaths --svgo --attrs author=me,foo=bar
Use as Node Module
$ npm i --save svgsonconst svgson = require('svgson');
// From .svg file
const fs = require('fs');
fs.readFile('myfile.svg', 'utf-8', function(err, data) {
svgson(data, {
svgo: true,
title: 'myFile',
pathsKey: 'myPaths',
customAttrs: {
foo: true
}
}, function(result) {
console.log(result);
});
});
// From svg String
const SVG = '<svg width="100" height="100"><circle r="15" stroke-linecap="round" /></svg>';
svgson(SVG, {}, result => console.log(result));
Use in Browser
$ npm run bundleor
$ browserify ./lib/svgson.js --standalone svgson -o svgson-bundle.jsthen in html file
<body>
<svg viewBox="0 0 100 100" id="mySVG">
<circle cx="50" cy="50" r="48" stroke="red" stroke-width="4"/>
</svg>
<script src="svgson-bundle.js"></script>
<script>
svgson(document.querySelector('#mySVG').outerHTML, {
title: 'mySVG',
pathsKey: 'paths',
customAttrs: {
a: 123,
foo: true,
bar: 'baz'
}
}, function(result) {
console.log(result);
});
</script>
</body>Tests
npm testLicense
MIT © Lionel T