valid-web-color

1.0.1 • Public • Published

Valid Web Color

A simple utility function returning a boolean for whether or not a string is a valid web color

NPM

Example

import validWebColor from 'valid-web-color';
 
console.log(validWebColor('#fff')); // true, short hex
console.log(validWebColor('#ffffff')); // true, long hex
console.log(validWebColor('white')); // true, named color
console.log(validWebColor('rgb(255,255,255)')); // true, RedGreenBlue
console.log(validWebColor('rgba(255,255,255, 1)')); // true, RedGreenBlueAlpha
console.log(validWebColor('hsl(0, 0%,100%)')); // true, HueSaturationLightness
console.log(validWebColor('hsla(0, 0%, 100%, 1)')); // true, HueSaturationLightnessAlpha
 
console.log(validWebColor('#sagdfhdfjd')); // false, random invalid string
console.log(validWebColor({})); // false, non-string

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i valid-web-color

Weekly Downloads

114

Version

1.0.1

License

MIT

Last publish

Collaborators

  • sirrodgepodge