esfunctional
Advanced tools
Comparing version 1.1.2 to 1.2.0
'use strict'; | ||
let chalk = require('chalk'); | ||
let events = require('events'); | ||
let lodash = require('lodash'); | ||
@@ -28,3 +30,3 @@ // es6 functional helpers globals | ||
*/ | ||
global._ = require('lodash'); | ||
global._ = lodash; | ||
@@ -66,2 +68,40 @@ /** | ||
/** | ||
* @name stub | ||
* @description Empty function. | ||
* @type Symbol | ||
*/ | ||
global.stub = () => {}; | ||
/** | ||
* @name all | ||
* @description Promise.all of left. | ||
* @type Symbol | ||
*/ | ||
global.all = Symbol('all'); | ||
Object.prototype[global.all] = function() { | ||
return Promise.all(this); | ||
}; | ||
/** | ||
* @name timeout | ||
* @description Time out a promise. | ||
* @type Symbol | ||
*/ | ||
global.timeout = Symbol('timeout'); | ||
Object.prototype[global.timeout] = function(msec) { | ||
return !msec ? this : Promise.race([this, new Promise((ok, nok) => ( | ||
setTimeout(() => nok(new Error('timeout')), msec) | ||
))]); | ||
}; | ||
/** | ||
* @name index | ||
* @description Get dictionary of indexes from array or single entry. | ||
* @type Symbol | ||
*/ | ||
global.index = (ent) => !ent ? {} : (ent instanceof Array ? ent : [ent]) [global.invert](); | ||
/** | ||
* @name promisify | ||
@@ -75,2 +115,3 @@ * @description Call callback-based method of object as Promise-based. | ||
let args = [].slice.call(arguments); | ||
return new Promise((ok, nok) => ( | ||
@@ -447,13 +488,3 @@ (typeof method === 'function' ? method : object[method]) | ||
// mongoose helpers | ||
/** | ||
* @function indexesFor | ||
* @description Create a function, which is called to set indexes for `Schema`. | ||
* @param {Schema} schema A schema to create index-declaring function to. | ||
* @returns {IndexMaker} A function which should be called to make indexes. | ||
*/ | ||
global.indexesFor = (schema) => (sort, opts) => (!opts || !opts.disabled) && schema.index(sort, opts) && sort; | ||
/** | ||
* @name byId | ||
@@ -465,2 +496,53 @@ * @description An object, used in hints etc. to identify usage of only `_id` path. | ||
// events | ||
/** | ||
* @name eventsEmitEsfunctionalOriginal | ||
* @description Patch builtin EventEmitter to allow wildcard events | ||
*/ | ||
if (!global.eventsEmitEsfunctionalOriginal) { | ||
global.eventsEmitEsfunctionalOriginal = events.prototype.emit; | ||
events.prototype.emit = function(type) { | ||
if (type !== '*') eventsEmitEsfunctionalOriginal.apply(this, ['*'].concat([].slice.call(arguments))); | ||
return eventsEmitEsfunctionalOriginal.apply(this, arguments); | ||
}; | ||
}; | ||
/** | ||
* @name event | ||
* @description Promisify waiting for specific events. Other events are ignored unless specified in 2nd argument | ||
* @type Symbol | ||
*/ | ||
global.event = Symbol('event'); | ||
Object.prototype[global.event] = function(subs, throws) { | ||
var _this = this; | ||
var subsIndex = index(subs); | ||
var throwsIndex = index(throws); | ||
var recur; | ||
return new Promise((ok, nok) => _this.on('*', recur = function(sub, data) { | ||
if (!(sub in throwsIndex) && subs !== '*' && !(sub in subsIndex)) return; | ||
_this.removeListener('*', recur); | ||
var ret = {event: sub, arg: data, args: [].slice.call(arguments, 1)}; | ||
if (!(sub in throwsIndex)) return ok(ret); | ||
ret.message = ret.arg && ret.arg.message; | ||
nok(ret); | ||
})); | ||
}; | ||
/** | ||
* @name eventstub | ||
* @description Stub given event types of EventEmitter | ||
* @type Symbol | ||
*/ | ||
global.eventstub = Symbol('eventstub'); | ||
Object.prototype[global.eventstub] = function() { | ||
let events = [].slice.call(arguments) [flatten](); | ||
events.forEach(event => this.on(event, global.stub)); | ||
return this; | ||
}; | ||
// test helper -- lacks | ||
@@ -467,0 +549,0 @@ |
{ | ||
"name": "esfunctional", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "Next Generation EcmaScript Functional Helpers", | ||
@@ -26,5 +26,5 @@ "main": "lib/v1/index.js", | ||
"dependencies": { | ||
"chalk": "1.1.1", | ||
"lodash": "3.10.1" | ||
"chalk": "1.1.3", | ||
"lodash": "4.10.0" | ||
} | ||
} |
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
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
20506
530
+ Addedchalk@1.1.3(transitive)
+ Addedlodash@4.10.0(transitive)
- Removedchalk@1.1.1(transitive)
- Removedlodash@3.10.1(transitive)
Updatedchalk@1.1.3
Updatedlodash@4.10.0