JSPM

  • Created
  • Published
  • Downloads 68171864
  • Score
    100M100P100Q233655F
  • License MIT

Transforms css values into the tree

Package Exports

  • postcss-value-parser
  • postcss-value-parser/lib/unit

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (postcss-value-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Travis CI

postcss-value-parser

transforms css values into the tree

Usage

var parser = require('postcss-value-parser');

/*{
    nodes: [
      type: 'function',
      value: 'rgba',
      nodes: [
        { type: 'word', value: '233' },
        { type: 'div', value: ',', before: '', after: ' ' },
        { type: 'word', value: '45' },
        { type: 'div', value: ',', before: '', after: ' ' },
        { type: 'word', value: '66' },
        { type: 'div', value: ',', before: ' ', after: '' },
        { type: 'word', value: '.5' }
      ]
    ]
  }*/
parser('rgba(233, 45, 66 ,.5)')
  .walk('rgba', function (fn) {
    var color = fn.filter(function (node) {
      return node.type === 'word';
    }); // [233, 45, 66, .5]
    fn.type = 'word';
    fn.value = convertToHex(color);
  })
  .toString();
  // #E92D42

Node types

  • { type: 'word', value: 'any' }
  • { type: 'string', value: 'string', quote: '"' || '\'' }
  • { type: 'div', value: '/' || ',', before: ' ', after: ' ' }
  • { type: 'space', value: ' ' } space as a separator
  • { type: 'function', value: 'name', nodes: [] }

API

var parser = require('postcss-value-parser');

parser.unit(value)

Returns parsed value

// .2rem
{
  number: '.2',
  unit: 'rem'
}

parser.stringify(nodes)

Stringifies node and array of nodes

var p = parser(value)

Returns parsed tree

p.nodes

Root nodes list

p.toString()

Stringify tree to the value

p.walk([name, ]cb[, reverse])

  • name value filter
  • cb(node, index, nodes)
  • reverse walk to the deepest functions firstly

License

MIT © Bogdan Chadkin