
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
@tbela99/css-parser
Advanced tools
CSS parser for node and the browser
$ npm install @tbela99/css-parser
Parse and render css in a single pass.
transform(css, transformOptions = {})
import {transform} from '@tbela99/css-parser';
const {ast, code, errors, stats} = await transform(css, {minify: true, resolveImport: true, cwd: 'files/css'});
Include ParseOptions and RenderOptions
parse(css, parseOptions = {})
const {ast, errors, stats} = await parse(css);
render(ast, RenderOptions = {});
import {render} from '@tbela99/css-parser';
// minified
const {code, stats} = render(ast, {minify: true});
console.log(code);
import {walk} from '@tbela99/css-parser';
for (const {node, parent, root} of walk(ast)) {
// do somehting
}
There are several ways to import the library into your application.
import as a module
import {transform} from '@tbela99/css-parser';
// ...
import as a CommonJS module
const {transform} = require('@tbela99/css-parser/cjs');
// ...
Programmatic import
import {transform} from '@tbela99/css-parser/web';
// ...
Javascript module
<script src="dist/web/index.js" type="module"></script>
Single JavaScript file
<script src="dist/index-umd-web.js"></script>
CSS
table.colortable td {
text-align:center;
}
table.colortable td.c {
text-transform:uppercase;
}
table.colortable td:first-child, table.colortable td:first-child+td {
border:1px solid black;
}
table.colortable th {
text-align:center;
background:black;
color:white;
}
Javascript
import {parse, render} from '@tbela99/css-parser';
const options = {minify: true, nestingRules: true};
const {code} = await parse(css, options).then(result => render(result.ast, {minify: false}));
//
console.debug(code);
Result
table.colortable {
& td {
text-align: center;
&.c {
text-transform: uppercase
}
&:first-child,&:first-child+td {
border: 1px solid #000
}
}
& th {
text-align: center;
background: #000;
color: #fff
}
}
CSS
table.colortable {
& td {
text-align: center;
&.c {
text-transform: uppercase
}
&:first-child,&:first-child+td {
border: 1px solid #000
}
}
& th {
text-align: center;
background: #000;
color: #fff
}
}
Javascript
import {parse, render} from '@tbela99/css-parser';
const options = {minify: true};
const {code} = await parse(css, options).then(result => render(result.ast, {minify: false, expandNestingRules: true}));
//
console.debug(code);
Result
table.colortable td {
text-align:center;
}
table.colortable td.c {
text-transform:uppercase;
}
table.colortable td:first-child, table.colortable td:first-child+td {
border:1px solid black;
}
table.colortable th {
text-align:center;
background:black;
color:white;
}
v0.0.1
FAQs
CSS parser for node and the browser
The npm package @tbela99/css-parser receives a total of 97 weekly downloads. As such, @tbela99/css-parser popularity was classified as not popular.
We found that @tbela99/css-parser demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.