package
parse a css color string
npm install parse-css-colorGitHub-flavored package documentation.
Across all versions, last 30 days.
27,414,618 in 30 days
Runtime metadata.
Tagged topics.
Latest published Apr 7, 2022
Parse a CSS color string.
NPM
npm i parse-css-colorOr as a <script> tag from a CDN as parseCssColor:
Unpkg CDN
<script src="https://unpkg.com/parse-css-color"></script>jsDelivr CDN
<script src="https://cdn.jsdelivr.net/npm/parse-css-color"></script>import parse from 'parse-css-color'
// HEX/A
parse('#00f')
//> { type: 'rgb', values: [0, 0, 255], alpha: 1 }
parse('#00f8')
//> { type: 'rgb', values: [0, 0, 255], alpha: 0.5333333333333333 }
parse('#0000FF80')
//> { type: 'rgb', values: [0, 0, 255], alpha: 0.5019607843137255 }
parse('#00g')
//> null
// HSL/A
parse('hsl(270deg 60% 70% / 25%)')
//> { type: 'hsl', values: [270, 60, 70], alpha: 0.25 }
parse('hsl(4.71239rad 260% -70% / 0.5)') // clipped to
//> { type: 'hsl', values: [270, 100, 0], alpha: 0.5 }
parse('hsla(.75turn, 60%, 70%, 50%)')
//> { type: 'hsl', values: [270, 60, 70], alpha: 0.5 }
parse
See tests for more cases.
npm install # install dependencies
npm test # run the tests (append `-- -w`) to watch
npm run dev # watch for changes and rebuildMIT © Noel Delgado
Estimated unpacked size across 3 packages.
36.2 kB
Includes dependencies.