Neighborly Package Megalodon
Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

css-color-checker

1.6.1 • Public • Published

Css Color Checker

npm version Build Status codecov Greenkeeper badge

A set of functions that check whether a string matches a particular color format.

import cssColorFormat from 'css-color-checker';
 
if (cssColorFormat('#FFF')) {
  console.log("It's a color!");
}
 
// Valid CSS color values return a string
cssColorFormat('#FFF'); // Returns 'hex'
cssColorFormat('#FFFFFF'); // Returns 'hex'
cssColorFormat('#FFFFFFFF'); // Returns 'hex'
cssColorFormat('rgb(255,255,255)'); // Returns 'rgb'
cssColorFormat('rgba(255,255,255,1)'); // Returns 'rgba'
cssColorFormat('hsl(0,0%,0%)'); // Returns 'hsl'
cssColorFormat('hsla(255,255,255,0.1)'); // Returns 'hsla'
cssColorFormat('hwb(360,0%,0%)'); // Returns 'hwb'
cssColorFormat('red'); // Returns 'red'
 
// Everything else return null
cssColorFormat('Not a color'); // false
cssColorFormat('#F'); // false

Installation

npm install --save css-color-checker or yarn add css-color-checker

How to use it

Note: If there is a leading or trailing space in the css color string (E.g. "#FFFFFF"), all color matching functions will return false.

Examples

See all examples here

Install

npm i css-color-checker

DownloadsWeekly Downloads

4

Version

1.6.1

License

MIT

Unpacked Size

264 kB

Total Files

28

Last publish

Collaborators

  • avatar