Dependency injection for node.js
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.editorconfig
.eslintrc
.gitignore
.travis.yml
index.js
package.json
readme.md

readme.md

Build Status

Fuxor

Very simple DI for node.

const fuxor = require('fuxor');
fuxor.add('fs', {
	readFileSync: function () {
		return 'Not really a file';
	}
});
const fs = require('fs');
console.log(fs.readFileSync('not really', 'anything', { whatever:'you want'}));//'Not really a file'

API

Add

const fuxor = require('fuxor');
// Add one entry to be overridden 
fuxor.add('fs', {
  readFileSync: function () {
    return 'Not really a file';
  }
});
// Add one entry to be overridden 
fuxor.add({ name: 'fs', result: {
  readFileSync: function () {
    return 'Not really a file';
  }
}});
// Add multiple entries at once
fuxor.add([{ name: 'fs', result: {
  readFileSync: function () {
    return 'Not really a file';
  }
}, {
  name: 'request',
  result: function () {
    return 'Not really a file';
  }
}]);

Clear

const fuxor = require('fuxor');
// After items have been added
fuxor.clear(); // All entries have been removed

remove

const fuxor = require('fuxor');
// After items have been added
fuxor.remove('your-module'); // The module has been removed

reset

const fuxor = require('fuxor');
// After items have been added
fuxor.reset(); // require now works back to normal