Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for tree-shaking #112

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 64 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ Color-convert is a color conversion library for JavaScript and node.
It converts all ways between `rgb`, `hsl`, `hsv`, `hwb`, `cmyk`, `ansi`, `ansi16`, `hex` strings, and CSS `keyword`s (will round to closest):

```js
import convert from 'color-convert';
import convert from "color-convert";

convert.rgb.hsl(140, 200, 100); // [96, 48, 59]
convert.keyword.rgb('blue'); // [0, 0, 255]
rgbToHsl(140, 200, 100); // [96, 48, 59]
keywordToRgb("blue"); // [0, 0, 255]

const rgbChannels = convert.rgb.channels; // 3
const cmykChannels = convert.cmyk.channels; // 4
const rgbChannels = convert.rgb.channels; // 3
const cmykChannels = convert.cmyk.channels; // 4
const ansiChannels = convert.ansi16.channels; // 1
```

Expand All @@ -29,27 +29,28 @@ All functions have a rounded and unrounded variant. By default, return values ar
All 'from' functions have a hidden property called `.channels` that indicates the number of channels the function expects (not including alpha).

```js
import convert from 'color-convert';
import convert from "color-convert";

// Hex to LAB
convert.hex.lab('DEADBF'); // [ 76, 21, -2 ]
convert.hex.lab.raw('DEADBF'); // [ 75.56213190997677, 20.653827952644754, -2.290532499330533 ]
hexToLab("DEADBF"); // [ 76, 21, -2 ]
convert.hex.lab.raw("DEADBF"); // [ 75.56213190997677, 20.653827952644754, -2.290532499330533 ]

// RGB to CMYK
convert.rgb.cmyk(167, 255, 4); // [ 35, 0, 98, 0 ]
rgbToCmyk(167, 255, 4); // [ 35, 0, 98, 0 ]
convert.rgb.cmyk.raw(167, 255, 4); // [ 34.509803921568626, 0, 98.43137254901961, 0 ]
```

### Arrays

All functions that accept multiple arguments also support passing an array.

Note that this does **not** apply to functions that convert from a color that only requires one value (e.g. `keyword`, `ansi256`, `hex`, etc.)

```js
import convert from 'color-convert';
import convert from "color-convert";

convert.rgb.hex(123, 45, 67); // '7B2D43'
convert.rgb.hex([123, 45, 67]); // '7B2D43'
rgbToHex(123, 45, 67); // '7B2D43'
rgbToHex([123, 45, 67]); // '7B2D43'
```

## Routing
Expand All @@ -59,71 +60,82 @@ Conversions that don't have an _explicitly_ defined conversion (in [conversions.
Keep in mind that extensive conversions _may_ result in a loss of precision, and exist only to be complete. For a list of "direct" (single-step) conversions, see [conversions.js](conversions.js).

## Color Space Scales

Conversions rely on an agreed upon 'full-scale' value for each of the channels. Listed here are those values for the most common color spaces

### rgb
channel | full-scale value
---|---
r | 255
g | 255
b | 255

| channel | full-scale value |
| ------- | ---------------- |
| r | 255 |
| g | 255 |
| b | 255 |

### hsl
channel | full-scale value
---|---
h | 360
s | 100
l | 100

| channel | full-scale value |
| ------- | ---------------- |
| h | 360 |
| s | 100 |
| l | 100 |

### hsv
channel | full-scale value
---|---
h | 360
s | 100
v | 100

| channel | full-scale value |
| ------- | ---------------- |
| h | 360 |
| s | 100 |
| v | 100 |

### hwb
channel | full-scale value
---|---
h | 360
w | 100
b | 100

| channel | full-scale value |
| ------- | ---------------- |
| h | 360 |
| w | 100 |
| b | 100 |

### cmyk
channel | full-scale value
---|---
c | 100
m | 100
y | 100
k | 100

| channel | full-scale value |
| ------- | ---------------- |
| c | 100 |
| m | 100 |
| y | 100 |
| k | 100 |

### hex
channel | full-scale value
---|---
hex | ```0xffffff```

| channel | full-scale value |
| ------- | ---------------- |
| hex | `0xffffff` |

### keyword
channel | value
---|---
name | any key from [color-name](https://github.com/colorjs/color-name/blob/master/index.js)

| channel | value |
| ------- | ------------------------------------------------------------------------------------- |
| name | any key from [color-name](https://github.com/colorjs/color-name/blob/master/index.js) |

### apple
channel | full-scale value
---|---
0 | 65535
1 | 65535
2 | 65535

| channel | full-scale value |
| ------- | ---------------- |
| 0 | 65535 |
| 1 | 65535 |
| 2 | 65535 |

### gray
channel | full-scale value
---|---
gray | 100

| channel | full-scale value |
| ------- | ---------------- |
| gray | 100 |

# Contribute

If there is a new model you would like to support, or want to add a direct conversion between two existing models, please send us a pull request.

# License

Copyright © 2011-2016, Heather Arthur.
Copyright © 2016-2021, Josh Junon.

Expand Down
Loading
Loading