# markup-color-extractor

> Extract colors from markup (XML and HTML)

Latest version **1.0.2** (published 2015-05-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install markup-color-extractor
pnpm add markup-color-extractor
yarn add markup-color-extractor
bun add markup-color-extractor
```

## 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 | 1.0.2 |
| Published | 2015-05-16 |
| First published | 2015-05-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+8 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Matthew Hasbach |
| Maintainers | mjhasbach |
| Keywords | markup, html, xml, parse, extract, color, hex, hexadecimal, argb, rgb, rgba, hsl, hsla, hsv, hsva, named, string, buffer, url, file |

## Links

- npm: https://www.npmjs.com/package/markup-color-extractor
- Repository: https://github.com/mjhasbach/node-markup-color-extractor
- Issues: https://github.com/mjhasbach/node-markup-color-extractor/issues
- npm.io page: https://npm.io/package/markup-color-extractor

## Dependencies (4)

- [lodash](https://npm.io/package/lodash.md) ~3.7.0
- [cheerio](https://npm.io/package/cheerio.md) ~0.19.0
- [request](https://npm.io/package/request.md) ~2.55.0
- [tinycolor2](https://npm.io/package/tinycolor2.md) ~1.1.2

## Alternatives

- [postcss-color-hex-alpha](https://npm.io/package/postcss-color-hex-alpha.md) — 6.4M weekly downloads
- [randomcolor](https://npm.io/package/randomcolor.md) — 348.0K weekly downloads
- [bows](https://npm.io/package/bows.md) — 1.3K weekly downloads
- [ep_prefer_color_scheme](https://npm.io/package/ep_prefer_color_scheme.md) — 260 weekly downloads
- [coc-yank](https://npm.io/package/coc-yank.md) — 61 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2015-05-16

## README

# node-markup-color-extractor

## Description
Extract colors from HTML and XML. This library can detect all of the color types supported by [TinyColor](https://github.com/bgrins/TinyColor).

## API
#### extractColors.from.buffer(```opt```)

Extract colors from a buffer

* object `opt` - An options object
  * buffer `buffer` - A [Buffer](https://nodejs.org/api/buffer.html) containing markup
  * function(null|object `err`, array `colors`) `cb` - A function to be executed after the colors are extracted
  * boolean `unique` - (Optional) If `true`, the color array will not contain duplicates (Default `true`)
  * boolean `text` - (Optional) If `true`, will search element inner text for colors
  * boolean|array `attributes` - (Optional) If `true`, will search all element attributes for colors, or if an array, will search only the attributes listed in the array

__Example__

```
fs.readFile(path.join(__dirname, 'colors.xml'), function(err, data) {
    if (err) { throw err; }

    extractColors.from.buffer({
        buffer: data,
        attributes: true,
        text: true,
        cb: function(err, colors) {
            if (err) { throw err; }
            console.log(colors);
        }
    });
});
```

#### extractColors.from.string(```opt```)

Extract colors from a string

* object `opt` - An options object
  * string `string` - A string containing markup
  * function(null|object `err`, array `colors`) `cb` - A function to be executed after the colors are extracted
  * boolean `unique` - (Optional) If `true`, the color array will not contain duplicates (Default `true`)
  * boolean `text` - (Optional) If `true`, will search element inner text for colors
  * boolean|array `attributes` - (Optional) If `true`, will search all element attributes for colors, or if an array, will search only the attributes listed in the array

__Example__

```
extractColors.from.string({
    string: '<color value="#E0162B">#0052A5</color>',
    text: true,
    attributes: ['value'],
    cb: function(err, colors) {
        if (err) { throw err; }
        console.log(colors);
    }
});
```

#### extractColors.from.file(```opt```)

Extract colors from a file

* object `opt` - An options object
  * string `file` - A path to a file containing markup
  * function(null|object `err`, array `colors`) `cb` - A function to be executed after the colors are extracted
  * boolean `unique` - (Optional) If `true`, the color array will not contain duplicates (Default `true`)
  * boolean `text` - (Optional) If `true`, will search element inner text for colors
  * boolean|array `attributes` - (Optional) If `true`, will search all element attributes for colors, or if an array, will search only the attributes listed in the array

__Example__

```
extractColors.from.file({
    file: path.join(__dirname, 'colors.xml'),
    attributes: true,
    text: true,
    cb: function(err, colors) {
        if (err) { throw err; }
        console.log(colors);
    }
});
```

#### extractColors.from.url(```opt```)

Extract colors from a url

* object `opt` - An options object
  * string `url` - A url to a file containing markup
  * function(null|object `err`, array `colors`) `cb` - A function to be executed after the colors are extracted
  * boolean `unique` - (Optional) If `true`, the color array will not contain duplicates (Default `true`)
  * boolean `text` - (Optional) If `true`, will search element inner text for colors
  * boolean|array `attributes` - (Optional) If `true`, will search all element attributes for colors, or if an array, will search only the attributes listed in the array

__Example__

```
extractColors.from.url({
    url: 'http://site.com/colors.html',
    attributes: true,
    text: true,
    cb: function(err, colors) {
        if (err) { throw err; }
        console.log(colors);
    }
});
```

#### Note

You may also supply any of the [htmlparser2 parser options](https://github.com/fb55/htmlparser2/wiki/Parser-options) in ```opt``` for all of the methods listed above.

## Installation
#### Npm
```
npm install markup-color-extractor
```

# Tests
Before running the tests, Mocha must be installed:
```
npm install -g mocha
```

To run the tests:
```
npm test
```

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