Package Exports
- liferay-css-parse
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (liferay-css-parse) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
css-parse 
JavaScript CSS parser for nodejs and the browser.
Installation
$ npm install css-parse
Usage
var parse = require('css-parse');
// CSS input string
var css = "body { \n background-color: #fff;\n }";
var output_obj = parse(css);
// Position and Filename parameters
var output_obj_pos = parse(css, { position: true, filename: 'file.css' });
// Print parsed object as CSS string
console.log(JSON.stringify(output_obj, null, 2));
API
var ast = parse(css, [options])
options:
filename- recommended for debuggingposition-trueby default.
Errors
Errors will have err.position where position is:
start- start line and column numbersend- end line and column numbersfilename- filename if passed to optionssource- source CSS string
If you create any errors in plugins such as in rework, you must set the position as well for consistency.
Example
css:
body {
background: #eee;
color: #888;
}parse tree:
{
"type": "stylesheet",
"stylesheet": {
"rules": [
{
"type": "rule",
"selectors": [
"body"
],
"declarations": [
{
"type": "declaration",
"property": "background",
"value": "#eee"
},
{
"type": "declaration",
"property": "color",
"value": "#888"
}
]
}
]
}
}parse tree with .position enabled:
{
"type": "stylesheet",
"stylesheet": {
"rules": [
{
"type": "rule",
"selectors": [
"body"
],
"declarations": [
{
"type": "declaration",
"property": "background",
"value": "#eee",
"position": {
"start": {
"line": 3,
"column": 3
},
"end": {
"line": 3,
"column": 19
}
}
},
{
"type": "declaration",
"property": "color",
"value": "#888",
"position": {
"start": {
"line": 4,
"column": 3
},
"end": {
"line": 4,
"column": 14
}
}
}
],
"position": {
"start": {
"line": 2,
"column": 1
},
"end": {
"line": 5,
"column": 2
}
}
}
]
}
}If you also pass in filename: 'path/to/original.css', that will be set
on node.position.filename.
Performance
Parsed 15,000 lines of CSS (2mb) in 40ms on my macbook air.
Related
License
MIT