require-extension-hooks
Advanced tools
Comparing version 0.1.0 to 0.2.0
26
index.js
@@ -11,2 +11,5 @@ const cache = {}; | ||
push(fn){ | ||
if (this._plugin && !fn){ | ||
fn = this._plugin; | ||
} | ||
this._extensions.forEach(ext => ext.push(fn)); | ||
@@ -16,2 +19,5 @@ return this; | ||
shift(fn){ | ||
if (this._plugin && !fn){ | ||
fn = this._plugin; | ||
} | ||
this._extensions.forEach(ext => ext.shift(fn)); | ||
@@ -22,2 +28,5 @@ return this; | ||
let args = arguments; | ||
if (this._plugin && args.length < 3){ | ||
args[2] = this._plugin; | ||
} | ||
this._extensions.forEach(ext => ext.splice.apply(ext, args)); | ||
@@ -29,2 +38,19 @@ return this; | ||
} | ||
plugin(name, options){ | ||
if (typeof name === 'function'){ | ||
this._plugin = name; | ||
}else{ | ||
try{ | ||
this._plugin = require('require-extension-hooks-' + name); | ||
}catch(e){ | ||
this._plugin = require(name); | ||
} | ||
} | ||
if (typeof this._plugin.configure === 'function'){ | ||
this._plugin.configure(options); | ||
} | ||
return this; | ||
} | ||
} | ||
@@ -31,0 +57,0 @@ |
{ | ||
"name": "require-extension-hooks", | ||
"version": "0.1.0", | ||
"description": "Add hoks for js extension types", | ||
"version": "0.2.0", | ||
"description": "Add hooks for js extension types", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -37,2 +37,6 @@ # require-extension-hooks | ||
### hook.plugin(name | fn) | ||
Loads a plugin. The plugin can either be a partial name (i.e. for *require-extension-hooks-vue* you can just type `hook.plugin('vue')`), the full name of a plugin (i.e. `hook.plugin('require-extension-hooks-vue')`) or a direct function (i.e. `hook.plugin(function(config){}`). | ||
The plugin function does not automatically append the plugin to the hook queue, you also need to tell it what to do. i.e. `hook.plugin('vue').push()`. | ||
### config | ||
@@ -39,0 +43,0 @@ A hook function takes a config object as its only argument. This object contains the following options: |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
10003
166
89
5
4