# get-svg-colors

> Extract stroke and fill colors from SVG files

Latest version **2.0.1** (published 2023-08-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install get-svg-colors
pnpm add get-svg-colors
yarn add get-svg-colors
bun add get-svg-colors
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2023-08-09 |
| First published | 2015-11-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 246.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 39 |
| Maintainers | zeke |

## Links

- npm: https://www.npmjs.com/package/get-svg-colors
- Repository: https://github.com/colorjs/get-svg-colors
- Homepage: https://github.com/colorjs/get-svg-colors#readme
- Issues: https://github.com/colorjs/get-svg-colors/issues
- npm.io page: https://npm.io/package/get-svg-colors

## Dependencies (5)

- [is-svg](https://npm.io/package/is-svg.md) ^4.3.1
- [cheerio](https://npm.io/package/cheerio.md) 1.0.0-rc.12
- [chroma-js](https://npm.io/package/chroma-js.md) ^2.0.3
- [lodash.uniq](https://npm.io/package/lodash.uniq.md) ^4.5.0
- [lodash.compact](https://npm.io/package/lodash.compact.md) ^3.0.0

## Recent versions

- 2.0.1 (latest) — 2023-08-09
- 2.0.0 — 2022-02-04
- 0.0.0 — 2022-02-04
- 1.5.1 — 2018-10-25
- 1.5.0 — 2018-10-23
- 1.4.0 — 2017-11-10
- 1.3.0 — 2016-02-27
- 1.2.2 — 2015-12-06
- 1.2.1 — 2015-12-06
- 1.2.0 — 2015-12-06
- 1.1.1 — 2015-11-18
- 1.1.0 — 2015-11-18
- 1.0.0 — 2015-11-18

## README

# get-svg-colors

Extract stroke and fill colors from SVG files. Designed for use in node, not the browser.

## Installation

```sh
npm install get-svg-colors --save
```

## Usage

```js
const getColors = require("get-svg-colors")

// 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

```sh
npm install
npm test
```

## Dependencies

- [cheerio](https://github.com/cheeriojs/cheerio): Tiny, fast, and elegant implementation of core jQuery designed specifically for the server
- [chroma-js](https://github.com/gka/chroma.js): JavaScript library for color conversions
- [is-svg](https://github.com/sindresorhus/is-svg): Check if a String/Buffer is SVG
- [lodash.compact](https://github.com/lodash/lodash): The modern build of lodash’s `_.compact` as a module.
- [lodash.uniq](https://github.com/lodash/lodash): The modern build of lodash’s `_.uniq` as a module.

## Dev Dependencies

- [mocha](https://github.com/mochajs/mocha): simple, flexible, fun test framework


## License

ISC

_Generated by [package-json-to-readme](https://github.com/colorjs/package-json-to-readme)_

---
_Source: https://npm.io/package/get-svg-colors · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
