Comparing version 0.0.3 to 0.1.0
255
index.d.ts
@@ -176,2 +176,7 @@ /* Type definitions for Navybird. | ||
/** | ||
* Like `.catch` but instead of catching all types of exceptions, it only catches those that don't originate from thrown errors but rather from explicit rejections. | ||
*/ | ||
error<U>(onReject: (reason: any) => U | PromiseLike<U>): Navybird<U>; | ||
/** | ||
* Pass a handler that will be called regardless of this promise's fate. Returns a new promise chained from this promise. | ||
@@ -234,2 +239,27 @@ * | ||
/** | ||
* Returns a promise that will be fulfilled with this promise's fulfillment value or rejection reason. | ||
* However, if this promise is not fulfilled or rejected within ms milliseconds, the returned promise | ||
* is rejected with a TimeoutError or the error as the reason. | ||
* | ||
* You may specify a custom error message with the `message` parameter. | ||
*/ | ||
timeout(ms: number, message?: string | Error): Navybird<R>; | ||
/** | ||
* Register a node-style callback on this promise. | ||
* | ||
* When this promise is is either fulfilled or rejected, | ||
* the node callback will be called back with the node.js convention where error reason is the first argument and success value is the second argument. | ||
* The error argument will be `null` in case of success. | ||
* If the `callback` argument is not a function, this method does not do anything. | ||
*/ | ||
nodeify(callback: (err: any, value?: R) => void, options?: Navybird.SpreadOption): this; | ||
nodeify(...sink: any[]): this; | ||
asCallback( | ||
callback: (err: any, value?: R) => void, | ||
options?: Navybird.SpreadOption | ||
): this; | ||
asCallback(...sink: any[]): this; | ||
/** | ||
* Synchronously inspect the state of this `promise`. The `PromiseInspection` will represent the state of | ||
@@ -260,10 +290,104 @@ * the promise as snapshotted at the time of calling `.reflect()`. | ||
/** | ||
* Convenience method for: | ||
* | ||
* <code> | ||
* .then(function() { | ||
* throw reason; | ||
* }); | ||
* </code> | ||
* Same limitations apply as with `.return()`. | ||
* | ||
* Alias `.thenThrow();` for compatibility with earlier ECMAScript version. | ||
*/ | ||
throw(reason: Error): Navybird<never>; | ||
thenThrow(reason: Error): Navybird<never>; | ||
/** | ||
* Convenience method for: | ||
* | ||
* <code> | ||
* .catch(function() { | ||
* return value; | ||
* }); | ||
* </code> | ||
* | ||
* in the case where `value` doesn't change its value. That means `value` is bound at the time of calling `.catchReturn()` | ||
*/ | ||
catchReturn<U>(value: U): Navybird<R | U>; | ||
// No need to be specific about Error types in these overrides, since there's no handler function | ||
catchReturn<U>( | ||
filter1: CatchFilter<Error>, | ||
filter2: CatchFilter<Error>, | ||
filter3: CatchFilter<Error>, | ||
filter4: CatchFilter<Error>, | ||
filter5: CatchFilter<Error>, | ||
value: U | ||
): Navybird<R | U>; | ||
catchReturn<U>( | ||
filter1: CatchFilter<Error>, | ||
filter2: CatchFilter<Error>, | ||
filter3: CatchFilter<Error>, | ||
filter4: CatchFilter<Error>, | ||
value: U | ||
): Navybird<R | U>; | ||
catchReturn<U>( | ||
filter1: CatchFilter<Error>, | ||
filter2: CatchFilter<Error>, | ||
filter3: CatchFilter<Error>, | ||
value: U | ||
): Navybird<R | U>; | ||
catchReturn<U>( | ||
filter1: CatchFilter<Error>, | ||
filter2: CatchFilter<Error>, | ||
value: U | ||
): Navybird<R | U>; | ||
catchReturn<U>(filter1: CatchFilter<Error>, value: U): Navybird<R | U>; | ||
/** | ||
* Convenience method for: | ||
* | ||
* <code> | ||
* .catch(function() { | ||
* throw reason; | ||
* }); | ||
* </code> | ||
* Same limitations apply as with `.catchReturn()`. | ||
*/ | ||
catchThrow(reason: Error): Navybird<R>; | ||
// No need to be specific about Error types in these overrides, since there's no handler function | ||
catchThrow( | ||
filter1: CatchFilter<Error>, | ||
filter2: CatchFilter<Error>, | ||
filter3: CatchFilter<Error>, | ||
filter4: CatchFilter<Error>, | ||
filter5: CatchFilter<Error>, | ||
reason: Error | ||
): Navybird<R>; | ||
catchThrow( | ||
filter1: CatchFilter<Error>, | ||
filter2: CatchFilter<Error>, | ||
filter3: CatchFilter<Error>, | ||
filter4: CatchFilter<Error>, | ||
reason: Error | ||
): Navybird<R>; | ||
catchThrow( | ||
filter1: CatchFilter<Error>, | ||
filter2: CatchFilter<Error>, | ||
filter3: CatchFilter<Error>, | ||
reason: Error | ||
): Navybird<R>; | ||
catchThrow( | ||
filter1: CatchFilter<Error>, | ||
filter2: CatchFilter<Error>, | ||
reason: Error | ||
): Navybird<R>; | ||
catchThrow(filter1: CatchFilter<Error>, reason: Error): Navybird<R>; | ||
/** | ||
* Like calling `.then`, but the fulfillment value or rejection reason is assumed to be an array, which is flattened to the formal parameters of the handlers. | ||
*/ | ||
spread<U, W>( | ||
fulfilledHandler: (...values: W[]) => U | PromiseLike<U> | ||
): Navybird<U>; | ||
spread<U>( | ||
fulfilledHandler: (...args: any[]) => U | PromiseLike<U> | ||
): Navybird<U>; | ||
spread<U, W>(fulfilledHandler: (...values: W[]) => U | PromiseLike<U>): Navybird<U>; | ||
spread<U>(fulfilledHandler: (...args: any[]) => U | PromiseLike<U>): Navybird<U>; | ||
@@ -290,8 +414,3 @@ /** | ||
reduce<Q, U>( | ||
reducer: ( | ||
memo: U, | ||
item: Q, | ||
index: number, | ||
arrayLength: number | ||
) => U | PromiseLike<U>, | ||
reducer: (memo: U, item: Q, index: number, arrayLength: number) => U | PromiseLike<U>, | ||
initialValue?: U | ||
@@ -304,7 +423,3 @@ ): Navybird<U>; | ||
each<R, U>( | ||
iterator: ( | ||
item: R, | ||
index: number, | ||
arrayLength: number | ||
) => U | PromiseLike<U> | ||
iterator: (item: R, index: number, arrayLength: number) => U | PromiseLike<U> | ||
): Navybird<R[]>; | ||
@@ -316,7 +431,3 @@ | ||
eachSeries<R, U>( | ||
iterator: ( | ||
item: R, | ||
index: number, | ||
arrayLength: number | ||
) => U | PromiseLike<U> | ||
iterator: (item: R, index: number, arrayLength: number) => U | PromiseLike<U> | ||
): Navybird<R[]>; | ||
@@ -328,7 +439,3 @@ | ||
mapSeries<R, U>( | ||
iterator: ( | ||
item: R, | ||
index: number, | ||
arrayLength: number | ||
) => U | PromiseLike<U> | ||
iterator: (item: R, index: number, arrayLength: number) => U | PromiseLike<U> | ||
): Navybird<U[]>; | ||
@@ -388,2 +495,22 @@ | ||
/** | ||
* Returns a promise that is resolved by a node style callback function. | ||
*/ | ||
static fromNode( | ||
resolver: (callback: (err: any, result?: any) => void) => void, | ||
options?: Navybird.FromNodeOptions | ||
): Navybird<any>; | ||
static fromNode<T>( | ||
resolver: (callback: (err: any, result?: T) => void) => void, | ||
options?: Navybird.FromNodeOptions | ||
): Navybird<T>; | ||
static fromCallback( | ||
resolver: (callback: (err: any, result?: any) => void) => void, | ||
options?: Navybird.FromNodeOptions | ||
): Navybird<any>; | ||
static fromCallback<T>( | ||
resolver: (callback: (err: any, result?: T) => void) => void, | ||
options?: Navybird.FromNodeOptions | ||
): Navybird<T>; | ||
/** | ||
* Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled when all the items in the array are fulfilled. | ||
@@ -421,5 +548,3 @@ * The promise's fulfillment value is an array with fulfillment values at respective positions to the original array. | ||
static all<R>( | ||
values: | ||
| PromiseLike<Iterable<PromiseLike<R> | R>> | ||
| Iterable<PromiseLike<R> | R> | ||
values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R> | ||
): Navybird<R[]>; | ||
@@ -465,9 +590,3 @@ | ||
arg5: A5 | PromiseLike<A5>, | ||
handler: ( | ||
arg1: A1, | ||
arg2: A2, | ||
arg3: A3, | ||
arg4: A4, | ||
arg5: A5 | ||
) => R | PromiseLike<R> | ||
handler: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => R | PromiseLike<R> | ||
): Navybird<R>; | ||
@@ -488,5 +607,3 @@ | ||
static map<R, U>( | ||
values: | ||
| PromiseLike<Iterable<PromiseLike<R> | R>> | ||
| Iterable<PromiseLike<R> | R>, | ||
values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>, | ||
mapper: (item: R, index: number, arrayLength: number) => U | PromiseLike<U>, | ||
@@ -506,5 +623,3 @@ options?: Navybird.ConcurrencyOption | ||
static reduce<R, U>( | ||
values: | ||
| PromiseLike<Iterable<PromiseLike<R> | R>> | ||
| Iterable<PromiseLike<R> | R>, | ||
values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>, | ||
reducer: ( | ||
@@ -527,10 +642,4 @@ total: U, | ||
static each<R, U>( | ||
values: | ||
| PromiseLike<Iterable<PromiseLike<R> | R>> | ||
| Iterable<PromiseLike<R> | R>, | ||
iterator: ( | ||
item: R, | ||
index: number, | ||
arrayLength: number | ||
) => U | PromiseLike<U> | ||
values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>, | ||
iterator: (item: R, index: number, arrayLength: number) => U | PromiseLike<U> | ||
): Navybird<R[]>; | ||
@@ -546,10 +655,4 @@ | ||
static eachSeries<R, U>( | ||
values: | ||
| PromiseLike<Iterable<PromiseLike<R> | R>> | ||
| Iterable<PromiseLike<R> | R>, | ||
iterator: ( | ||
item: R, | ||
index: number, | ||
arrayLength: number | ||
) => U | PromiseLike<U> | ||
values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>, | ||
iterator: (item: R, index: number, arrayLength: number) => U | PromiseLike<U> | ||
): Navybird<R[]>; | ||
@@ -567,10 +670,4 @@ | ||
static mapSeries<R, U>( | ||
values: | ||
| PromiseLike<Iterable<PromiseLike<R> | R>> | ||
| Iterable<PromiseLike<R> | R>, | ||
iterator: ( | ||
item: R, | ||
index: number, | ||
arrayLength: number | ||
) => U | PromiseLike<U> | ||
values: PromiseLike<Iterable<PromiseLike<R> | R>> | Iterable<PromiseLike<R> | R>, | ||
iterator: (item: R, index: number, arrayLength: number) => U | PromiseLike<U> | ||
): Navybird<U[]>; | ||
@@ -615,8 +712,28 @@ } | ||
} | ||
interface FromNodeOptions { | ||
multiArgs?: boolean; | ||
} | ||
interface SpreadOption { | ||
spread: boolean; | ||
} | ||
/** | ||
* Represents an error is an explicit promise rejection as opposed to a thrown error. | ||
* For example, if an error is errbacked by a callback API promisified through undefined or undefined | ||
* and is not a typed error, it will be converted to a `OperationalError` which has the original error in | ||
* the `.cause` property. | ||
* | ||
* `OperationalError`s are caught in `.error` handlers. | ||
*/ | ||
class OperationalError extends Error {} | ||
/** | ||
* Signals that an operation has timed out. Used as a custom cancellation reason in `.timeout`. | ||
*/ | ||
class TimeoutError extends Error {} | ||
/** @deprecated Use PromiseLike<T> directly. */ | ||
type Thenable<T> = PromiseLike<T>; | ||
type ResolvableProps<T> = object & | ||
{ [K in keyof T]: PromiseLike<T[K]> | T[K] }; | ||
type ResolvableProps<T> = object & { [K in keyof T]: PromiseLike<T[K]> | T[K] }; | ||
@@ -623,0 +740,0 @@ interface Resolver<R> { |
273
index.js
"use strict"; | ||
const constants = require("./constants"); | ||
const utils = require("./utils"); | ||
const errors = require("./errors"); | ||
const implementations = { | ||
catch: require("./src/catch"), | ||
delay: require("delay"), | ||
timeout: require("./src/timeout"), | ||
}; | ||
const delay = require("delay"); | ||
const pCatchIf = require("p-catch-if"); | ||
const catchReturnHandleFactory = function(value) { | ||
return function catchReturnValue() { | ||
return value; | ||
}; | ||
}; | ||
const catchThrowHandleFactory = function(reason) { | ||
return function catchThrowReason() { | ||
throw reason; | ||
}; | ||
}; | ||
class Navybird extends Promise { | ||
caught(...args) { | ||
return Promise.prototype.catch.call(this, catchFn(args)); | ||
return Promise.prototype.catch.call(this, implementations.catch(args)); | ||
} | ||
error(fn) { | ||
return this.caught(utils.originatesFromRejection, fn); | ||
} | ||
tap(fn) { | ||
@@ -28,3 +49,3 @@ const promiseConstructor = this.constructor; | ||
.resolve(err) | ||
.then(catchFn(args)) | ||
.then(implementations.catch(args)) | ||
.then(function tapCatchValue() { | ||
@@ -38,3 +59,3 @@ return promiseConstructor.reject(err); | ||
return this.tap(function delayValue() { | ||
return delay(ms); | ||
return implementations.delay(ms); | ||
}); | ||
@@ -49,5 +70,19 @@ } | ||
thenThrow(reason) { | ||
return this.then(function thenThrowReason() { | ||
throw reason; | ||
}); | ||
} | ||
catchReturn(...args) { | ||
return this.catch(implementations.catch(args, catchReturnHandleFactory)); | ||
} | ||
catchThrow(...args) { | ||
return this.catch(implementations.catch(args, catchThrowHandleFactory)); | ||
} | ||
spread(fn) { | ||
if (typeof fn !== "function") { | ||
return apiRejection(FUNCTION_ERROR + classString(fn)); | ||
return utils.apiRejection(constants.FUNCTION_ERROR + utils.classString(fn)); | ||
} | ||
@@ -128,3 +163,3 @@ return this.then(function spreadValue(val) { | ||
reflect() { | ||
const inspection = new PromiseInspection(this); | ||
const inspection = new this.constructor.PromiseInspection(this); | ||
const val = function reflectValue() { | ||
@@ -135,108 +170,66 @@ return inspection; | ||
} | ||
} | ||
module.exports = Navybird; | ||
nodeify(cb, options) { | ||
if (typeof cb !== "function") return this; | ||
const spread = options !== undefined && Object(options).spread; | ||
const successAdapter = spread | ||
? function nodeifySpreadAdapter(res) { | ||
utils.nextTick(function nodeifySpreadAdapterNextTick() { | ||
if (Array.isArray(res)) { | ||
cb.apply(null, [null].concat(res)); | ||
} | ||
return cb(null, res); | ||
}); | ||
} | ||
: function nodeifyNormalAdapter(res) { | ||
utils.nextTick(function nodeifyNormalAdapterNextTick() { | ||
return cb(null, res); | ||
}); | ||
}; | ||
const FUNCTION_ERROR = "expecting a function but got "; | ||
const errorAdapter = function nodeifyErrorAdapter(err) { | ||
if (!err) { | ||
var newErr = new Error(err + ""); | ||
newErr.cause = err; | ||
err = newErr; | ||
} | ||
const INSPECTION_VALUE_ERROR = | ||
"cannot get fulfillment value of a non-fulfilled promise\n\n\ | ||
See http://goo.gl/MqrFmX\n"; | ||
utils.nextTick(function nodeifyErrorAdapterNextTick() { | ||
cb(err); | ||
}); | ||
}; | ||
const INSPECTION_REASON_ERROR = | ||
"cannot get rejection reason of a non-rejected promise\n\n\ | ||
See http://goo.gl/MqrFmX\n"; | ||
return this.then(successAdapter, errorAdapter); | ||
} | ||
const apiRejection = function(msg) { | ||
return Navybird.reject(new Navybird.TypeError(msg)); | ||
}; | ||
timeout(ms, reason) { | ||
return implementations.timeout(this, ms, reason); | ||
} | ||
} | ||
const classString = function(obj) { | ||
return {}.toString.call(obj); | ||
}; | ||
module.exports = Navybird; | ||
utils.setNavybird(Navybird); | ||
const resolveWrapper = function(fn) { | ||
return function() { | ||
return Navybird.resolve(fn.apply(this, arguments)); | ||
}; | ||
}; | ||
Object.assign(Navybird, errors.errors); | ||
const catchFn = function(args) { | ||
if (args.length > 2) { | ||
return pCatchIf(args.slice(0, args.length - 1), args[args.length - 1]); | ||
} else if (args.length == 2) { | ||
return pCatchIf(args[0], args[1]); | ||
} | ||
return args[0]; | ||
}; | ||
Navybird.TypeError = TypeError; | ||
Navybird.prototype["catch"] = Navybird.prototype.caught; | ||
Navybird.prototype["return"] = Navybird.prototype.thenReturn; | ||
Navybird.prototype.lastly = Navybird.prototype.finally; | ||
Navybird.prototype["throw"] = Navybird.prototype.thenThrow; | ||
Navybird.prototype["lastly"] = Navybird.prototype.finally; | ||
Navybird.prototype["asCallback"] = Navybird.prototype.nodeify; | ||
Navybird.delay = resolveWrapper(delay); | ||
Navybird.delay = utils.resolveWrapper(implementations.delay); | ||
Navybird.isPromise = require("p-is-promise"); | ||
Navybird.promisify = require("util").promisify; | ||
Navybird.map = require("./src/map")( | ||
Navybird, | ||
apiRejection, | ||
FUNCTION_ERROR, | ||
classString | ||
); | ||
Navybird.map = require("./src/map")(Navybird); | ||
Navybird.reduce = require("./src/reduce")(Navybird); | ||
Navybird.defer = require("./src/defer")(Navybird); | ||
Navybird.eachSeries = Navybird.each = require("./src/eachSeries")(Navybird); | ||
Navybird.mapSeries = require("./src/mapSeries")(Navybird); | ||
Navybird.fromCallback = Navybird.fromNode = require("./src/fromCallback")(Navybird); | ||
Navybird.join = require("./src/join")(Navybird); | ||
Navybird.PromiseInspection = require("./src/inspection")(Navybird); | ||
Navybird.inspectable = require("./src/inspectable")(Navybird); | ||
Navybird.eachSeries = function(iterable, iterator) { | ||
const ret = []; | ||
return Navybird.reduce( | ||
iterable, | ||
function eachSeriesReducer(a, b, i, length) { | ||
return Navybird.resolve(iterator(b, i, length)).then( | ||
function eachSeriesIteratorCallback(val) { | ||
ret.push(b); | ||
} | ||
); | ||
}, | ||
{} | ||
).thenReturn(ret); | ||
}; | ||
Navybird.each = Navybird.eachSeries; | ||
Navybird.mapSeries = function(iterable, mapper) { | ||
const ret = []; | ||
return Navybird.reduce( | ||
iterable, | ||
function mapSeriesReducer(a, b, i, length) { | ||
return Navybird.resolve(mapper(b, i, length)).then( | ||
function mapSeriesMapperCallback(val) { | ||
ret.push(val); | ||
} | ||
); | ||
}, | ||
{} | ||
).thenReturn(ret); | ||
}; | ||
class NavybirdDefer { | ||
constructor() { | ||
const self = this; | ||
this.promise = new Navybird(function deferPromiseCapturer(resolve, reject) { | ||
self.resolve = resolve; | ||
self.reject = reject; | ||
}); | ||
} | ||
get fulfill() { | ||
return this.resolve; | ||
} | ||
} | ||
Navybird.defer = function() { | ||
return new NavybirdDefer(); | ||
}; | ||
Navybird.cast = Navybird.resolve.bind(Navybird); | ||
@@ -247,82 +240,4 @@ Navybird.fulfilled = Navybird.resolve.bind(Navybird); | ||
Navybird.join = function(...args) { | ||
const last = args.length - 1; | ||
if (last > 0 && typeof args[last] === "function") { | ||
const fn = args.pop(); | ||
return Navybird.all(args).spread(fn); | ||
} | ||
return Navybird.all(args); | ||
}; | ||
class PromiseInspection { | ||
constructor(target) { | ||
const self = this; | ||
this._isPending = true; | ||
this._isRejected = false; | ||
this._isFulfilled = false; | ||
this._value = undefined; | ||
this._reason = undefined; | ||
this._target = target.then( | ||
function inspectableResolvedHandle(v) { | ||
self._isFulfilled = true; | ||
self._isPending = false; | ||
self._value = v; | ||
return v; | ||
}, | ||
function inspectableRejectedHandle(e) { | ||
self._isRejected = true; | ||
self._isPending = false; | ||
self._reason = e; | ||
throw e; | ||
} | ||
); | ||
} | ||
target() { | ||
return this._target; | ||
} | ||
isFulfilled() { | ||
return this._isFulfilled; | ||
} | ||
isRejected() { | ||
return this._isRejected; | ||
} | ||
isPending() { | ||
return this._isPending; | ||
} | ||
value() { | ||
if (this.isFulfilled()) return this._value; | ||
throw new Navybird.TypeError(INSPECTION_VALUE_ERROR); | ||
} | ||
reason() { | ||
if (this.isRejected()) return this._reason; | ||
throw new Navybird.TypeError(INSPECTION_REASON_ERROR); | ||
} | ||
} | ||
Navybird.PromiseInspection = PromiseInspection; | ||
const NavybirdInspection = Symbol.for("NavybirdInspection"); | ||
Navybird.inspectable = function(promise) { | ||
if (promise[NavybirdInspection]) return promise; | ||
const inspection = new PromiseInspection(promise); | ||
const result = inspection.target(); | ||
result[NavybirdInspection] = inspection; | ||
result.isFulfilled = inspection.isFulfilled.bind(inspection); | ||
result.isPending = inspection.isPending.bind(inspection); | ||
result.isRejected = inspection.isRejected.bind(inspection); | ||
result.value = inspection.value.bind(inspection); | ||
result.reason = inspection.reason.bind(inspection); | ||
return result; | ||
}; | ||
Object.keys(Navybird).forEach(function(key) { | ||
utils.notEnumerableProp(Navybird, key, Navybird[key]); | ||
}); |
{ | ||
"name": "navybird", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"main": "index.js", | ||
@@ -9,2 +9,3 @@ "license": "MIT", | ||
"devDependencies": { | ||
"clarify": "^2.1.0", | ||
"coveralls": "^3.0.0", | ||
@@ -15,3 +16,5 @@ "husky": "^0.14.3", | ||
"nyc": "^11.4.1", | ||
"prettier": "^1.11.1" | ||
"prettier": "^1.11.1", | ||
"sinon": "^4.4.2", | ||
"trace": "^3.1.0" | ||
}, | ||
@@ -21,7 +24,10 @@ "scripts": { | ||
"test": "node_modules/.bin/nyc node_modules/.bin/mocha", | ||
"test:only": "node_modules/.bin/mocha", | ||
"test:debug": "node_modules/.bin/nyc node_modules/.bin/mocha --stack_trace_limit=100 -r trace -r clarify", | ||
"test:debug:only": "node_modules/.bin/mocha --stack_trace_limit=100 -r trace -r clarify", | ||
"coverage": "node_modules/.bin/nyc report --reporter=text-lcov", | ||
"coveralls": "node_modules/.bin/nyc report --reporter=text-lcov | node_modules/.bin/coveralls", | ||
"prettier": "node_modules/prettier --write index.js", | ||
"prettier-js": "prettier --trailing-comma es5 --arrow-parens always --write", | ||
"prettier-ts": "prettier --parser typescript --trailing-comma es5 --arrow-parens always --write" | ||
"prettier": "npm run prettier-js index.js", | ||
"prettier-js": "node_modules/.bin/prettier --trailing-comma es5 --arrow-parens always --print-width=90 --write", | ||
"prettier-ts": "node_modules/.bin/prettier --parser typescript --trailing-comma es5 --arrow-parens always --print-width=90 --write" | ||
}, | ||
@@ -28,0 +34,0 @@ "lint-staged": { |
@@ -7,8 +7,6 @@ // https://github.com/sindresorhus/p-map/blob/15347cbaa82d517258390d6b1df8ac415701ff5f/index.js | ||
"use strict"; | ||
module.exports = function mapFactory( | ||
Promise, | ||
apiRejection, | ||
FUNCTION_ERROR, | ||
classString | ||
) { | ||
const utils = require("../utils"); | ||
const constants = require("../constants"); | ||
module.exports = function mapFactory(Promise) { | ||
const map = function map(iterable, mapper, opts) { | ||
@@ -32,3 +30,5 @@ return new Promise(function mapPromise(resolve, reject) { | ||
if (typeof mapper !== "function") { | ||
return resolve(apiRejection(FUNCTION_ERROR + classString(fn))); | ||
return resolve( | ||
utils.apiRejection(constants.FUNCTION_ERROR + utils.classString(fn)) | ||
); | ||
} | ||
@@ -35,0 +35,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
268645
38
5005
9
2