| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
CSS parser / stringifier.
$ npm install css
var css = require('css');
var obj = css.parse('body { font-size: 12px; }', options);
css.stringify(obj, options);Accepts a CSS string and returns an AST object.
options:
var ast = css.parse('body { font-size: 12px; }', { source: 'source.css' });Errors will have error.position, just like node.position. The error contains the source position in the message. To get the error message without the position use error.reason.
If you create any errors in plugins such as in rework, you must set the position as well for consistency.
All nodes have the following properties.
Information about the position in the source string that corresponds to the node.
Object:
The line and column numbers are 1-based: The first line is 1 and the first column of a line is 1 (not 0).
The position property lets you know from which source file the node comes from (if available), what that file contains, and what part of that file was parsed into the node.
String. The possible values are the ones listed in the Types section below.
A reference to the parent node, or null if the node has no parent.
The available values of node.type are listed below, as well as the available properties of each node (other than the common properties listed above.)
The root node returned by css.parse.
A rule-level or declaration-level comment. Comments inside selectors, properties and values etc. are lost.
The @charset at-rule.
The @custom-media at-rule.
The @document at-rule.
The @font-face at-rule.
The @host at-rule.
The @import at-rule.
The @keyframes at-rule.
The @media at-rule.
The @namespace at-rule.
The @page at-rule.
The @supports at-rule.
CSS:
body {
background: #eee;
color: #888;
}Parse tree:
{
"type": "stylesheet",
"stylesheet": {
"rules": [
{
"type": "rule",
"selectors": [
"body"
],
"declarations": [
{
"type": "declaration",
"property": "background",
"value": "#eee",
"position": {
"start": {
"line": 2,
"column": 3
},
"end": {
"line": 2,
"column": 19
}
}
},
{
"type": "declaration",
"property": "color",
"value": "#888",
"position": {
"start": {
"line": 3,
"column": 3
},
"end": {
"line": 3,
"column": 14
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 4,
"column": 2
}
}
}
]
}
}MIT
| Back | FazBrowse Home | New Git URL |