base-option
Advanced tools
Comparing version 0.6.2 to 0.7.0
52
index.js
@@ -15,2 +15,3 @@ /*! | ||
if (this.isRegistered('base-options')) return; | ||
var Options = utils.Options; | ||
@@ -21,11 +22,12 @@ var define = utils.define; | ||
// shallow clone options | ||
var opts = utils.merge({}, options); | ||
var self = this; | ||
// original constructor reference | ||
var ctor = this.constructor; | ||
Options.call(this, utils.merge(this.options, opts)); | ||
Options.call(this, utils.merge(this.options, options)); | ||
/** | ||
* Mixin `Options.prototype` methods | ||
*/ | ||
this.visit('define', Options.prototype); | ||
var opts = this.options; | ||
@@ -46,4 +48,4 @@ /** | ||
define(this.option, 'set', function(key, val) { | ||
set(self.options, key, val); | ||
return self.options; | ||
set(opts, key, val); | ||
return opts; | ||
}); | ||
@@ -66,3 +68,3 @@ | ||
define(this.option, 'get', function(key) { | ||
return get(self.options, key); | ||
return get(opts, key); | ||
}); | ||
@@ -85,20 +87,30 @@ | ||
define(this.option, 'create', function(options) { | ||
var opts = new Options(utils.merge({}, self.options)); | ||
define(opts, 'merge', opts.option.bind(opts)); | ||
define(opts, '_callbacks', opts._callbacks); | ||
var inst = new Options(utils.merge({}, opts)); | ||
if (options) { | ||
opts.merge.apply(opts, arguments); | ||
inst.option.apply(inst, arguments); | ||
} | ||
return opts; | ||
define(inst.options, 'set', function(key, val) { | ||
set(this, key, val); | ||
return this; | ||
}); | ||
define(inst.options, 'get', function(key) { | ||
return get(this, key); | ||
}); | ||
define(inst.options, 'merge', function() { | ||
var args = [].concat.apply([], [].slice.call(arguments)); | ||
args.unshift(this); | ||
return utils.merge.apply(utils.merge, args); | ||
}); | ||
define(inst, '_callbacks', inst._callbacks); | ||
return inst.options; | ||
}); | ||
// restore original constructor | ||
this.constructor = ctor; | ||
// prevent the plugin from | ||
// being passed to `run` | ||
if (opts.run !== false) { | ||
return fn; | ||
} | ||
define(this, 'constructor', ctor); | ||
return fn; | ||
}; | ||
}; |
{ | ||
"name": "base-option", | ||
"description": "Adds a few options methods to base, like `option`, `enable` and `disable`. See the readme for the full API.", | ||
"version": "0.6.2", | ||
"version": "0.7.0", | ||
"homepage": "https://github.com/node-base/base-option", | ||
@@ -6,0 +6,0 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", |
@@ -215,3 +215,3 @@ # base-option [![NPM version](https://img.shields.io/npm/v/base-option.svg)](https://www.npmjs.com/package/base-option) [![Build Status](https://img.shields.io/travis/node-base/base-option.svg)](https://travis-ci.org/node-base/base-option) | ||
### [.option.set](index.js#L43) | ||
### [.option.set](index.js#L45) | ||
@@ -233,3 +233,3 @@ Set option `key` on `app.options` with the given `value` | ||
### [.option.get](index.js#L62) | ||
### [.option.get](index.js#L64) | ||
@@ -251,3 +251,3 @@ Get option `key` from `app.options` | ||
### [.option.create](index.js#L80) | ||
### [.option.create](index.js#L82) | ||
@@ -314,2 +314,2 @@ Returns a shallow clone of `app.options` with all of the options methods, as well as a `.merge` method for merging options onto the cloned object. | ||
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on March 02, 2016._ | ||
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on March 09, 2016._ |
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
11343
110
0