1.9.1 • Published 2 years ago

color-string v1.9.1

Weekly downloads
13,115,918
License
MIT
Repository
github
Last release
2 years ago

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)"
colorcuc-gaf@azurerodrigo/react-native-monorepo-icon-splash@knapsack/typeseasy-select-rnvuedragdropuploadimages@tina-form/color-fieldcloud-archive-s3bb-chat@ihikmawan/tailwindcss-multi-theme-l2human-color@fundefund/funde_ckgql_din_mod@olivervorasai/slider@mkiloyan/renderer-reactukor-remasterwilscannerscss-replacetinacms@everything-registry/sub-chunk-1355temporary-react-pdfp149-tablelightnesskafirchain-tetrislitepie-datepicker-gabelaieris-css3-colorjesusdemojibo-sdklogin-encrypt-ziong-search-dropdownnka-gantt-task-reactnode-pcb-stackup-corenode-pixelnode-pixel-asyncnglogger-acefonelulu5239mggauharmotusjupyterlab-mavenworksjsassjson2ableton-live-skinncc.jsneopixel-utilsneo4j-bloomm2m-chartjs-plugin-crosshairmeshblu-rpimicrosoft-adaptivecards-json-to-scssnois-react-toastnove-repositorynotion-database-exporternamed-web-colorsmatissemdlog@tinacms/toolkit@tinacms/fields@vechaiui/utils@southcn/ckeditor5-build-inline@sparkz-community/form-gen-client-lib@soyjak/utils@the91end/react-auth@tillschweneker/ckeditor5-build-strapi-wysiwyg-markdown@tonysusi/vapid@verticlabs/color-replace@usulpro/react-json-view@viatsyshyn/ts-color@tiger-za-pdf/render@tiger-za-pdf/stylesheet@shauncenter/react-pdf-render@shonaui/core@shortcm/qr-image@shoutem/react-form-builder@sk-web-gui/utils@sipster/react-color-picker@sitestudio/tinacms-without-better-sqlite3@spritejs/core@rnv/sdk-utils@stansaal/ckeditor5-custom-build@stayfocus/renderer-react@supernova-studio/supernova-sdk-beta@supernovaio/sdk@supernovaio/supernova-sdk@sak1sham/react-toc-highlight@xotic750/color@vue-helper/vue-keep-alive@yak-spirit/yak-swap-uiamacoabstract-thingsac-3d-viewer@zuckersalzundpfeffer/gridsome@ts-awesome/color@zenuml/core@zarcode/react-json-view@zebracompany/f_editoragcimamp-gridsomeawesome-cordova-plugins-retenoawesome-cordova-plugins-reteno-firebaseaws-lambda-redshift-loader@andromedaprotocol/utils
1.9.1

2 years ago

1.8.2

2 years ago

1.9.0

2 years ago

1.8.1

2 years ago

1.8.0

2 years ago

1.7.3

2 years ago

1.7.2

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.7.4

2 years ago

1.6.0

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.3

6 years ago

1.5.2

7 years ago

1.5.1

7 years ago

1.5.0

7 years ago

1.4.0

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.4.0

8 years ago

0.3.0

9 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.3

10 years ago

0.1.2

11 years ago

0.1.1

13 years ago

0.1.0

13 years ago