validate-css-value
Validate whether a CSS value is valid for a given property using real browser checks.
Given that it depends on browser-side checks it can be assumed to not work as expected outside of a browser (e.g. Node).
Installation
With npm
:
npm install validate-css-value
With yarn
:
yarn add validate-css-value
Examples
import { validate } from 'validate-css-value';
validate('background-color', 'red');
validate('background-color', 'rud');
validate('backgroundColor', 'red');
validate('backgroundColor', 'rud');
validate('border', '1px solid red');
validate('border', '-1px occasional rud');
Testing
cypress
is used for testing. yarn test
will likely work in a development environment, but may require some additional configuration in CI.
Credit
Inspired by this StackOverflow question and its answers.