encode-postcss-container
Encodes a postcss container into a JavaScript object.
Install
npm install encode-postcss-container
Usage
const fs = require('fs');
const postcss = require('postcss');
const promisify = require('promisify');
const encodePostCSSContainer = require('encode-postcss-container');
const readFile = promisify(fs.readFile, fs);
readFile('pato/tp/your.css', 'utf8')
.then((css) => {
return postcss([
plugin1,
plugin2,
...
])
.process(css);
})
.then((result) => {
const encoded = encodePostCSSContainer(result.root);
console.log(encoded);
console.log(encodePostCSSContainer.decode(encoded));
})
.use(require('middleware-static-livereload')({
documentRoot: '/server',
}))
.listen(3000);
Sample 1
@media (max-width: 500px) {
main {
width: 400px
}
}
yields
{
"encoded": [
[3, [2, [0, 1]]]
],
"data": [
"width",
"400px",
"main",
"@media (max-width: 500px)"
]
}
Sample 2
.classA {
color: blue
}
.classB {
color: blue
}
.classA>.classB {
color: blue
}
yields
{
"encoded": [
[2, [0, 1]],
[3, [0, 1]],
[4, [0, 1]]
],
"data": [
"color",
"blue",
".classA",
".classB",
".classA>.classB"
]
}
License
MIT