Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use - npm Package Compare versions

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;
};

50

package.json
{
"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"
]
}
}
}

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc