sync read svg icons and parse to icons object
JavaScript HTML
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
index.js
package.json

README.md

svg-reader

Build Status

sync read svg icons and parse to icons object

get

npm install svg-reader

use

const read = require('svg-reader')
var icons = read(__dirname + '/icons.svg')

/*
icons = 
{ home: 
   { name: 'home',
     width: 928,
     height: 1000,
     path: 'M786 ... 12t-4-13z',
     ascent: 850,
     svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 928 1000"><g transform="scale(1,-1) translate(0 -850)"><path d="M78 ... 4-13z"/></g></svg>' },
  link: 
   { name: 'link',
     width: 928,
     height: 1000,
     path: 'M81 ... 14z',
     ascent: 850,
     svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 928 1000"><g transform="scale(1,-1) translate(0 -850)"><path d="M81 ... 114z"/></g></svg>' },
  unlink: 
   { name: 'unlink',
     width: 928,
     height: 1000,
     path: 'M24 ... 13z',
     ascent: 850,
     svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 928 1000"><g transform="scale(1,-1) translate(0 -850)"><path d="M24 ... 5-13z"/></g></svg>' }
}

*/

//if do not need svg,  pass a option { nosvg: true } 
var icons = read(__dirname + '/icons.svg', { nosvg: true })
/*
icons = 
{ home: 
   { name: 'home',
     width: 928,
     height: 1000,
     path: 'M786 ... 12t-4-13z',
     ascent: 850},
  link: 
   { name: 'link',
     width: 928,
     height: 1000,
     path: 'M81 ... 14z',
     ascent: 850},
  unlink: 
   { name: 'unlink',
     width: 928,
     height: 1000,
     path: 'M24 ... 13z',
     ascent: 850}
}

*/

test

git clone git@github.com:zxdong262/svg-reader.git
cd svg-reader
npm i
npm run test

License

MIT