jotform / css.js

A lightweight, battle tested, fast, CSS parser in JavaScript
https://medium.com/jotform-form-builder/writing-a-css-parser-in-javascript-3ecaa1719a43
MIT License
427 stars 63 forks source link

Stringify #20

Open ctsstc opened 6 years ago

ctsstc commented 6 years ago

I would love to be able to edit the parsed object and then stringify it back to CSS.

ctsstc commented 6 years ago

Or does this already exist? I noticed there's a ton of functions prototyped/exposed on the global.cssjs = fi;

There may need to be a README update, or additional documentation added.

Maybe utilize something such as ESDoc.

ctsstc commented 6 years ago

Digging into the source I've found these nifty functions to help me with what I was already trying to do:

      const CSSJS = require("css.js");
      const CSS = new CSSJS.cssjs();

      let parsed = CSS.parseCSS(styling);
          parsed = CSS.applyNamespacing(parsed, prefix);
      let css = CSS.getCSSForEditor(parsed);
PandaWood commented 6 years ago

That's exactly what I need it for, thanks! I couldn't see any tests for applyNamespacing(), though.

PandaWood commented 6 years ago

Actually, just an addendum on this @ctsstc You could call applyNamespacing(myCss) without calling parseCss because this method checks if you're passing a string and calls parseCss for you (see around line 557 of the unminified file)