Skip to content

Repository files navigation

factorify

Better object factories.

Installation

Install with component(1):

$ component install mikanda/factorify

Usage

varfactory=require('factorify');// build factoryvarUser=factory().sequence('seq','id-').attr('name',function(){returnrandomName();});// build object using factoryvarobject=newUser();console.log(object.name);// -> 'generated random name'

API

Factory#sequence(name, [prefix])

Makes this attribute a sequence number. Optional prefix is prepended to the number.

Factory#attr(name, fn)

Defines a new attribute for which the value is calculated using fn.

Object([defs])

Initialize new object. defs is an optional map to override attributes.

varUser=factory().attr('name',function(){return'my-name';});varuser=newUser({name: 'my-other-name'});console.log(user.name)// -> 'my-other-name'

License

MIT

About

Better object factories.

Resources

Stars

1 star

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages