JSCSSP is a CSS parser in JavaScript.
Download cssParser.js and include the file in your project.
With npm
npm install jscssp
var CSSParser = require('jscssp'); // If installed via npm
var source = 'body { font: 2em sans-serif; }';
var parser = new CSSParser();
var sheet = parser.parse(source, false, true);
var textResult = sheet.cssText()
console.log(textResult);
Because my (x)html editor based on Gecko is unable to edit CSS rules or declarations that are not implemented - and then dropped - by Gecko's Style Engine. Since a content editor for the Web does not target one browser only, I needed a way to parse and preserve all the contents of a stylesheet, including unrecognized rules or properties, comments and even whitespaces.
The code is distributed under the tri-license MPL/GPL/LGPL.
No idea, really.
Nope it is not for a real parser, not based on RegExps and with a CSS Object Model output. You can still minify the code if you need a smaller footprint but don't forget to preserve the license block.
Yeah, unfortunately… I had to downgrade the quality of my code to support that hum well hum "browser". Nuf said.
daniel at glazman dot org