Socket
Socket
Sign inDemoInstall

postcss-values-parser

Package Overview
Dependencies
7
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    postcss-values-parser

A CSS property value parser for use with PostCSS


Version published
Weekly downloads
3.7M
decreased by-0.66%
Maintainers
1
Install size
77.8 kB
Created
Weekly downloads
 

Package description

What is postcss-values-parser?

The postcss-values-parser package is a tool for parsing CSS values, allowing developers to analyze and manipulate CSS strings in JavaScript. It provides a detailed AST (Abstract Syntax Tree) for CSS values, making it easier to understand and modify CSS properties programmatically.

What are postcss-values-parser's main functionalities?

Parsing CSS values

This feature allows you to parse any string representing CSS values into a structured AST. The code sample demonstrates parsing a simple CSS value string.

const parse = require('postcss-values-parser').parse;
let root = parse('10px solid black');
console.log(root.nodes);

Walking through the AST

After parsing CSS values into an AST, this feature enables walking through the AST nodes. This can be useful for analyzing or modifying specific parts of the CSS value.

const parse = require('postcss-values-parser').parse;
let root = parse('10px solid black');
root.walk((node) => console.log(node));

Modifying CSS values

This feature demonstrates how to modify CSS values after parsing. In the code sample, the size value of a CSS property is changed from '10px' to '15px'.

const parse = require('postcss-values-parser').parse;
let root = parse('10px solid black');
root.nodes[0].value = '15px';
console.log(root.toString());

Other packages similar to postcss-values-parser

Readme

Source


postcss-values-parser tests cover size

A CSS property value parser built upon PostCSS, following the same node and traversal patterns as PostCSS.

Install

Using npm:

npm install postcss-values-parser --save-dev

Please consider becoming a patron if you find this module useful.

Requirements

postcss-values-parser Node version v6.14.0+ and PostCSS v7.0.0+.

Benefits

  • Leverages PostCSS and its tokenizer under the hood
  • Doesn't strip characters; eg. parenthesis
  • Full AST traversal
  • Ability to walk the AST for every Node type
  • Convenience methods to stringify Nodes
  • Follows PostCSS patterns for whitespace between Nodes
  • Provides convenience properties for number units, colors, etc.

Usage

Using the parser is straightforward and minimalistic:

const { parse } = require('postcss-values-parser');

const root = parse('#fff');
const node = root.first;

// → Word {
//     raws: { before: '', after: '' },
//     value: '#fff',
//     type: 'word',
//     isHex: true,
//     isColor: true,
//     isVariable: false,
//     ...
//   }

Please see the Documentation for further information on using the module.

Meta

CONTRIBUTING

LICENSE (Mozilla Public License)

Keywords

FAQs

Last updated on 07 Jan 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc