@ballfish/shape_json
v0.0.6
Published
Design a schema to shape JSON object
Downloads
23
Readme
shape_json
Introduction
A tool to help for shaping properties of json object to the type and name you want.
Install
$ yarn add shape_json
const ShapeJson = require('@ballfish/shape_json')
Usage
const origin = {
campaignName: 'test',
adsetName: 'owo',
name: 'wow',
clicks: '123'
}
const schema = {
campaignName: {
to: 'campaign'
},
adsetName: {},
clicks: {
to: 'cc',
type: shape_json.type.number
}
}
const option = {
otherProperties: 'keep',
error: 'ignore',
notFoundProperties: 'give-default',
keyDuplicate: 'keep-schema'
}
console.log(ShapeJson.shape(origin, schema, option))
/**
* {
* name: 'wow',
* campaign: 'test',
* adsetName: 'owo',
* cc: 123
* }
*/