ngoose
javascript object factory with defaults.
ngoose does one thing well: it create new objects with default fields values based on a schema definition.
Installation
npm install --save ngoose
Usage
const model = ; const user = ; const instance = ;console;
{ age: 0, name: "" }
You can supply data to the factory method:
const instance = ;console;
{ age: 0, name: "Garibaldi" }
Supplied fields that are not defined in schema are not inserted in created instance:
const instance = ;console;
{ age: 0, name: "Garibaldi" }
You can specify default values in schema:
const user = ; const instance=;console;
{ address: "somewhere", name: "Garibaldi" }
You can compose models with other models or with inlined objects:
const user = ; const bill = ; const instance = ; console;
{ customer: { name: 'unknown', cool: true }, payment: { terms: '', days: 30 } }
Examples
See tests for further usage examples.
License
The MIT License (MIT)
Copyright (c) 2015 parro-it