Skip to content

Latest commit

 

History

History
56 lines (44 loc) · 1.08 KB

README.md

File metadata and controls

56 lines (44 loc) · 1.08 KB

Build Status

Install

Using npm:

npm install shape-array

Usage

Shape array to a json object:

'use strict';
const shape = require('shape-array');
const personify = shape.scheme(['id', 'name', 'address.street', 'address.zip']);

let data = [1, 'John', 'github', '1234'];
let person = personify(data);
//person equals:
{
  id: 1,
  name: 'John',
  address: {
    street: 'github',
    zip: '1234'
  }
}

Reverse json to array:

const reverse = shape.reverse(['id', 'name', 'address.street', 'address.zip']);

let json = {
  id: 1,
  name: 'John',
  address: {
    street: 'github',
    zip: '1234'
  }
};
let array = reverse(json);
//array equals:
[1, 'John', 'github', '1234']

Related

License

MIT © Andre Stehle