Skip to content

Pure function for emitting models from JSON defaults, reusing the Object.assign signature and including derived non-null type validation

License

Notifications You must be signed in to change notification settings

KrazyLabs/json-model-assign

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json-model-assign

Pure function for emitting factories for building models from JSON defaults, reusing the Object.assign signature and including derived non-null type validation.

Install

npm install --save json-model-assign

or

yarn add json-model-assign

Use Case

Predefining shared models (as factories) for use in both an API backend and consuming web client.

// MyModel.js
const json = '{ "id": 0, "title": "" }' // can also be an object
module.exports = require('json-model-assign')(json)

Another Use Case

Preparing a model for transport.

const modelFactory = require('MyModel')
// ... form UI ...
// model for HTTP JSON POST
const model = modelFactory({ id: formResultsId, title: formResultsTitle });

Another Use Case

Consuming an incoming event in an AWS Lambda.

const modelFactory = require('MyModel')

exports.handler = (event, context, callback) => {
  const model = modelFactory(event) // expected model with updates applied
}

About

Pure function for emitting models from JSON defaults, reusing the Object.assign signature and including derived non-null type validation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published