model-attributes
attribute meta description
const ma = require('model-attributes');
const attributes = ma.createAttributes({
att1: {},
att2: { datault: 2}
});
const object = {};
ma.setAttributes(object, attributes, {
att1: 'value1'
});
console.log(object.att1);
console.log(object.att2);
API Reference
model-attributes.setAttributes(dest, atts, src, cb, prefix) ⇒
Copies attribute values from a source object into a destination object.
Kind: static method of model-attributes
Returns: void
Param | Type | Description |
---|
dest | Object | target object to be modified |
atts | Object | attribute definitions to be used |
src | Object | origin of the data to be copied |
cb | function | callback to be executed for each copied value |
prefix | String | name prefix used for all attributes |
model-attributes.getAttribute(object, atts, path) ⇒ Any
Delivers a attribute value for a given attribute name
Kind: static method of model-attributes
Returns: Any
- attribute value
Param | Type | Description |
---|
object | Object | to query |
atts | Object | attribute definitions to be used |
path | String | attribute name |
model-attributes.getAttributes(object, attributes, options) ⇒ Object
Retrive attribute values from an object
Kind: static method of model-attributes
Returns: Object
- values
Param | Type | Description |
---|
object | Object | attribute value source |
attributes | Object | |
options | Object | |
model-attributes.createAttributes(definitions) ⇒ Object
Create attributes from its definition
Kind: static method of model-attributes
Returns: Object
- attributes
Param | Type |
---|
definitions | Object |
model-attributes.mergeAttributes(dest, atts) ⇒ Object
Merge attribute definitions
Kind: static method of model-attributes
Returns: Object
- merged definitions (dest)
Param | Type | Description |
---|
dest | Object | attribute definitions to be used also the merge target |
atts | Object | attribute definitions to be used |
install
With npm do:
npm install model-attributes
license
BSD-2-Clause