
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
postcss-values-parser
Advanced tools
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.
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());
css-tree is a CSS parser that produces an AST for CSS documents. It offers similar functionality for parsing CSS but is more focused on entire stylesheets rather than individual values. Compared to postcss-values-parser, css-tree provides a broader scope of CSS parsing capabilities.
css-what is a package for parsing CSS selectors. It provides functionality to parse selector strings into an understandable format but does not focus on CSS properties or values. While it offers parsing capabilities, its focus is different from that of postcss-values-parser, which is more centered on CSS values.
A CSS property value parser built upon PostCSS, following the same node and traversal patterns as PostCSS.
Using npm:
npm install postcss-values-parser --save-dev
Please consider becoming a patron if you find this module useful.
postcss-values-parser
Node version v6.14.0+ and PostCSS v7.0.0+.
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.
FAQs
A CSS property value parser for use with PostCSS
The npm package postcss-values-parser receives a total of 3,518,134 weekly downloads. As such, postcss-values-parser popularity was classified as popular.
We found that postcss-values-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.