@ballfish/shape_json

Design a schema to shape JSON object

Usage no npm install needed!

<script type="module">
  import ballfishShapeJson from 'https://cdn.skypack.dev/@ballfish/shape_json';
</script>

README

shape_json

NPM version

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
 * }
 */