1.0.7 • Published 11 months ago

@dobuki/obj-assembler v1.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

obj-assembler


CodeQL

pages-build-deployment

npm version


Basic usage:

ObjAssembler is meant mainly to build complex JSON objects out of multiple JSON files. Commonly, you have one master JSON files that will be composed of multiple objects. Rather than have one large file, you can take pieces of them and put them into separate file.

For instance, to achieve the following:

graph TD;
    jsonA-->master;
    jsonB-->master;
    jsonC-->master;

Have your master file as follow:

master:

{
  "componentA": {
    "type": "json",
    "src": "jsonA.json"
  },
  "componentB": {
    "type": "json",
    "src": "jsonB.json"
  },
  "componentC": {
    "type": "json",
    "src": "jsonC.json"
  }
}

Then fill each child jsons with content.

jsonA:

{
   "fieldA": 123
}

jsonB:

{
   "fieldB": "this is content B"
}

jsonC:

["a", "b", "c"]

Compose the JSON using the code below:

import Assembler from "obj-assembler"

const masterJSON = loadJsonFile("master.json"); //  masterJSON should be an object.

const assembler = new Assembler();
assembler.assemble(masterJSON);

This will result in the following JSON:

{
  "componentA": {
      "fieldA": 123
  },
  "componentB": {
   "fieldB": "this is content B"
  },
  "componentC": ["a", "b", "c"]
}

See below for more advance usage.

Advanced usage readme:

link to usage

Demo

demo

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

2 years ago