svg2colors
v1.4.0
Published
Extract stroke and fill colors from SVG files
Readme
svg2colors
Extract stroke and fill colors from SVG files. Designed for use in node, not the browser.
Installation
npm install svg2colors --saveUsage
const getColors = require("svg2colors")
// Give it an SVG filename
const colors = getColors(__dirname + '/australia.svg')
// Or an SVG string
const colors = getColors('<svg...>')
// You'll get back an object with two keys: `fills` and `strokes`
// `fills` is an array of chroma-js objects
colors.fills.map(color => color.hex())
// => ['#FFFFFF', '#123123', '#F0F0F0']
// `strokes` is also an array of chroma-js objects
colors.strokes.map(color => color.hex())
// => ['#FFFFFF', '#123123', '#F0F0F0']
// Crazy stuff...
colors.fills[0].alpha(0.5).css();
// => 'rgb(0,128,128)'
// Pass the `flat` option to get back a single array including
// de-duped fills and strokes together
const colors = getColors('<svg...>', {flat: true})
// => [...]Tests
npm install
npm testDependencies
- cheerio: Tiny, fast, and elegant implementation of core jQuery designed specifically for the server
- chroma-js: JavaScript library for color conversions
- is-svg: Check if a String/Buffer is SVG
- lodash.compact: The modern build of lodash’s
_.compactas a module. - lodash.uniq: The modern build of lodash’s
_.uniqas a module.
Dev Dependencies
- mocha: simple, flexible, fun test framework
License
ISC
Generated by package-json-to-readme
