Gathering detailed insights and metrics for postcss-value-parser
Gathering detailed insights and metrics for postcss-value-parser
Gathering detailed insights and metrics for postcss-value-parser
Gathering detailed insights and metrics for postcss-value-parser
postcss-values-parser
A CSS property value parser for use with PostCSS
figma-tokens-values-parser
A CSS property value parser for use with PostCSS
postcss-value
A value parser for PostCSS
@taktikorg/unde-animi-omnis
<p align="center"> <a href="https://www.npmjs.com/package/@taktikorg/unde-animi-omnis"><img src="https://img.shields.io/npm/v/@taktikorg/unde-animi-omnis"></a> <a href=""><img src="https://img.shields.io/github/actions/workflow/status/RemiMyrset/@taktikor
Transforms css values into the tree
npm install postcss-value-parser
Typescript
Module System
Node Version
NPM Version
99.8
Supply Chain
100
Quality
80
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
12,572,107,285
Last Day
8,342,568
Last Week
45,444,582
Last Month
195,032,783
Last Year
2,117,371,242
MIT License
144 Stars
118 Commits
23 Forks
4 Watchers
9 Branches
13 Contributors
Updated on Dec 21, 2024
Minified
Minified + Gzipped
Latest Version
4.2.0
Package Id
postcss-value-parser@4.2.0
Unpacked Size
26.56 kB
Size
7.81 kB
File Count
9
NPM Version
8.1.2
Node Version
12.22.7
Published on
Nov 29, 2021
Cumulative downloads
Total Downloads
Last Day
51.5%
8,342,568
Compared to previous day
Last Week
5.1%
45,444,582
Compared to previous week
Last Month
0.3%
195,032,783
Compared to previous month
Last Year
-3.7%
2,117,371,242
Compared to previous year
Transforms CSS declaration values and at-rule parameters into a tree of nodes, and provides a simple traversal API.
1var valueParser = require('postcss-value-parser'); 2var cssBackgroundValue = 'url(foo.png) no-repeat 40px 73%'; 3var parsedValue = valueParser(cssBackgroundValue); 4// parsedValue exposes an API described below, 5// e.g. parsedValue.walk(..), parsedValue.toString(), etc.
For example, parsing the value rgba(233, 45, 66, .5)
will return the following:
1{ 2 nodes: [ 3 { 4 type: 'function', 5 value: 'rgba', 6 before: '', 7 after: '', 8 nodes: [ 9 { type: 'word', value: '233' }, 10 { type: 'div', value: ',', before: '', after: ' ' }, 11 { type: 'word', value: '45' }, 12 { type: 'div', value: ',', before: '', after: ' ' }, 13 { type: 'word', value: '66' }, 14 { type: 'div', value: ',', before: ' ', after: '' }, 15 { type: 'word', value: '.5' } 16 ] 17 } 18 ] 19}
If you wanted to convert each rgba()
value in sourceCSS
to a hex value, you could do so like this:
1var valueParser = require('postcss-value-parser'); 2 3var parsed = valueParser(sourceCSS); 4 5// walk() will visit all the of the nodes in the tree, 6// invoking the callback for each. 7parsed.walk(function (node) { 8 9 // Since we only want to transform rgba() values, 10 // we can ignore anything else. 11 if (node.type !== 'function' && node.value !== 'rgba') return; 12 13 // We can make an array of the rgba() arguments to feed to a 14 // convertToHex() function 15 var color = node.nodes.filter(function (node) { 16 return node.type === 'word'; 17 }).map(function (node) { 18 return Number(node.value); 19 }); // [233, 45, 66, .5] 20 21 // Now we will transform the existing rgba() function node 22 // into a word node with the hex value 23 node.type = 'word'; 24 node.value = convertToHex(color); 25}) 26 27parsed.toString(); // #E92D42
Each node is an object with these common properties:
word
, string
, div
, space
, comment
, or function
).
Each type is documented below.value
property; but what exactly value
means
is specific to the node type. Details are documented for each type below.10px 20px
, the word
node
whose value is 20px
will have a sourceIndex
of 5
.The catch-all node type that includes keywords (e.g. no-repeat
),
quantities (e.g. 20px
, 75%
, 1.5
), and hex colors (e.g. #e6e6e6
).
Node-specific properties:
A quoted string value, e.g. "something"
in content: "something";
.
Node-specific properties:
"
or '
.true
if the string was not closed properly. e.g. "unclosed string
.A divider, for example
,
in animation-duration: 1s, 2s, 3s
/
in border-radius: 10px / 23px
:
in (min-width: 700px)
Node-specific properties:
,
, /
, or :
(see examples above).Whitespace used as a separator, e.g.
occurring twice in border: 1px solid black;
.
Node-specific properties:
A CSS comment starts with /*
and ends with */
Node-specific properties:
/*
and */
true
if the comment was not closed properly. e.g. /* comment without an end
.A CSS function, e.g. rgb(0,0,0)
or url(foo.bar)
.
Function nodes have nodes nested within them: the function arguments.
Additional properties:
rgb
in rgb(0,0,0)
.
in rgb( 0,0,0)
.
in rgb(0,0,0 )
.true
if the parentheses was not closed properly. e.g. ( unclosed-function
.Media features surrounded by parentheses are considered functions with an
empty value. For example, (min-width: 700px)
parses to these nodes:
1[ 2 { 3 type: 'function', value: '', before: '', after: '', 4 nodes: [ 5 { type: 'word', value: 'min-width' }, 6 { type: 'div', value: ':', before: '', after: ' ' }, 7 { type: 'word', value: '700px' } 8 ] 9 } 10]
url()
functions can be parsed a little bit differently depending on
whether the first character in the argument is a quotation mark.
url( /gfx/img/bg.jpg )
parses to:
1{ type: 'function', sourceIndex: 0, value: 'url', before: ' ', after: ' ', nodes: [ 2 { type: 'word', sourceIndex: 5, value: '/gfx/img/bg.jpg' } 3] }
url( "/gfx/img/bg.jpg" )
, on the other hand, parses to:
1{ type: 'function', sourceIndex: 0, value: 'url', before: ' ', after: ' ', nodes: [ 2 type: 'string', sourceIndex: 5, quote: '"', value: '/gfx/img/bg.jpg' }, 3] }
The unicode-range CSS descriptor sets the specific range of characters to be
used from a font defined by @font-face and made available
for use on the current page (unicode-range: U+0025-00FF
).
Node-specific properties:
var valueParser = require('postcss-value-parser');
Parses quantity
, distinguishing the number from the unit. Returns an object like the following:
1// Given 2rem 2{ 3 number: '2', 4 unit: 'rem' 5}
If the quantity
argument cannot be parsed as a number, returns false
.
This function does not parse complete values: you cannot pass it 1px solid black
and expect px
as
the unit. Instead, you should pass it single quantities only. Parse 1px solid black
, then pass it
the stringified 1px
node (a word
node) to parse the number and unit.
Stringifies a node or array of nodes.
The custom
function is called for each node
; return a string to override the default behaviour.
Walks each provided node, recursively walking all descendent nodes within functions.
Returning false
in the callback
will prevent traversal of descendent nodes (within functions).
You can use this feature to for shallow iteration, walking over only the immediate children.
Note: This only applies if bubble
is false
(which is the default).
By default, the tree is walked from the outermost node inwards.
To reverse the direction, pass true
for the bubble
argument.
The callback
is invoked with three arguments: callback(node, index, nodes)
.
node
: The current node.index
: The index of the current node.nodes
: The complete nodes array passed to walk()
.Returns the valueParser
instance.
Returns the parsed node tree.
The array of nodes.
Stringifies the node tree.
Walks each node inside parsed.nodes
. See the documentation for valueParser.walk()
above.
MIT © Bogdan Chadkin
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 16/27 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
30 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-05-05
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More