
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
cssparser.js is a parser that generates json matched with source css structure.
Just want to use cssparser.js? Nothing needed.
If want generating parser, install 'jison' before it.
First of all, you should install cssparser.
$ npm install cssparser
or
$ npm install cssparser -g
Then execute and you can generate JSON file from command-line.
$ cssparser cssFile
or
$ cssparser cssFile -o output_file
You can generate javascript object from your javascript module.
// getting parser module
var cssparser = require("cssparser");
// create new instance of Parser
var parser = new cssparser.Parser();
// parse
var ast = parser.parse(raw)
// getting json
var json = ast.toJSON(type)
$ git clone https://github.com/cwdoh/cssparser.js.git
$ npm install
$ npm run build
There are 3 types of JSON format.
Example is tested with rulesets of http://css3please.com
cssparser example/test.css --console -i 4
@charset 'utf-8';
@import url("fineprint.css") print;
@media screen {
* {
position: absolute;
}
}
.footer {
position: fixed;
bottom: 0 !important;
width: 1rem;
}
[
{
"type": "@charset",
"value": "'utf-8'"
},
{
"type": "@import",
"value": "url(\"fineprint.css\")",
"mediaQuery": [
"print"
]
},
{
"type": "@media",
"value": [
"screen"
],
"nestedRules": [
{
"type": "rule",
"selectors": [
"*"
],
"declarations": {
"position": "absolute"
}
}
]
},
{
"type": "rule",
"selectors": [
".footer"
],
"declarations": {
"position": "fixed",
"bottom": "0 !important",
"width": "1rem"
}
}
]
####Type 'deep'
{
"type": "STYLESHEET",
"value": [
{
"type": "AT_RULE",
"rule": "charset",
"value": "'utf-8'"
},
{
"type": "AT_RULE",
"rule": "import",
"value": "url(\"fineprint.css\")",
"nextExpression": [
"print"
]
},
{
"type": "AT_RULE",
"rule": "media",
"value": [
"screen"
],
"nestedRules": [
{
"type": "QUALIFIED_RULE",
"value": {
"type": "DECLARATION_LIST",
"value": [
{
"type": "DECLARATION",
"property": "position",
"value": "absolute"
}
]
},
"selectors": [
"*"
]
}
]
},
{
"type": "QUALIFIED_RULE",
"value": {
"type": "DECLARATION_LIST",
"value": [
{
"type": "DECLARATION",
"property": "position",
"value": "fixed"
},
{
"type": "DECLARATION",
"property": "bottom",
"value": 0,
"important": true
},
{
"type": "DECLARATION",
"property": "width",
"value": "1rem"
}
]
},
"selectors": [
".footer"
]
}
]
}
{
"type": "STYLESHEET",
"value": [
{
"type": "AT_RULE",
"rule": {
"type": "ID",
"value": "charset",
"prefix": "@"
},
"value": {
"type": "STRING",
"value": "'utf-8'"
}
},
{
"type": "AT_RULE",
"rule": {
"type": "ID",
"value": "import",
"prefix": "@"
},
"value": {
"type": "URL",
"name": {
"type": "ID",
"value": "url"
},
"value": "\"fineprint.css\""
},
"nextExpression": {
"type": "MEDIA_QUERY_LIST",
"value": [
{
"type": "MEDIA_QUERY",
"mediaType": {
"type": "ID",
"value": "print"
}
}
]
}
},
{
"type": "AT_RULE",
"rule": {
"type": "ID",
"value": "media",
"prefix": "@"
},
"value": {
"type": "MEDIA_QUERY_LIST",
"value": [
{
"type": "MEDIA_QUERY",
"mediaType": {
"type": "ID",
"value": "screen"
}
}
]
},
"nestedRules": [
{
"type": "QUALIFIED_RULE",
"value": {
"type": "DECLARATION_LIST",
"value": [
{
"type": "DECLARATION",
"property": {
"type": "ID",
"value": "position"
},
"value": {
"type": "ID",
"value": "absolute"
}
}
]
},
"selectors": {
"type": "SELECTOR_LIST",
"value": [
{
"type": "UNIVERSAL_SELECTOR",
"value": "*"
}
]
}
}
]
},
{
"type": "QUALIFIED_RULE",
"value": {
"type": "DECLARATION_LIST",
"value": [
{
"type": "DECLARATION",
"property": {
"type": "ID",
"value": "position"
},
"value": {
"type": "ID",
"value": "fixed"
}
},
{
"type": "DECLARATION",
"property": {
"type": "ID",
"value": "bottom"
},
"value": {
"type": "NUMBER",
"value": 0
},
"important": true
},
{
"type": "DECLARATION",
"property": {
"type": "ID",
"value": "width"
},
"value": {
"type": "DIMENSION",
"value": 1,
"unit": "rem"
}
}
]
},
"selectors": {
"type": "SELECTOR_LIST",
"value": [
{
"type": "CLASS_SELECTOR",
"value": ".footer"
}
]
}
}
]
}
FAQs
parsing CSS document and transforming to JSON format
The npm package cssparser receives a total of 215 weekly downloads. As such, cssparser popularity was classified as not popular.
We found that cssparser demonstrated a not healthy version release cadence and project activity because the last version was released 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
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.