Convert JSON config files to SCSS!
How many times do you need to access some variable which you've stored in a SCSS file in your JavaScript? Won't be it great if you could share the same variables in JavaScript and SCSS?
With this library, you can store your variables in JSON and convert it to SCSS just before building the files. It supports plain strings as well as lists and maps, even nested ones.
Sample JSON data:
{
"blueviolet": "#7366bd",
"bittersweetshimmer": "#bf4f51",
"breakpoints": [ 320, 480, 720 ]
}
Gnereated SCSS code:
$blueviolet: #7366bd;
$bittersweetshimmer: #bf4f51;
$breakpoints: ( 320, 480, 720 );
To use the command line version, globally install json2scss
,
npm install -g json2scss
To convert a JSON file to SCSS, run,
json2scss input.json > output.scss
And you're done.
To use it in the code, locally install json2scss
,
npm install --save-dev json2scss
To convert a JSON string or plain object into SCSS,
var json2scss = require("json2scss"),
json = require("./data.json");
console.log(json2scss(json));