Goku
Transform & serialize to simple JS objects
Goku takes simple descriptors and transforms + serializes complex JS objects into simple JSON objects.
Features:
- recursion
- es6 support (class name based serialization)
- field aliases
- serialization groups
Sample
// descriptor in user-descriptor.json // aliases number: as: 'id' // always serialized firstName: true lastName: true // not serialized by default email: 'details' createdAt: 'details' children: 'details' ; const user = number: 1 firstName: 'Jane' lastName: 'Doe' email: 'jane@doe.com' createdAt: children: child1 child2 ; goku;// --› {// id: 1,// firstName: 'Jane',// lastName: 'Doe'// } goku;// --› {// id: 1,// firstName: 'Jane',// lastName: 'Doe',// email: 'jane@doe.com',// createdAt: [ Date ],// children: [// {...},// {...}// ]// }
Usage
Installation
$ npm install goku
Then
// ES6
import Goku from 'goku';
// ES5
var Goku = require('goku');
Using in an ES6 project
stage: 1 ignore: /node_modules\//
Descriptors
Defining and registering your descriptors
- direct registration
goku;goku;
- json files
// in user-descriptor.json
goku;goku;
- js files
// in user-descriptor.js firstName: true lastName: true
goku;goku;
Descriptor syntax
- always serialized
firstName: true
- conditional group based serialization
firstName: 'details'
- aliased serialization
firstName: as: 'first'
- mixed
firstName: as: 'first' groups: 'details'
Recipes
Rest APIs with Express + Goku
// initialize gokuconst goku = ;goku;goku; // middlewares for serialization { return { reqgroups = data; ; };} server; { const users = ...; res;} { const user = ...; res;} router ; router ;
Contributions
gulp watch
gulp test
# this module is written in ES6 - so it has to be transpiled
# before being published to NPM
npm publish