json-shaper
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "json-shaper", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Shape a flat array into a molded json shape with deep nesting", | ||
@@ -8,3 +8,3 @@ "author": "Chris Kalmar <christian.kalmar@gmail.com>", | ||
"scripts": { | ||
"test": "mocha --compilers js:babel-register --require test/setup.js -R spec --check-leaks **/*.js", | ||
"test": "mocha --compilers js:babel-register --require test/setup.js -R spec --check-leaks lib/*.js", | ||
"lint": "eslint .", | ||
@@ -11,0 +11,0 @@ "lint:fix": "eslint . --fix", |
107
README.md
@@ -5,3 +5,4 @@ # json-shaper | ||
[![Build Status](https://travis-ci.org/chriskalmar/json-shaper.svg?branch=master)](https://travis-ci.org/chriskalmar/json-shaper) | ||
[![codecov](https://codecov.io/gh/chriskalmar/json-shaper/branch/master/graph/badge.svg)](https://codecov.io/gh/chriskalmar/json-shaper) | ||
[![coverage](https://codecov.io/gh/chriskalmar/json-shaper/branch/master/graph/badge.svg)](https://codecov.io/gh/chriskalmar/json-shaper) | ||
[![npm version](https://badge.fury.io/js/json-shaper.svg)](https://www.npmjs.com/package/json-shaper) | ||
@@ -18,3 +19,107 @@ Shape a flat array into a molded json shape with deep nesting | ||
## How to use | ||
```js | ||
// import shaper | ||
import { shaper } from 'json-shaper'; | ||
// load data to be transformed | ||
import input from './data/input.js' | ||
// define a schema to shape by | ||
const schema = { | ||
id: 'id', | ||
firstName: 'first_name', | ||
lastName: 'last_name', | ||
workplace: { | ||
id: 'office_id', | ||
name: 'office_company_name', | ||
address: { | ||
street: 'company_street', | ||
postCode: 'company_postcode', | ||
country: 'company_cty', | ||
} | ||
}, | ||
isActive: 'user_is_active' | ||
} | ||
// generate transformer function based on schema | ||
const transformer = shaper(schema) | ||
// transform data | ||
const result = input.map(transformer) | ||
// profit | ||
console.log(JSON.stringify(result, null, 2)); | ||
``` | ||
#### If the input data looks like this: | ||
```js | ||
[ | ||
{ | ||
"id": 32, | ||
"first_name": "John", | ||
"last_name": "Flow", | ||
"office_id": 12, | ||
"office_company_name": "ACME Inc.", | ||
"company_street": "Rocket Street 3", | ||
"company_postcode": "11122", | ||
"company_cty": "Space City", | ||
"user_is_active": false | ||
}, | ||
{ | ||
"id": 100, | ||
"first_name": "Mike", | ||
"last_name": "", | ||
"office_id": 532, | ||
"office_company_name": "", | ||
"user_is_active": true | ||
}, | ||
... | ||
... | ||
... | ||
] | ||
``` | ||
#### json-shaper will transform it into this: | ||
```js | ||
[ | ||
{ | ||
"id": 32, | ||
"firstName": "John", | ||
"lastName": "Flow", | ||
"workplace": { | ||
"id": 12, | ||
"name": "ACME Inc.", | ||
"address": { | ||
"street": "Rocket Street 3", | ||
"postCode": "11122", | ||
"country": "Space City", | ||
} | ||
}, | ||
"isActive": false | ||
}, | ||
{ | ||
"id": 100, | ||
"firstName": "Mike", | ||
"lastName": "", | ||
"workplace": { | ||
"id": 532, | ||
"name": "", | ||
"address": {} | ||
}, | ||
"isActive": true | ||
}, | ||
... | ||
... | ||
... | ||
] | ||
``` | ||
## Performance / Benchmarks | ||
// TODO | ||
## License | ||
@@ -21,0 +126,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
127003
17
382
146