
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
A simple dependency injection framework for Node.js inspired by Angular.js.
Inject directly into your exports functions!
module.exports = function(myDep) {
// do something awesome with myDep
};
$ npm install --save nodep
index.js
var $p = require('nodep')();
$p.init({
myVar: localVariable
}).init([
'anNpmPackage',
'./a/nested/local.dependency',
'./a.local.dependency'
]);
Use your dependencies like this:
a.local.dependency.js
module.exports = function(localDependency, myVar, anNpmPackage) {
localDependency.doStuff();
myVar.doStuff();
anNpmPackage();
};
./a/nested/local.dependency becomes localDependency is executed and injectableanNpmPackage is loaded from node_modulesmyVar is injectable./a.local.dependency becomes aLocalDependency is executed and injectable.js extension will be ignoredindex.js
var $p = require('nodep')();
$p.init('src/*').init([
'anNpmPackage',
'./a/nested/local.dependency',
'glob/patterns/*'
]);
Register other instances of nodep into your project.
index.js
var $p = require('nodep')();
$p.provider([
'anNpmPackage',
'./a.local.provider',
aLocalVariable
]).provider('anotherNpmPackage');
anNpmPackage, aLocalVariable, and anotherNpmPackage are available for injection.a.module.loaded.into.nodep.js
// $p is already available for injection
module.exports = function($p) {
var myDependency = $p.inject('myDependency');
};
// You can inject the old instance of this dependency
$p.decorator('aDependencyToOverride', function(aDependencyToOverride) {
var oldDep = aDependencyToOverride;
});
$ npm install -g gulp
$ gulp
$ gulp autotest
$ gulp docs
$ gulp changelog
functionObjectThe dependency injection provider
Kind: inner property of nodep
Example
var $p = require('nodep')();
Object
ObjectObjectObjectObjectRegExpRegExpRegExpStringRegExpStringStringStringStringStringObjectBooleanArray.<String>ObjectObject?ObjectThe dependency reference storage object
Kind: static property of $p
ObjectThe package of this library
Kind: static property of $p
ObjectThe module of $p
Kind: static property of $p
ObjectAn injectable reference to this module
Kind: static property of $p
RegExpExpression used to parse dependency names and format them to camel case
Kind: static constant of $p
RegExpExpression used to clean up trailing characters in a path
Kind: static constant of $p
RegExpExpression to remove path and .js extension when calculating the dependency name
Kind: static constant of $p
StringReplace string when evaluating PATH_REPLACE_REGEXP
Kind: static constant of $p
RegExpExpression to remove comments when parsing arguments for a dependency
Kind: static constant of $p
StringError message to send when trying to register a non-string type
Kind: static constant of $p
StringError message to send when a circular reference is detected in the dependency tree
Kind: static constant of $p
StringError message to send when trying to register a provider without dependencies
Kind: static constant of $p
StringUsed to format text into camel case
Kind: static method of $p
Returns: String - a camel case formatted result
| Param | Type | Description |
|---|---|---|
| match | String | the matched text from a replace |
| $1 | String | the first capture group |
| offset | String | the current index of the match group |
StringUsed to format dependency names from filenames
Kind: static method of $p
Returns: String - a formatted dependency name
| Param | Type | Description |
|---|---|---|
| path | String | the file path to turn into a dependency name |
Will extract the order and name of injectable arguments in a given function
Kind: static method of $p
| Param | Type | Description |
|---|---|---|
| fn | function | the function to extract injection arguments from |
Function to apply args to a new dependency and register it
Kind: static method of $p
| Param | Type | Description |
|---|---|---|
| name | String | the name of the new dependency to register |
| args | Array.<String> | the names of args to apply to the new dependeency |
| overwrite | Boolean | overwrite the current dependency |
ObjectMain dependency injection function
Dependency Handling:
$p.register./my/project/example.js$p.nameexampleKind: static method of $p
Returns: Object - a reference to this provider
| Param | Type | Description |
|---|---|---|
| name | String | the name of a dependency to register to the provider |
| dependency | ? | a value to assign to this dependency |
| [skipInject] | Boolean | inject into a provided dependency of type function unless true |
BooleanEasy dependency test, will register simple dependencies
Kind: static method of $p
Returns: Boolean - true if register was successful
| Param | Type | Description |
|---|---|---|
| path | String | the name or filepath of a dependency to register to the provider |
Default registration function in front of $p.decorator
Kind: static method of $p
| Param | Type | Description |
|---|---|---|
| paths | String | Array.<String> | the name or filepath of a dependency to register to the provider or an array of the former |
Array.<String>Function to normalize glob type paths into file paths omitting any non-js files
Kind: static method of $p
Returns: Array.<String> - an array with globbed paths normalized and merged with regular paths
| Param | Type | Description |
|---|---|---|
| paths | Array.<String> | file paths and globbed paths |
ObjectLoad one or more dependencies into the provider Loading Mechanism:
$p.registerKind: static method of $p
Returns: Object - a reference to this provider
| Param | Type | Description |
|---|---|---|
| paths | Array.<String> | Object | String | a list, key/value store, or single dependency |
ObjectLoad an existing instance of nodep into this provider
Kind: static method of $p
Returns: Object - a reference to this provider
| Param | Type | Description |
|---|---|---|
| instances | Array.<Object> | Object | String | an array of existing provider or single instance |
?Used to programmatically obtain a reference to a dependency
Kind: static method of $p
Returns: ? - a reference to the dependency with (name)
| Param | Type | Description |
|---|---|---|
| name | String | The name of the dependency to inject |
Copyright (c) 2015 Brian Jesse
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Node.js dependency injection
We found that nodep demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.