0.1.0 • Published 3 years ago

@sil/jsonto v0.1.0

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

JSON To...

Convert JSON files to anything you want!

JSON to makes it possible to create any type of file using JSON data. We provide the tool, you provide the input and the template.

Why?

It is initially made to use create Sass/SCSS files from JSON. Defining settings in a json file which can be used by a frontend and automatically generate SCSS settings files.

Usage

  1. Install the script
npm install @sil/jsonto --save-dev
  1. Create a (template)#template

  2. Add the script to your package.json

{
    ...
    "scripts": {
        ...
        "build:config": "@sil/jsonto src/config.json src/scss/config.scss src/templates/my-config.template"
        ...
    }
    ...
}
  1. Run it!
npm run build:config

Template

The template engine uses (EJS)https://ejs.co/, so you can add anything in the file you want. A simple example to build a Sass config file;

my-config.template

$my-config: (
    <% Object.keys(data).forEach((key, index)=>{ -%>
        "<%- key %>": "<%- data[key]%>"<% if(index == data.length){ %>,<%}%>
    <% >}) -%>
)!default;

SCSS

For now, JSON To has been mainly used for SCSS templates. Thats why it provides a few extra functions to use with Sass. Because a json object isn't 1:1 usable in SCSS.

typeDescription
toSassValuefunctionConverts a value to a valid Sass value
toSassObjectfunctionConverts a whole object to a Sass object
sassDatastringThe full data object converted to a valid Sass list
0.1.0

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago