svg-color-linter
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published


logo

SVG Color Linter

Linting tool to check if SVG files only use colors of a given color palette.

CLI Command

The tool can be executed with this command:

npx svg-color-linter --colors colors.yml file1.svg file2.svg

It will fetch all the colors of a YAML file which must have the following structure:

colors:
  - '#FFEBEE'
  - '#FFCDD2'
  - '#EF9A9A'
  - '#E57373'
  - '#EF5350'
  - '#F44336'

It also supports glob file patterns to check multiple files matching the pattern like this:

npx svg-color-linter --colors colors.yml ./images/**/*.svg ./another-dir/*.svg test.svg

Programmatic use

The tool can be imported as module into existing JavaScript or TypeScript code. Therefor it is necessary to install it via npm or yarn:

NPM:

npm install --save-dev svg-color-linter

Yarn:

yarn add --dev svg-color-linter

The module can be imported like this:

import { isColorInPalette, getSuggestions } from 'svg-color-linter';

isColorInPalette('#FFFFFF', ['#EEEEEE', '#121212']);
// false

getSuggestions('#C0CA35', ['#EEEEEE', '#121212']);
// [
//   { hex: '#C0CA33', distance: 0.160467661071053 },
//   { hex: '#CDDC39', distance: 4.307076277707079 },
//   { hex: '#D4E157', distance: 5.606714639567858 },
//   { hex: '#AFB42B', distance: 5.713845679863578 },
//   { hex: '#DCE775', distance: 8.065940911169271 }
// ]

Readme

Keywords

Package Sidebar

Install

npm i svg-color-linter

Weekly Downloads

225

Version

1.3.0

License

MIT

Unpacked Size

22 kB

Total Files

42

Last publish

Collaborators

  • pkief