Gathering detailed insights and metrics for @csstools/css-calc
Gathering detailed insights and metrics for @csstools/css-calc
Gathering detailed insights and metrics for @csstools/css-calc
Gathering detailed insights and metrics for @csstools/css-calc
npm install @csstools/css-calc
Typescript
Module System
Min. Node Version
Node Version
NPM Version
CSS (43.25%)
JavaScript (30.24%)
TypeScript (22.9%)
HTML (3.03%)
Nunjucks (0.48%)
Shell (0.1%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT-0 License
984 Stars
4,380 Commits
77 Forks
9 Watchers
6 Branches
132 Contributors
Updated on Jul 12, 2025
Latest Version
2.1.4
Package Id
@csstools/css-calc@2.1.4
Unpacked Size
69.35 kB
Size
18.91 kB
File Count
7
NPM Version
10.9.0
Node Version
22.12.0
Published on
May 27, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
Implemented from : https://drafts.csswg.org/css-values-4/ on 2023-02-17
Add CSS calc to your project:
1npm install @csstools/css-calc @csstools/css-parser-algorithms @csstools/css-tokenizer --save-dev
1import { calc } from '@csstools/css-calc'; 2 3// '20' 4console.log(calc('calc(10 * 2)'));
1import { stringify, tokenizer } from '@csstools/css-tokenizer'; 2import { parseCommaSeparatedListOfComponentValues } from '@csstools/css-parser-algorithms'; 3import { calcFromComponentValues } from '@csstools/css-calc'; 4 5const t = tokenizer({ 6 css: 'calc(10 * 2)', 7}); 8 9const tokens = []; 10 11{ 12 while (!t.endOfFile()) { 13 tokens.push(t.nextToken()); 14 } 15 16 tokens.push(t.nextToken()); // EOF-token 17} 18 19const result = parseCommaSeparatedListOfComponentValues(tokens, {}); 20 21// filter or mutate the component values 22 23const calcResult = calcFromComponentValues(result, { precision: 5, toCanonicalUnits: true }); 24 25// filter or mutate the component values even further 26 27const calcResultStr = calcResult.map((componentValues) => { 28 return componentValues.map((x) => stringify(...x.tokens())).join(''); 29}).join(','); 30 31// '20' 32console.log(calcResultStr);
precision
:The default precision is fairly high. It aims to be high enough to make rounding unnoticeable in the browser.
You can set it to a lower number to suit your needs.
1import { calc } from '@csstools/css-calc'; 2 3// '0.3' 4console.log(calc('calc(1 / 3)', { precision: 1 })); 5// '0.33' 6console.log(calc('calc(1 / 3)', { precision: 2 }));
globals
:Pass global values as a map of key value pairs.
Example : Relative color syntax (
lch(from pink calc(l / 2) c h)
) exposes color channel information as ident tokens. By passing globals forl
,c
andh
it is possible to solve nestedcalc()
's.
1import { calc } from '@csstools/css-calc'; 2 3const globals = new Map([ 4 ['a', '10px'], 5 ['b', '2rem'], 6]); 7 8// '20px' 9console.log(calc('calc(a * 2)', { globals: globals })); 10// '6rem' 11console.log(calc('calc(b * 3)', { globals: globals }));
toCanonicalUnits
:By default this package will try to preserve units. The heuristic to do this is very simplistic. We take the first unit we encounter and try to convert other dimensions to that unit.
This better matches what users expect from a CSS dev tool.
If you want to have outputs that are closes to CSS serialized values you can pass toCanonicalUnits: true
.
1import { calc } from '@csstools/css-calc'; 2 3// '20hz' 4console.log(calc('calc(0.01khz + 10hz)', { toCanonicalUnits: true })); 5 6// '20hz' 7console.log(calc('calc(10hz + 0.01khz)', { toCanonicalUnits: true })); 8 9// '0.02khz' !!! 10console.log(calc('calc(0.01khz + 10hz)', { toCanonicalUnits: false })); 11 12// '20hz' 13console.log(calc('calc(10hz + 0.01khz)', { toCanonicalUnits: false }));
No vulnerabilities found.
Reason
30 commit(s) and 7 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
1 existing vulnerabilities detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
branch protection is not maximal on development and all release branches
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 1/24 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-07-07
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