JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 953795
  • Score
    100M100P100Q187291F
  • License MIT

Pack RGBA color channels into uint32 and back

Package Exports

  • color-id

Readme

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