Skip to content

Legacy utility to parse and stringify CSS declarations

License

Notifications You must be signed in to change notification settings

wooorm/css-declarations

Repository files navigation

css-declarations

Build Coverage Downloads Size

Parse and stringify CSS declarations (such as the HTML style attribute).

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

npm:

npm install css-declarations

Use

import {parse, stringify} from 'css-declarations'

var values = parse(`
  color:/*red*/purple;
  -webkit-border-radius: 3px !important;;
`)
// => {color: 'purple', webkitBorderRadius: '3px !important'}

stringify(values)
// => 'color: purple; -webkit-border-radius: 3px !important;'

API

This package exports the following identifiers: parse, stringify. There is no default export.

parse(value[, options])

Parse CSS declarations from string to object.

options.warning

When given, warning is called when an error is encountered (Function).

Returns

Object.<string> — Declarations.

stringify(values)

Serialize CSS declarations from object to string.

Returns

string — Serialized declarations.

function warning(reason, offset)

Invoked when an error occurs. Errors come from reworkcss/css.

Parameters
  • reason (string) — English reason for error;
  • offset (number) — Index-based position of error.

License

MIT © Titus Wormer