parse-latin
Advanced tools
Comparing version 0.4.0-rc.1 to 0.4.0-rc.2
@@ -327,49 +327,100 @@ /**! | ||
/** | ||
* @param {string} key | ||
* @param {Function|Array.<Function>} plugin | ||
* @this {ParseLatin|Object} | ||
* Factory to inject `plugins`. Takes `callback` for | ||
* the actual inserting. | ||
* | ||
* @param {fucntion(Object, string, Array.<Function>)} callback | ||
* @return {function(string, Array.<Function>)} | ||
*/ | ||
parseLatinPrototype.use = function (key, plugin) { | ||
var self, | ||
wareKey; | ||
self = this; | ||
function useFactory(callback) { | ||
/** | ||
* Throw if the method is not pluggable. | ||
* Validate if `plugins` can be inserted. Invokes | ||
* the bound `callback` to do the actual inserting. | ||
* | ||
* @param {string} key - Method to inject on | ||
* @param {Array.<Function>|Function} plugins - One | ||
* or more plugins. | ||
*/ | ||
if (!(key in self)) { | ||
throw new Error( | ||
'Illegal Invocation: Unsupported `key` for ' + | ||
'`use(key, plugin)`. Make sure `key` is a ' + | ||
'supported function' | ||
); | ||
} | ||
return function (key, plugins) { | ||
var self, | ||
wareKey; | ||
/** | ||
* Fail silently when no plugin is given. | ||
*/ | ||
self = this; | ||
if (!plugin) { | ||
return; | ||
} | ||
/** | ||
* Throw if the method is not pluggable. | ||
*/ | ||
wareKey = key + 'Plugins'; | ||
if (!(key in self)) { | ||
throw new Error( | ||
'Illegal Invocation: Unsupported `key` for ' + | ||
'`use(key, plugins)`. Make sure `key` is a ' + | ||
'supported function' | ||
); | ||
} | ||
if (typeof plugin === 'function') { | ||
plugin = [plugin]; | ||
} else { | ||
plugin = plugin.concat(); | ||
} | ||
/** | ||
* Fail silently when no plugins are given. | ||
*/ | ||
if (self[wareKey]) { | ||
self[wareKey] = self[wareKey].concat(plugin); | ||
} else { | ||
self[wareKey] = plugin; | ||
} | ||
}; | ||
if (!plugins) { | ||
return; | ||
} | ||
wareKey = key + 'Plugins'; | ||
/** | ||
* Make sure `plugins` is a list. | ||
*/ | ||
if (typeof plugins === 'function') { | ||
plugins = [plugins]; | ||
} else { | ||
plugins = plugins.concat(); | ||
} | ||
/** | ||
* Make sure `wareKey` exists. | ||
*/ | ||
if (!self[wareKey]) { | ||
self[wareKey] = []; | ||
} | ||
/** | ||
* Invoke callback with the ware key and plugins. | ||
*/ | ||
callback(self, wareKey, plugins); | ||
}; | ||
} | ||
/** | ||
* Inject `plugins` to modifiy the result of the method | ||
* at `key` on the operated on context. | ||
* | ||
* @param {string} key | ||
* @param {Function|Array.<Function>} plugins | ||
* @this {ParseLatin|Object} | ||
*/ | ||
parseLatinPrototype.use = useFactory(function (context, key, plugins) { | ||
context[key] = context[key].concat(plugins); | ||
}); | ||
/** | ||
* Inject `plugins` to modifiy the result of the method | ||
* at `key` on the operated on context, before any other. | ||
* | ||
* @param {string} key | ||
* @param {Function|Array.<Function>} plugins | ||
* @this {ParseLatin|Object} | ||
*/ | ||
parseLatinPrototype.useFirst = useFactory(function (context, key, plugins) { | ||
context[key] = plugins.concat(context[key]); | ||
}); | ||
/** | ||
* Create a `WordNode` with its children set to a single | ||
@@ -376,0 +427,0 @@ * `TextNode`, its value set to the given `value`. |
{ | ||
"name": "parse-latin", | ||
"version": "0.4.0-rc.1", | ||
"version": "0.4.0-rc.2", | ||
"description": "Latin-script (natural language) parser", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
73800
1610
0