fela-plugin-validator

Fela plugin to validate style objects

Usage no npm install needed!

<script type="module">
  import felaPluginValidator from 'https://cdn.skypack.dev/fela-plugin-validator';
</script>

README

fela-plugin-validator

npm version npm downloads Bundlephobia

Enforces object validation for keyframes and rules.
Logs invalid properties to the console.
If enabled, csslint is used to check the CSS.
One might also enable automatic property deletion.

Installation

yarn add fela-plugin-validator

You may alternatively use npm i --save fela-plugin-validator.

Usage

Make sure to read the documentation on how to use plugins.

import { createRenderer } from 'fela'
import validator from 'fela-plugin-validator'

const renderer = createRenderer({
  plugins: [validator()],
})

Plugin ordering

Make sure that you place the validator plugin at the end of your plugins array - or else you may get some false error / validation messages.

Configuration

Options
 Option Value Default Description
logInvalid (boolean?)  true logs invalid properties/values
deleteInvalid (boolean?)  false deletes invalid properties/values
useCSSLint (boolean?)
(Object?)
false use CSSLint for style validation.
If an object is transferred, it will be interpreted as a set of rules for the validation (see here)
Example
import { createRenderer } from 'fela'
import validator from 'fela-plugin-validator'

const validatorPlugin = validator({
  logInvalid: true,
  deleteInvalid: true,
  useCSSLint: true,
})

const renderer = createRenderer({
  plugins: [validatorPlugin],
})

Example

If the deleteInvalid option is enabled.

Keyframe

Input

{
  '0%': {
    color: 'red'
  },
  '101%': {
    color: 'blue'
  },
  color: 'blue'
}

Output

{
  '0%': {
    color: 'red'
  }
}

Rule

Input

{
  color: 'red',
  ':hover': {
    color: 'green',
    foo: {
      color: 'blue'
    }
  },
  'nested': {
    color: 'yellow'
  }
}

Output

{
  color: 'red',
  ':hover': {
    color: 'green',
  }
}

License

Fela is licensed under the MIT License.
Documentation is licensed under Creative Commons License.
Created with ♥ by @robinweser and all the great contributors.