A simple, tiny, light and powerful CSS parser written completely in JavaScript and Node.js developed originally for ThetaIDE.
NOTE: This library requires Node.js. If you didn't install it, download it from the original site https://nodejs.org/en/ or run sudo apt-get install nodejs
command if you're on Ubuntu or Debian.
For an example, create an index.js file:
const cssParser = require('./cssParser.js');
const FileSystem= require('fs');
cssParser.parse(FileSystem.readFileSync("example.css").toString());
And create a CSS file called "example.css" in the same directory:
example {
background-color: blue;
color: white;
}
Finally, run node index.js
and the output will be an object describing each code block, property and value.
Example:
{ '0': { start: 9, end: 56, string: '{ background-color: blue; color: white; }', type: 'Code block', selector: '.example', 'Declaration 0': { string: ' background-color: blue;', property: [Object], start: 9, end: 34, value: [Object] }, 'Declaration 1': { string: ' color: white;', property: [Object], start: 34, end: 54, value: [Object] } } }