validate-css-value
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

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';

// With kebab-case.
validate('background-color', 'red'); // => true
validate('background-color', 'rud'); // => false

// With camelCase.
validate('backgroundColor', 'red'); // => true
validate('backgroundColor', 'rud'); // => false

// Supports more than just colors, including shorthand values.
validate('border', '1px solid red');       // => true
validate('border', '-1px occasional rud'); // => false

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.

Readme

Keywords

none

Package Sidebar

Install

npm i validate-css-value

Weekly Downloads

2

Version

0.2.1

License

Apache-2.0

Unpacked Size

27.9 kB

Total Files

15

Last publish

Collaborators

  • dobs