Dafit
Transform data to fit your structures.
Installation
$ npm install --save dafit
Usage
Dafit enables you to create a dynamic schema you want your data to fit.
;// import dafit from 'dafit';// then user dafit.Resolver// or// const { Resolver } = require('dafit'); const defaultValue = null; const resolveUser = id: defaultValue // if field id is present will return it if not will set it to defaultValue userfirst_name // will set firstname as the return value of the function userlast_name ` ` // will wait for any thenable (e.g Promise) to resolve { // receives a context to enable more dynamic resolving if contactwithPermissions return return } const user = id: 1 first_name: 'John' last_name: 'Cena' age: 39 const result = ;// Promise<{// id: 1, // firstname: 'John', // lastname: 'Cena', // fullName: 'John CENA', // friends: [...], // permissions: ['WRITE_DASHBOARD']// }>
You can also use a synchronuous resolver for some use case to avoid using Promises
;// const { SyncResolver } = require('dafit'); const defaultValue = null; const resolveUser = id: defaultValue // if field id is present will return it if not will set it to defaultValue userfirst_name // will set firstname as the return value of the function userlast_name ` ` // the promise will not be resolved before return const user = id: 1 first_name: 'John' last_name: 'Cena' age: 39 const result = ;// {// id: 1, // firstname: 'John', // lastname: 'Cena', // fullName: 'John CENA',// aPromise: Promise<'Hello World!'>// }
Change Log
- Changes are reported on the Github release page