1.0.1 • Published 8 years ago

@f/parse-color v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

parse-color

Build status Git tag NPM version Code style

Parse a valid CSS color string into an array of its components (e.g. ['rgb', r, g, b], ['hsl', h, s, l], etc..)

Installation

$ npm install @f/parse-color

Usage

var parseColor = require('@f/parse-color')

parseColor('rgba(128, 37, 55, .20)') // -> ['rgba', 128, 37, 55, .20]
// You may also use %s
parseColor('rgba(128, 37, 55, 20%)') // -> ['rgba', 128, 37, 55, .20]
parseColor('hsl()')

Recognized color encodings

Percentages

Where appropriate, values may be expressed as a percentage. They will be translated to their corresponding decimal equivalent. I.e. 20% -> .20.

API

parseColor(str)

  • str - A CSS color string

Returns: An array of the form [type, p1, p2, p3, alpha?] Where type is one of rgb/rgba/hsl/hsla/hsv/hsva/hwb/hwba, and p1-p3 are the corresponding components of the type's encoding. Alpha may be specified or left undefined, depending on whether the color type ends in 'a'.

License

MIT