Gathering detailed insights and metrics for postcss-calc-ast-parser
Gathering detailed insights and metrics for postcss-calc-ast-parser
npm install postcss-calc-ast-parser
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.5
Supply Chain
99.6
Quality
75.4
Maintenance
100
Vulnerability
100
License
TypeScript (77.69%)
JavaScript (22.31%)
Total Downloads
3,864,020
Last Day
14,226
Last Week
68,051
Last Month
273,619
Last Year
2,989,428
2 Stars
21 Commits
1 Forks
3 Watching
2 Branches
1 Contributors
Latest Version
0.1.4
Package Id
postcss-calc-ast-parser@0.1.4
Unpacked Size
73.88 kB
Size
15.17 kB
File Count
39
NPM Version
6.5.0
Node Version
11.8.0
Cumulative downloads
Total Downloads
Last day
-11.1%
14,226
Compared to previous day
Last week
-10.8%
68,051
Compared to previous week
Last month
12.7%
273,619
Compared to previous month
Last year
246.5%
2,989,428
Compared to previous year
Parse the calc()
function defined in CSS and convert it to AST.
There are already various parsers of CSS and values ​​defined in CSS.
However, these parser do not have the information of calc function AST. Also, it may not be possible to use it combination with SCSS or Less.
postcss-calc-ast-parser
is a parser specialized for the calc()
(max
, min
and clamp
) functions.
We are aiming to work even when used in combination with SCSS or Less.
1npm install --save-dev postcss-calc-ast-parser
1const calcAstParser = require("postcss-calc-ast-parser") 2 3const parsed = calcAstParser.parse("calc(100%/3 - 2*1em - 2*1px)")
For example, parsing the value calc(100%/3 - 2*1em - 2*1px)
will return the following:
1{ 2 "type": "Root", 3 "nodes": [ 4 { 5 "type": "Function", 6 "name": "calc", 7 "nodes": [ 8 { 9 "type": "MathExpression", 10 "left": { 11 "type": "MathExpression", 12 "left": { 13 "type": "Percentage", 14 "value": 100, 15 "unit": "%" 16 }, 17 "operator": "/", 18 "right": { 19 "type": "Number", 20 "value": 3 21 } 22 }, 23 "operator": "-", 24 "right": { 25 "type": "MathExpression", 26 "left": { 27 "type": "MathExpression", 28 "left": { 29 "type": "Number", 30 "value": 2 31 }, 32 "operator": "*", 33 "right": { 34 "type": "Length", 35 "value": 1, 36 "unit": "em" 37 } 38 }, 39 "operator": "-", 40 "right": { 41 "type": "MathExpression", 42 "left": { 43 "type": "Number", 44 "value": 2 45 }, 46 "operator": "*", 47 "right": { 48 "type": "Length", 49 "value": 1, 50 "unit": "px" 51 } 52 } 53 } 54 } 55 ] 56 } 57 ] 58}
To know more about certain nodes in produced AST, please go AST docs.
1const calcAstParser = require("postcss-calc-ast-parser") 2 3const parsed = calcAstParser.parse("calc(100% - 20px)")
Parse the given source code.
1calcAstParser.parse( 2 code: string, 3 options?: { 4 /** 5 * Allow inline comments. default `true` 6 */ 7 allowInlineCommnets: boolean 8 } 9): AST.Root
Stringifies the given node.
1calcAstParser.stringify(node: AST.Node): string
Get the resolved type of the given math expression.
1calcAstParser.getResolvedType(expr: AST.MathExpression): 2 | "Number" | "Length" | "Angle" | "Time" | "Frequency" | "Resolution" | "Percentage" | "Flex" 3 | "Unknown" // Is includes unknown values and SCSS interpolation etc. 4 | "invalid" // Type can not be resolved.
Returns the calculated value of MathExpression
. Returns null
if it can not be resolved.
1 2calcAstParser.reduceExpression(expr: 3 | AST.MathExpression 4 | AST.Root 5 | AST.FunctionNode 6 | AST.NumberValue 7 | AST.LengthValue 8 | AST.AngleValue 9 | AST.TimeValue 10 | AST.FrequencyValue 11 | AST.ResolutionValue 12 | AST.PercentageValue 13 | AST.FlexValue 14): 15 | { 16 value: number, 17 type: "Number" | "Length" | "Angle" | "Time" | "Frequency" | "Resolution" | "Percentage" | "Flex", 18 unit?: string 19 } 20 | null
Walks each node of the given type inside parsed.nodes.
1parsed.walk(type: string | RegExp, callback: (node) => boolean | void): boolean | void
No vulnerabilities found.
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
Found 0/20 approved changesets -- score normalized to 0
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
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-01-27
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