@kim-seng-chiu/jsonderulo v3.0.2
JSON Derulo
This is still a work in progress, I apologise if the documentation does not make much sense.
This package takes in data and returns it as a JSON object. Kind of like how Jason Derulo sings his name in every song.
I am not sure if the name of this package infringes on anything.
noKeys
This method can be used when the keys for the object are not important. It will determine the data type that is passed to the function.
Example
const jd = require("jsonDerulo");
const sentence = "Please put this in an object";
const returnObject = jd.noKeys(sentence);
console.log(returnObject);
// console prints
// { 0: "Please put this in an object" }specifiedKeys
Example
const jd = require("jsonDerulo");
const keys = ["id", "name", "age"];
const data = [[1, "Bethany", 23], [2, "Mike", 35], [3, "Daniel", 31]];
const toDatabase = jd.specifiedKeys(keys, data);
console.log(toDatabase);
// prints
// [{"id":1,"name":"Bethany","age":23},{"id":2,"name":"Mike","age":35},{"id":3,"name":"Daniel","age":31}]Mapper
The idea is for this function to be used with a large dataset of objects that require to be mapped to a new schema.
class Mapper takes an options argument for its constructor. The options support fields as below:
pluginsis the plugins which will be registered for thisMapper. Also see Plugin System.
class Mapper provides an instance method map with these arguments:
inputis the "raw" or original data.schemais the defined schema that the original data requires to be mapped to. This is defined here. Methodmaploops over the defined schema to find and match the corresponding values from the input.
Schema for Mapper
- The template should be a JSON object
- Each
keyshould have an object with the following attributes - Refer to JSON data types
| attribute | data type | required | values |
|---|---|---|---|
| type | string | yes | "string", "number", "boolean", "datetime", "object", "array", "set", "tags", "set(strings)" |
| mapItems | array(strings) | no | - |
| description | string | no | - |
| properties | object | yes for data type object | - |
Data types for Mapper
(documentation WIP) | data type | description of usage | | --------- | -------------------- | | string | | | number | | | boolean | | | datetime | | | object | | | array | | | set | | | tags | | | set(strings) | |
Filtering an array to extract particular values (WIP)
New Feature (Plugin System)
Roadmap for Mapper
- Refactor for consistent variable names
getPrimitivesSetto be used for set(strings | numbers)- Filtering source data that is an array with multiple conditions