
Security News
ESLint Adds Official Support for Linting HTML
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
everycss-parser
Advanced tools
Everycss-parser is a liberal CSS parser written in javascript. It follows the css syntaxe but takes some liberties allowing:
Globally:
$ npm install everycss-parser -g
In your project:
$ npm install everycss-parser --save
In your package.json:
dependencies: {
"everycss-parser": "*"
}
var
fs = require('fs'),
Parser = require('everycss-parser');
fs.readFile('some.css', 'utf-8', function (error, data) {
if (error) {
return console.log(error);
}
// return object representation of `some.css`
(new Parser()).parse(data);
});
Everycss outputs a plain object representing your css. This object is the root
of your css and contains all top level elements.
The elements are:
Root, rules and at-rules share the same object structure:
attribute | value | Description |
---|---|---|
type | 'root', 'rule' or 'at-rule' | type of the block |
selector | selector or null | selectors of the block |
atKeyword | string or null | at-rule keyword without leading '@' |
opened | bool | if the block has brackets (eg: @import 'some.css'; is not) |
content | array | content of the block |
attribute | value | Description |
---|---|---|
type | 'declaration' | |
property | string | type of the block |
value | value | values for the property |
Values, selectors and parenthesis share the same object structure:
attribute | value | Description |
---|---|---|
type | 'value', 'selector' or 'parenthesis' | type of the block |
content | string or array | content of the selection |
Collections content could be represented in four ways according to a given precision. Values and parenthesis use the valuePrecision
attribute and selectors use the selectorPrecision
one.
parser = new Parser();
parser.valuePrecision = 1;
parser.selectorPrecision = 1;
Collection content is represented as a string like:
'foo 1px+2px, bar 3px'
Each comma separated values is represented as an element of the collection
's content array:
[
'foo 1px+2px',
'bar 3px'
]
Like for precision 1 but each comma separated values is represented as an array of space separated values:
[
['foo', '1px+2px'],
['bar', '3px']
]
Like for precision 2 but each space separated values is represented as an array of tokens:
[
[
[
{
"type": "identifier",
"value": "foo"
}
],
[
{
"type": "number",
"unit": "px",
"value": 1
},
{
"type": "operator",
"value": "+"
},
{
"type": "number",
"unit": "px",
"value": 2
}
]
],
[
[
{
"type": "identifier",
"value": "bar"
}
],
[
{
"type": "number",
"unit": "px",
"value": 3
}
]
]
]
attribute | value | Description |
---|---|---|
type | 'function' | |
keyword | string | function name |
arguments | value | arguments passed to the function |
attribute | value | Description |
---|---|---|
type | 'number' | |
unit | string or null | unit of the number |
value | float | value of the number |
attribute | value | Description |
---|---|---|
type | 'identifier' | |
quote | ''' or '"' | the quote used |
value | string | the unquoted string |
3 or 6 chars Hex colors
attribute | value | Description |
---|---|---|
type | 'color' | |
value | string | 3 or 6 chars hex value without leading '#' |
Identifiers are unquoted words like center
or auto
.
attribute | value | Description |
---|---|---|
type | 'identifier' | |
value | string | the identifier |
Everycss parses comment and inline comment. Inline comments are not allowed in CSS but are oftenly used by processors.
attribute | value | Description |
---|---|---|
type | 'comment' | |
inline | bool | If the comment is inline (// ) or not (/* */ ) |
value | string | the comment (/* , */ and // are preserved) |
Are operators are charIdentifiers are unquoted words like center
or auto
.
attribute | value | Description |
---|---|---|
type | 'identifier' | |
value | string | the identifier |
FAQs
Liberal CSS parser
We found that everycss-parser 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
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.