Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

color-string

Package Overview
Dependencies
2
Maintainers
1
Versions
36
Issues
File Explorer

Advanced tools

color-string

Parser and generator for CSS color strings

    1.9.1latest

Version published
Maintainers
1
Weekly downloads
13,785,791
decreased by-13.2%

Weekly downloads

Readme

Source

color-string

library for parsing and generating CSS color strings.

Install

With npm:

$ npm install color-string

Usage

Parsing

colorString.get('#FFF') // {model: 'rgb', value: [255, 255, 255, 1]} colorString.get('#FFFA') // {model: 'rgb', value: [255, 255, 255, 0.67]} colorString.get('#FFFFFFAA') // {model: 'rgb', value: [255, 255, 255, 0.67]} colorString.get('hsl(360, 100%, 50%)') // {model: 'hsl', value: [0, 100, 50, 1]} colorString.get('hsl(360 100% 50%)') // {model: 'hsl', value: [0, 100, 50, 1]} colorString.get('hwb(60, 3%, 60%)') // {model: 'hwb', value: [60, 3, 60, 1]} colorString.get.rgb('#FFF') // [255, 255, 255, 1] colorString.get.rgb('blue') // [0, 0, 255, 1] colorString.get.rgb('rgba(200, 60, 60, 0.3)') // [200, 60, 60, 0.3] colorString.get.rgb('rgba(200 60 60 / 0.3)') // [200, 60, 60, 0.3] colorString.get.rgb('rgba(200 60 60 / 30%)') // [200, 60, 60, 0.3] colorString.get.rgb('rgb(200, 200, 200)') // [200, 200, 200, 1] colorString.get.rgb('rgb(200 200 200)') // [200, 200, 200, 1] colorString.get.hsl('hsl(360, 100%, 50%)') // [0, 100, 50, 1] colorString.get.hsl('hsl(360 100% 50%)') // [0, 100, 50, 1] colorString.get.hsl('hsla(360, 60%, 50%, 0.4)') // [0, 60, 50, 0.4] colorString.get.hsl('hsl(360 60% 50% / 0.4)') // [0, 60, 50, 0.4] colorString.get.hwb('hwb(60, 3%, 60%)') // [60, 3, 60, 1] colorString.get.hwb('hwb(60, 3%, 60%, 0.6)') // [60, 3, 60, 0.6] colorString.get.rgb('invalid color string') // null

Generation

colorString.to.hex([255, 255, 255]) // "#FFFFFF" colorString.to.hex([0, 0, 255, 0.4]) // "#0000FF66" colorString.to.hex([0, 0, 255], 0.4) // "#0000FF66" colorString.to.rgb([255, 255, 255]) // "rgb(255, 255, 255)" colorString.to.rgb([0, 0, 255, 0.4]) // "rgba(0, 0, 255, 0.4)" colorString.to.rgb([0, 0, 255], 0.4) // "rgba(0, 0, 255, 0.4)" colorString.to.rgb.percent([0, 0, 255]) // "rgb(0%, 0%, 100%)" colorString.to.keyword([255, 255, 0]) // "yellow" colorString.to.hsl([360, 100, 100]) // "hsl(360, 100%, 100%)" colorString.to.hwb([50, 3, 15]) // "hwb(50, 3%, 15%)" // all functions also support swizzling colorString.to.rgb(0, [0, 255], 0.4) // "rgba(0, 0, 255, 0.4)" colorString.to.rgb([0, 0], [255], 0.4) // "rgba(0, 0, 255, 0.4)" colorString.to.rgb([0], 0, [255, 0.4]) // "rgba(0, 0, 255, 0.4)"

Keywords

FAQs

What is color-string?

Parser and generator for CSS color strings

Is color-string popular?

The npm package color-string receives a total of 11,080,852 weekly downloads. As such, color-string popularity was classified as popular.

Is color-string well maintained?

We found that color-string demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 1 open source maintainer collaborating on the project.

Last updated on 22 Apr 2022

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc