npm.io
2.0.0 • Published 3 months ago

color-id

Licence
MIT
Version
2.0.0
Deps
0
Size
4 kB
Vulns
0
Weekly
0
Stars
2

color-id

Pack RGBA color channels into a single uint32 integer and back.

Install

npm install color-id

Usage

import colorId, { from } from 'color-id'

// normalized 0..1 (default)
colorId([1, 0, 0, 1])     // 0xff0000ff
from(0xff0000ff)           // [1, 0, 0, 1]

// byte values 0..255
colorId([255, 0, 0, 255], false)  // 0xff0000ff
from(0xff0000ff, false)           // [255, 0, 0, 255]

API

coloId(rgba, normalized=true) / default export

Pack [r, g, b, a?] channels into a uint32. Values are clamped to valid range. Alpha defaults to 1 (normalized) or 255 (byte).

from(n, normalized=true)

Unpack uint32 into [r, g, b, a] channels.

normalizedtrue for 0..1 range, false for 0..255 byte values.

License

MIT

Keywords