• Stars
    star
    214
  • Rank 184,643 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 13 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Parser and generator for CSS color strings

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)"

More Repositories

1

color

🌈 Javascript color conversion and manipulation library
JavaScript
4,775
star
2

better-exceptions

Pretty and useful exceptions in Python, automatically.
Python
4,531
star
3

color-convert

Plain color conversion functions in JavaScript
JavaScript
746
star
4

tortellini

A really stupid INI file format for C++11
C++
137
star
5

tabs-are-better-than-spaces

They are. Don't fight it.
HTML
73
star
6

node-error-ex

Easy error subclassing and stack customization
CoffeeScript
62
star
7

arua-meta

Standards, RFCs and discussion of the Arua language
Vim Script
44
star
8

node-editor

Generic node editor web components
TypeScript
27
star
9

xopt

ANSI C command line options parser
C
22
star
10

node-man-api

Eases the generation of (proper) man pages
JavaScript
18
star
11

node-is-arrayish

Check if an object can be used like an Array
CoffeeScript
16
star
12

flexicon

A lightweight, regex-based lexer framework for Python
Python
12
star
13

node-simple-swizzle

Simply swizzle your arguments
CoffeeScript
11
star
14

terminfo

Parse the Terminfo database
JavaScript
8
star
15

pet

Dead simple HTTP requests
JavaScript
8
star
16

dot-dot-dash-demo

Quick demo for Dot Dot Dash
C++
7
star
17

arua.io

The Arua language website
HTML
6
star
18

xp

A regular expression search (and replace) command line tool
JavaScript
6
star
19

handler-agent

Zero-dependency (req,res) handler callback agent for use in client requests
JavaScript
6
star
20

casscade

Experimental Cassowary (Kiwi) constraint-based layouts using CSS layout worklets (Houdini layout API)
JavaScript
5
star
21

starfuse

Mount StarBound .pak files as regular directories
Python
4
star
22

scaly

Minimalistic, composable cache and database layering inspired by CPU caches
JavaScript
4
star
23

this-image-is

A Reddit bot that tells you what's in an image using neural networks.
Python
4
star
24

CaptainJack

[ABANDONED] The unofficial JACK audio device driver for OS/X
C
3
star
25

qunit

Super simple unit testing in C99
C
3
star
26

mds-lava

Lava mod for Mindustry
3
star
27

nesmap

Universal NES Map editor
CoffeeScript
3
star
28

node-smart-pipe

Pipe to standard input, cross platform
CoffeeScript
3
star
29

docopt.md

Keep your docopt configuration directly in your readme
JavaScript
2
star
30

node-high-order

Find the length of a UTF-8 glyph by its first byte
CoffeeScript
2
star
31

mds-ancients-units

ANCiENTS Mindustry Mod (Units pack)
JavaScript
2
star
32

factorio-hand-crank

Hand Crank mod for Factorio
Makefile
2
star
33

fugu

(this is a mirror, I didn't write this)
C++
2
star
34

s-storage

localStorage bindings for S.js
JavaScript
2
star
35

node-man-api-mdoc

MDoc macro extensions for man-api
JavaScript
2
star
36

node-backslash

Parse backslashed strings
JavaScript
2
star
37

bellingbot

Bellingcat discord bot
Python
2
star
38

sig-router

A URL/history API router for S.js and Surplus applications
JavaScript
2
star
39

cssquery

Simple object queries using CSS-like selector syntax. I don't recommend you actually use this.
Python
2
star
40

lucky-the-eclectus

My parrot in Discord bot format. Keeps you company; nothing more.
JavaScript
1
star
41

node-transform-domain

Transforms a value given a source and destination domain
JavaScript
1
star
42

match-file-tree

Lightweight regex based file tree traversal
JavaScript
1
star
43

node-find-api

Finds all of the API calls and docs in a source file
JavaScript
1
star
44

arua-bootstrap-2

The Arua bootstrap compiler
C++
1
star
45

libcopynes

Git mirror of libcopynes
C
1
star
46

Codicle

Just Learn.
CoffeeScript
1
star
47

node-ddb

Fixed-sized frame decoding for Node.js using ffmpeg
C++
1
star
48

test-repo

JavaScript
1
star
49

node-legos

Snap your streams together
JavaScript
1
star
50

node-require-with-globals

Safely require a module with a modified global object.
JavaScript
1
star
51

cbind

Real C-binding / argument injection (some seriously cool shit)
C
1
star
52

test-layout-api-bug

Blink engine Houdini Layout API + WebAssembly access violation reproduction
HTML
1
star
53

josh-manders-made-this

But not really.
1
star
54

beep-osx

"Hardware speaker" beep for OS X
Objective-C
1
star
55

eloquent

Make expressive APIs easily and cleanly
CoffeeScript
1
star
56

cassowary-playground

A playground for Cassowary constraints
Rust
1
star
57

mist

Mist build system
CoffeeScript
1
star
58

eslint-plugin-smelly

Find code patterns that might be code smell
JavaScript
1
star
59

mud-json

JSON driver for the Mud ORM
JavaScript
1
star
60

node-call-with-globals

Safely call a function with a modified global object.
JavaScript
1
star
61

lib-llvm-clang

LLVM.js/Clang.js dependencies for Codicle
1
star
62

node-abyss

Deep and asynchronous.
JavaScript
1
star
63

tap-dot-neo

Spiritual successor to `tap-dot`
JavaScript
1
star
64

prisoners-dilemma

Prisoners Dilemma simulator
C
1
star
65

clang-extra-npm

Installs `clang-tools-extra` for you.
Shell
1
star
66

eslint-plugin-wtf

Catch mistakes literally no developer should be making.
JavaScript
1
star
67

node-atomic-fs

Atomically perform file operations
CoffeeScript
1
star
68

did-they-seriously-rename-master

Oh my god what bullshit is this
1
star
69

riffusion-cli

Hacked together CLI for Riffusion. Please, please don't abuse this.
JavaScript
1
star
70

node-find-higher-file

Traverses a path to find a file in a higher directory
JavaScript
1
star
71

node-emplace

Emplace objects and arrays - pointer to pointer style!
CoffeeScript
1
star
72

node-has-module

Checks for the existence of a module
JavaScript
1
star
73

autotest

C/C++ unit testing on Linux as simple as writing functions
C
1
star
74

qix-.github.io

My portfolio site.
Roff
1
star
75

node-consumer-stream

Readline-like functionality that keeps track of line counts and properly handles final lines without trailing newlines
CoffeeScript
1
star
76

duplicant

Finds similar lines in a codebase and shows them as a heatmap in VSCode
Rust
1
star