factory-create

0.0.8 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i factory-create

Weekly Downloads

7

Version

0.0.8

License

MIT

Last publish

Collaborators

  • ralucas