Comparing version 1.0.3 to 1.1.0
97
index.js
@@ -1,1 +0,96 @@ | ||
exports = module.exports = require('./use'); | ||
/*! | ||
* use <https://github.com/jonschlinkert/use> | ||
* | ||
* Copyright (c) 2015, Jon Schlinkert. | ||
* Licensed under the MIT License. | ||
*/ | ||
'use strict'; | ||
var define = require('define-property'); | ||
var isObject = require('isobject'); | ||
module.exports = function base(app) { | ||
if (!app.fns) { | ||
define(app, 'fns', []); | ||
} | ||
/** | ||
* Define a plugin function to be passed to use. The only | ||
* parameter exposed to the plugin is the application | ||
* instance. | ||
* | ||
* Also, if a plugin returns a function, the function will be pushed | ||
* onto the `fns` array, allowing the plugin to be called at a | ||
* later point, elsewhere in the application. | ||
* | ||
* ```js | ||
* var use = require('use'); | ||
* | ||
* // define a plugin | ||
* function foo(app) { | ||
* // do stuff | ||
* } | ||
* | ||
* var app = function(){}; | ||
* use(app); | ||
* | ||
* // register plugins | ||
* app.use(foo); | ||
* app.use(bar); | ||
* app.use(baz); | ||
* ``` | ||
* @name .use | ||
* @param {Function} `fn` plugin function to call | ||
* @return {Object} Returns the item instance for chaining. | ||
* @api public | ||
*/ | ||
define(app, 'use', use); | ||
/** | ||
* Run all plugins on `fns`. Any plugin that returns a function | ||
* when called by `use` is pushed onto the `fns` array. | ||
* | ||
* ```js | ||
* var config = {}; | ||
* app.run(config); | ||
* ``` | ||
* @name .run | ||
* @param {Object} `value` Object to be modified by plugins. | ||
* @return {Object} Returns the item instance for chaining. | ||
* @api public | ||
*/ | ||
define(app, 'run', function (val) { | ||
decorate(val); | ||
var len = this.fns.length, i = -1; | ||
while (++i < len) val.use(this.fns[i]); | ||
return this; | ||
}); | ||
/** | ||
* Call plugin `fn`. If a function is returned push it into the | ||
* `fns` array to be called by the `run` method. | ||
*/ | ||
function use(fn) { | ||
var plugin = fn.call(this, this); | ||
if (typeof plugin === 'function') { | ||
this.fns.push(plugin); | ||
} | ||
return this; | ||
} | ||
/** | ||
* Ensure the `.use` method exists on `val` | ||
*/ | ||
function decorate(val) { | ||
if (isObject(val) && !val.use && !val.run) { | ||
base(val); | ||
} | ||
} | ||
return app; | ||
}; |
{ | ||
"name": "use", | ||
"version": "1.0.3", | ||
"description": "DRY version of require()", | ||
"bin": { | ||
"moruga": "index.js" | ||
"description": "Easily add plugin support to your node.js application.", | ||
"version": "1.1.0", | ||
"homepage": "https://github.com/jonschlinkert/use", | ||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"repository": "jonschlinkert/use", | ||
"bugs": { | ||
"url": "https://github.com/jonschlinkert/use/issues" | ||
}, | ||
"author": "Kurt Griffiths <sffirgk@gmail.com> (http://kgriffs.com)", | ||
"keywords": [ | ||
"require", | ||
"multiple", | ||
"util" | ||
"license": "MIT", | ||
"files": [ | ||
"index.js" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/kgriffs/node-use.git" | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "node ./test.js" | ||
"test": "mocha" | ||
}, | ||
"license": "Apache 2.0", | ||
"main": "use.js" | ||
"dependencies": { | ||
"define-property": "^0.2.5", | ||
"isobject": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"base-plugins": "^0.4.1", | ||
"gulp": "^3.9.0", | ||
"gulp-eslint": "^1.1.0", | ||
"gulp-istanbul": "^0.10.2", | ||
"gulp-mocha": "^2.1.3", | ||
"mocha": "*", | ||
"should": "*" | ||
}, | ||
"verb": { | ||
"related": { | ||
"list": [ | ||
"base-methods", | ||
"ware" | ||
] | ||
} | ||
} | ||
} |
114
README.md
@@ -1,44 +0,100 @@ | ||
Use.js | ||
====== | ||
# use [![NPM version](https://badge.fury.io/js/use.svg)](http://badge.fury.io/js/use) | ||
DRY version of require() for Node.js | ||
> Easily add plugin support to your node.js application. | ||
### Installation ### | ||
## Install | ||
```bash | ||
npm install use | ||
Install with [npm](https://www.npmjs.com/) | ||
```sh | ||
$ npm i use --save | ||
``` | ||
### Example ### | ||
## Usage | ||
```javascript | ||
eval(require('use')( | ||
'util', | ||
'http', | ||
'https', | ||
'url', | ||
'path', | ||
'stream', | ||
```js | ||
var use = require('use'); | ||
``` | ||
'xregexp#XRegExp', | ||
## API | ||
'./helper' | ||
)); | ||
### [.use](index.js#L49) | ||
util.debug('Easy as pie...'); | ||
Define a plugin function to be passed to use. The only parameter exposed to the plugin is the application instance. | ||
XRegExp.replace( | ||
'x-key-lime', | ||
XRegExp('\\b\\w', 'g'), | ||
function(match) { | ||
return match.toUpperCase(); | ||
} | ||
); | ||
Also, if a plugin returns a function, the function will be pushed | ||
onto the `fns` array, allowing the plugin to be called at a | ||
later point, elsewhere in the application. | ||
helper.doSomethingGrand(); | ||
**Params** | ||
* `fn` **{Function}**: plugin function to call | ||
* `returns` **{Object}**: Returns the item instance for chaining. | ||
**Example** | ||
```js | ||
var use = require('use'); | ||
// define a plugin | ||
function foo(app) { | ||
// do stuff | ||
} | ||
var app = function(){}; | ||
use(app); | ||
// register plugins | ||
app.use(foo); | ||
app.use(bar); | ||
app.use(baz); | ||
``` | ||
### Warning ### | ||
### [.run](index.js#L65) | ||
This module does not work in strict mode. Only enable strict mode, if you need it, *after* the eval statement. | ||
Run all plugins on `fns`. Any plugin that returns a function when called by `use` is pushed onto the `fns` array. | ||
**Params** | ||
* `value` **{Object}**: Object to be modified by plugins. | ||
* `returns` **{Object}**: Returns the item instance for chaining. | ||
**Example** | ||
```js | ||
var config = {}; | ||
app.run(config); | ||
``` | ||
## Similar projects | ||
* [base-methods](https://www.npmjs.com/package/base-methods): Starter for creating a node.js application with a handful of common methods, like `set`, `get`,… [more](https://www.npmjs.com/package/base-methods) | [homepage](https://github.com/jonschlinkert/base-methods) | ||
* [ware](https://www.npmjs.com/package/ware): Easily create your own middleware layer. | [homepage](https://github.com/segmentio/ware) | ||
## Running tests | ||
Install dev dependencies: | ||
```sh | ||
$ npm i -d && npm test | ||
``` | ||
## Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/use/issues/new). | ||
## Author | ||
**Jon Schlinkert** | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
Copyright © 2015 Jon Schlinkert | ||
Released under the MIT license. | ||
*** | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on November 10, 2015._ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
6341
84
1
0
100
1
2
7
4
1
+ Addeddefine-property@^0.2.5
+ Addedisobject@^2.0.0
+ Addeddefine-property@0.2.5(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedis-accessor-descriptor@1.0.1(transitive)
+ Addedis-data-descriptor@1.0.1(transitive)
+ Addedis-descriptor@0.1.7(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisobject@2.1.0(transitive)