
Company News
Socket Joins New OpenJS Program to Fund Node.js Security Work
Socket is joining the OpenJS Security Stewardship Program to fund Node.js vulnerability research, maintainer remediation, and security releases.
@csstools/css-tokenizer
Advanced tools
Implemented from : https://drafts.csswg.org/css-syntax/
Add CSS Tokenizer to your project:
npm install @csstools/css-tokenizer --save-dev
import { tokenize } from '@csstools/css-tokenizer';
const myCSS = `@media only screen and (min-width: 768rem) {
.foo {
content: 'Some content!' !important;
}
}
`;
const tokens = tokenize({
css: myCSS,
});
console.log(tokens);
Or use the streaming interface:
import { tokenizer, TokenType } from '@csstools/css-tokenizer';
const myCSS = `@media only screen and (min-width: 768rem) {
.foo {
content: 'Some content!' !important;
}
}
`;
const t = tokenizer({
css: myCSS,
});
while (true) {
const token = t.nextToken();
if (token[0] === TokenType.EOF) {
break;
}
console.log(token);
}
{
onParseError?: (error: ParseError) => void
}
onParseErrorThe tokenizer is forgiving and won't stop when a parse error is encountered.
To receive parsing error information you can set a callback.
import { tokenizer, TokenType } from '@csstools/css-tokenizer';
const t = tokenizer({
css: '\\',
}, { onParseError: (err) => console.warn(err) });
while (true) {
const token = t.nextToken();
if (token[0] === TokenType.EOF) {
break;
}
}
Parser errors will try to inform you where in the tokenizer logic the error happened. This tells you what kind of error occurred.
PostCSS is a tool for transforming CSS with JavaScript plugins. It includes a tokenizer and parser, making it a more comprehensive tool compared to @csstools/css-tokenizer, which focuses solely on tokenization.
CSSTree is a toolset for CSS including a fast detailed parser, walker, generator, and lexer. It provides more advanced features like AST generation and manipulation, whereas @csstools/css-tokenizer focuses on tokenization.
The 'css' package is a CSS parser and stringifier. It provides a full parser that converts CSS into an AST and back, offering more functionality than just tokenization, which is the primary focus of @csstools/css-tokenizer.
FAQs
Tokenize CSS
The npm package @csstools/css-tokenizer receives a total of 67,936,479 weekly downloads. As such, @csstools/css-tokenizer popularity was classified as popular.
We found that @csstools/css-tokenizer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.

Company News
Socket is joining the OpenJS Security Stewardship Program to fund Node.js vulnerability research, maintainer remediation, and security releases.

Security News
Two compromised GitHub Actions were re-enabled with malicious tags intact, exposing thousands of downstream repositories to Mini Shai-Hulud.

Research
/Security News
A malicious Firefox extension fetches its payload after installation to evade detection, steal Google session cookies, and automate account takeover.