Skip to content

Latest commit

 

History

History
43 lines (32 loc) · 1.11 KB

README.md

File metadata and controls

43 lines (32 loc) · 1.11 KB

json-to-constant

Create constants out of json files to be use as fixtures for unit tests, or however you see fit.

The available command line options are:

  • --source (alias: -s, required) {string} - source folder path

  • --output (alias: -o, optional) {string} - output folder path

  • --uppercase (alias: -u, optional) {boolean} - flag to indicate if constant name should be all uppercase (ex. MY_CONSTANT vs my_constant)

    • If no output is provided source is used as the output folder.

This is a simple node program that takes Json files and create TS files exporting a constant with the json object as the value. It uses the name of the file as the name of the constant, for example:

  • JSON file (people.json)
{
    "name": "John Smith",
    "age": 45,
    "gender": "male"
}
  • Created ts file
    export constant people = {
        'name': 'John Smith',
        'age': 45,
        'gender': 'male'
    };

Using it via npm scripts

{
    "scripts": {
        "fixtures": "json-to-constant -s fixtures -o converted-fixtures -u false"
    }
}