Skip to content

ralucas/factory-create

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Utility functions that can be used as a factory for instantiating objects

Getting Started

Install the module with: npm install factory-create

var factory = require('factory-create');

Documentation

There are 4 methods:

  • create -- This is basically a slight abstraction of the Object.create method in ES5:
var instance = factory.create(Class, {
  valueProp: { 
    writable: true,  
    configurable:true, 
    value: 'myValue' 
  },
  dataProp: {
    configurable:true, 
    get: function() { 
      return this.valueProp;
    },
    set: function(value) { 
      this.valueProp = 'newValue'; 
    }
  }
});
  • createInstance -- Creates an instance from a relative file path
var instance = factory.createInstance('./classes/anotherClass.js', params); // returns instance with methods and properties
  • createInstances -- Creates instances from a collection of file paths, returns an object of instances
var instances = factory.createInstances(instancesObj, params);
  • createFromIndex -- Creates instances from an index.js file for the current directory

Parameter: options {object} firstSplit {string} Gives the property name as the first split (i.e. redis-service.js has property redis) params {object} Parameters to pass instance instanceName {string} Pass a hash of options exclusive to that instance

var instance = factory.createFromIndex(); // Assumes creation of instances all located in same directory as index.js
module.exports = instance;

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

License

Copyright (c) 2015 Richard A. Lucas
Licensed under the MIT license.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published