🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

prfun

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prfun - npm Package Compare versions

Comparing version
2.1.4
to
2.1.5
.eslintignore

Sorry, the diff of this file is not supported yet

+28
{
"extends": "node-style-guide",
"env": {
"node": true
},
"globals": {},
"rules": {
"space-after-keywords": "off",
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"object-curly-spacing": ["error", "always"],
"keyword-spacing": [2, {"before": true, "after": true}],
"max-statements": "off",
"capitalized-comments": [
"error",
"always",
{
"ignoreConsecutiveComments": true
}
],
"quotes": [
2,
"single",
{
"avoidEscape": true
}
]
}
}
+8
-3
language: node_js
node_js:
# From the nvm docs, "this installs the latest version of node".
- "node"
- "stable"
- "5.0"
- "4.4"
- "4.2"
- "9"
- "8"
- "7"
- "6"
- "5"
- "4"
- "4.0"

@@ -8,0 +13,0 @@ - "0.12"

@@ -0,1 +1,6 @@

# prfun 2.1.5 (2018-01-06)
* Allow functions created by `Promise.async` to accept legacy node-style
callback arguments.
* Switch to `eslint`, update `mocha`, and ensure we test up to node 9.
# prfun 2.1.4 (2016-05-05)

@@ -2,0 +7,0 @@ * Add a cache to ensure that only a single `prfun` `Promise` class is

@@ -79,3 +79,3 @@ // Utility functions for ES6 Promises.

var PrFunPromise;
// jscs:disable maximumLineLength
/* eslint-disable max-len */
var isClass = function isClass(v) {

@@ -86,3 +86,3 @@ // See: http://stackoverflow.com/questions/30758961/how-to-check-if-a-variable-is-an-es6-class-declaration

};
// jscs:enable maximumLineLength
/* eslint-enable max-len */
if (isClass(ParentPromise)) {

@@ -92,3 +92,2 @@ // ES6 classes are currently unoptimized in V8.

try {
/* jshint evil:true */
return eval('(function(ParentPromise){' +

@@ -155,3 +154,3 @@ '"use strict";' +

if (!(Promise.resolve(42) instanceof Promise)) {
throw('Bad implementation');
throw new Error('Bad implementation');
}

@@ -228,3 +227,2 @@ } catch (ex) {

var arrayFilter = Array.prototype.filter;
Promise.filter = function(pArray, callback, thisArg) {

@@ -450,3 +448,3 @@ var P = this || Promise;

return P.resolve(pValue).then(function(value) {
return new P(function(resolve, reject) {
return new P(function(resolve, reject) { // eslint-disable-line
setTimeout(function() { resolve(value); }, ms);

@@ -484,3 +482,3 @@ });

Promise['try'] = function(fn, ctx /* ..args */) {
Promise['try'] = function(fn, ctx /* ..args */) { // eslint-disable-line
var P = this || Promise;

@@ -517,3 +515,2 @@ // It shouldn't be necessary to slice the arguments, but some

predicates = predicates.map(function(v) {
/* jshint eqnull: true */
var isErrorType = (v === Error) ||

@@ -527,3 +524,3 @@ (v != null && v.prototype instanceof Error);

}
return function(e) {
return function(e) { // eslint-disable-line
throw new TypeError('caught filter must inherit from Error ' +

@@ -639,7 +636,7 @@ 'or be a simple predicate function');

switch (l) {
case 0: { nodeFunction.call(self, cb); return; }
case 1: { nodeFunction.call(self, a, cb); return; }
case 2: { nodeFunction.call(self, a, b, cb); return; }
case 3: { nodeFunction.call(self, a, b, c, cb); return; }
default: { throw new Error('unreachable'); }
case 0: { nodeFunction.call(self, cb); return; }
case 1: { nodeFunction.call(self, a, cb); return; }
case 2: { nodeFunction.call(self, a, b, cb); return; }
case 3: { nodeFunction.call(self, a, b, c, cb); return; }
default: { throw new Error('unreachable'); }
}

@@ -787,3 +784,3 @@ });

// Generators.
Promise.async = function(makeGenerator) {
Promise.async = function(makeGenerator, cbArg) {
var P = this || Promise;

@@ -811,3 +808,3 @@ return function() {

};
return new P(function(resolve, reject) {
var resultP = new P(function(resolve, reject) {
var callback, errback;

@@ -831,2 +828,4 @@ var continuer = function(fn, arg) {

});
return (cbArg === undefined) ? resultP :
Promise.prototype.nodify.call(resultP, arguments[cbArg]);
};

@@ -833,0 +832,0 @@ };

{
"name": "prfun",
"version": "2.1.4",
"version": "2.1.5",
"description": "Helper functions for ES6 promises",
"main": "index.js",
"scripts": {
"jscs": "jscs .",
"jscs-fix": "jscs --fix .",
"lint": "jshint . && npm run jscs",
"lint-no-0.8": "node -e 'process.exit(/v0[.][0-8][.]/.test(process.version) ? 0 : 1)' || npm run lint",
"eslint": "eslint .",
"eslint-fix": "eslint --fix .",
"lint": "npm run eslint",
"lint-no-0.x": "node -e 'process.exit(/v0[.][0-9]+[.]/.test(process.version) ? 0 : 1)' || npm run lint",
"mocha": "if node -e 'process.exit(/v0[.]([0-9]|10)[.]/.test(process.version) ? 0 : 1)' ; then mocha ; else mocha --harmony ; fi",
"test": "npm run lint-no-0.8 && npm run mocha"
"test": "npm run lint-no-0.x && npm run mocha"
},

@@ -31,10 +31,10 @@ "repository": {

"devDependencies": {
"core-js": "^2.3.0",
"jscs": "^2.11.0",
"jshint": "^2.9.2",
"mocha": "^2.4.5"
"core-js": "^2.5.3",
"eslint": "^4.14.0",
"eslint-config-node-style-guide": "^3.0.0",
"mocha": "^3.5.0"
},
"optionalDependencies": {
"core-js": "^2.3.0"
"core-js": "^2.5.3"
}
}

@@ -1190,4 +1190,5 @@ # prfun

console.error( err );
} else {
console.log(dataForMe);
}
console.log(dataForMe);
});

@@ -1341,4 +1342,4 @@ ```

#### `Promise.async(GeneratorFunction generatorFunction)` → `Function`
[`Promise.async`]: #promiseasyncgeneratorfunction-generatorfunction--function
#### `Promise.async(GeneratorFunction generatorFunction [, int cbArg])` → `Function`
[`Promise.async`]: #promiseasyncgeneratorfunction-generatorfunction--int-cbArg--function

@@ -1351,2 +1352,5 @@ Takes a function that can use `yield` to await the resolution of

If the optional `cbArg` is present, then `Promise.nodify` is invoked
on the result with the given (optional) argument as a parameter.
```js

@@ -1426,2 +1430,34 @@ // Use Promise.async to create a function that acts as a coroutine

**Caution**
Note the difference between `func1` and `func2` in the following:
```js
var thrower = Promise.method(function(msg) { throw new Error(msg); });
var func1 = Promise.async(function *() {
try {
return thrower("hey");
} catch (e) {
console.log("This line is never reached.");
}
});
var func2 = Promise.async(function *() {
try {
return (yield thrower("ho"));
} catch (e) {
console.log("Exception is caught here!", e);
}
});
```
When `func1` returns a `Promise`, we leave the scope of the try block.
By the time the returned `Promise` rejects with an error, we can no longer
catch it.
If you want to ensure that rejected `Promise`s get a chance to be caught,
be sure to `yield` them (which resolves the `Promise` completely) before
returning, as in `func2`.
**Tip**

@@ -1457,2 +1493,22 @@

**Legacy callbacks**
For compatibility with legacy code which uses callbacks, you can
use the optional `cbArg`, as follows:
```js
var getDataFor = Promise.async(function *(input) {
return dataFromDataBase(input);
}, 1 /* arg #1 is optional callback */);
/* Calling this using node 'callback' syntax */
getDataFor(input, function(err, dataForMe) {
if (err) {
console.error( err );
} else {
console.log(dataForMe);
}
});
```
<hr>

@@ -1463,3 +1519,3 @@

Copyright (c) 2014-2015 C. Scott Ananian
Copyright (c) 2014-2018 C. Scott Ananian

@@ -1466,0 +1522,0 @@ Portions are Copyright (c) 2014 Petka Antonov

@@ -1,2 +0,2 @@

// jscs:disable maximumLineLength
/* eslint-disable max-len */
'use strict';

@@ -11,3 +11,3 @@

var THIS = {name: 'this'};
var THIS = { name: 'this' };

@@ -86,3 +86,3 @@ function CustomError1() {}

.bind(THIS).timeout(10).then(assert.fail)
.caught(Promise.TimeoutError, function(err) {
.caught(Promise.TimeoutError, function(err) { // eslint-disable-line no-unused-vars
assert(this === THIS);

@@ -103,3 +103,3 @@ });

a.b();
}).caught(Error, function(e) {
}).caught(Error, function(e) { // eslint-disable-line no-unused-vars
assert(THIS === this);

@@ -112,3 +112,3 @@ });

}).caught(CustomError2, assert.fail)
.caught(CustomError1, function(e) {
.caught(CustomError1, function(e) { // eslint-disable-line no-unused-vars
assert(THIS === this);

@@ -196,3 +196,3 @@ });

specify('this should refer to the bound object', function() {
return fulfilled({key: 'value'}).bind(THIS).get('key').then(function(val) {
return fulfilled({ key: 'value' }).bind(THIS).get('key').then(function(val) {
assert(val === 'value');

@@ -207,3 +207,3 @@ assert(this === THIS);

specify('this should refer to the bound object', function() {
return fulfilled({key: function() {return 'value';}}).bind(THIS).call('key').then(function(val) {
return fulfilled({ key: function() {return 'value';} }).bind(THIS).call('key').then(function(val) {
assert(val === 'value');

@@ -322,3 +322,3 @@ assert(this === THIS);

specify('when the callback errs', function(done) {
rejected(3).bind(THIS).nodify(function(err, success) {
rejected(3).bind(THIS).nodify(function(err, success) { // eslint-disable-line no-unused-vars
try {

@@ -325,0 +325,0 @@ assert(err === 3);

@@ -1,2 +0,3 @@

// jscs:disable maximumLineLength
/* eslint-disable max-len */
/* eslint no-unused-vars: ["error", { "args": "none" }] */
'use strict';

@@ -7,4 +8,2 @@

var fulfilled = Promise.resolve.bind(Promise);
var rejected = Promise.reject.bind(Promise);
var pending = Promise.defer.bind(Promise);

@@ -19,7 +18,2 @@

function BadError(msg) {
this.message = msg;
return this;
}
function predicatesUndefined(e) {

@@ -345,3 +339,2 @@ return e === void 0;

var c = pending();
var b = new CustomError();

@@ -348,0 +341,0 @@ setTimeout(function() { a.resolve(3); }, 10);

@@ -0,1 +1,2 @@

/* eslint no-unused-vars: ["error", { "args": "none" }] */
'use strict';

@@ -6,6 +7,2 @@

var fulfilled = Promise.resolve.bind(Promise);
var rejected = Promise.reject.bind(Promise);
var pending = Promise.defer.bind(Promise);
describe('Promise filter', function() {

@@ -12,0 +9,0 @@

@@ -1,3 +0,2 @@

// jscs:disable maximumLineLength
/* jshint evil:true */
/* eslint-disable max-len, no-unused-vars */
'use strict';

@@ -172,2 +171,72 @@

});
describe('caution from README', function() {
var thrower = Promise.method(function(msg) { throw new Error(msg); });
specify('return promise-which-rejects does not catch', function() {
var func1 = Promise.async(eval('(function *() {' +
'try {' +
' return thrower("hey");' +
'} catch (e) {' +
' assert(false); /* this line is never reached */' +
'}' +
'})'));
return func1().then(assert.fail, function(e) {
assert.equal(e.message, 'hey');
});
});
specify('return yield-promise-which-rejects does catch', function() {
var func1 = Promise.async(eval('(function *() {' +
'try {' +
' return (yield thrower("ho"));' +
'} catch (e) {' +
' assert.equal(e.message, "ho");' +
' return "caught";' +
'}' +
'})'));
return func1().then(function(v) {
assert.equal(v, 'caught');
});
});
});
describe('legacy callbacks', function() {
var getDataFor = Promise.async(eval(
'(function *(input) {' +
'yield Promise.resolve();' +
'if (!input) throw new Error("no input");' +
'return input;' +
'})'), 1 /* Arg #1 is optional callback */);
specify('should return Promise', function() {
var p = getDataFor(5);
assert(p instanceof Promise);
return p.then(function(v) {
assert.equal(v, 5);
});
});
specify('should accept callback for value', function() {
return new Promise(function(resolve, reject) {
getDataFor(6, function(err, v) {
if (err) {
return reject(err);
}
resolve(v);
});
}).then(function(vv) { assert.equal(vv, 6); });
});
specify('should accept callback for exception', function() {
return new Promise(function(resolve, reject) {
getDataFor(0, function(err, v) {
if (err) {
return resolve(err); // An error is the expected result!
}
reject(new Error(v));
});
}).then(function(vv) { assert(vv.message, 'no input'); });
});
});
});

@@ -1,2 +0,2 @@

// jscs:disable maximumLineLength
/* eslint-disable max-len */
'use strict';

@@ -3,0 +3,0 @@

@@ -7,3 +7,2 @@ 'use strict';

var fulfilled = Promise.resolve.bind(Promise);
var rejected = Promise.reject.bind(Promise);
var pending = Promise.defer.bind(Promise);

@@ -46,4 +45,3 @@

assert.fail();
}
catch (e) {
} catch (e) {
assert(e instanceof TypeError);

@@ -103,3 +101,3 @@ }

return {
then: function(f, v) {
then: function(f, v) { // eslint-disable-line no-unused-vars
f(3);

@@ -106,0 +104,0 @@ },

@@ -1,2 +0,2 @@

// jscs:disable maximumLineLength
/* eslint-disable max-len */
'use strict';

@@ -9,2 +9,5 @@

var sentinel = {};
var sentinelError = new RejectionError();
var erroneousNode = function(a, b, c, cb) {

@@ -16,5 +19,2 @@ setTimeout(function() {

var sentinel = {};
var sentinelError = new RejectionError();
var successNode = function(a, b, c, cb) {

@@ -45,3 +45,3 @@ setTimeout(function() {

var errToThrow;
var thrower = Promise.promisify(function(a, b, c, cb) {
var thrower = Promise.promisify(function(a, b, c, cb) { // eslint-disable-line no-unused-vars
errToThrow = new RejectionError();

@@ -52,3 +52,3 @@ throw errToThrow;

var tprimitive = 'Where is your stack now?';
var throwsStrings = Promise.promisify(function(cb) {
var throwsStrings = Promise.promisify(function(cb) { // eslint-disable-line no-unused-vars
throw tprimitive;

@@ -239,3 +239,3 @@ });

assert(e instanceof Error);
assert(e.message == tprimitive);
assert(e.message === tprimitive);
});

@@ -257,3 +257,3 @@ });

assert(e instanceof Error);
assert(e.message == tprimitive);
assert(e.message === tprimitive);
});

@@ -266,3 +266,3 @@ });

assert(e instanceof Error);
assert(e.message == tprimitive);
assert(e.message === tprimitive);
});

@@ -275,3 +275,3 @@ });

assert(e instanceof Error);
assert(e.message == tprimitive);
assert(e.message === tprimitive);
});

@@ -284,3 +284,3 @@ });

assert(e instanceof Error);
assert(e.message == tprimitive);
assert(e.message === tprimitive);
});

@@ -326,12 +326,12 @@ });

var stringthrow = function(cb) {
throw('Primitive as error');
var stringthrow = function(cb) { // eslint-disable-line no-unused-vars
throw ('Primitive as error');
};
var errthrow = function(cb) {
throw(new Error('error as error'));
var errthrow = function(cb) { // eslint-disable-line no-unused-vars
throw (new Error('error as error'));
};
var typethrow = function(cb) {
throw(new CustomError());
var typethrow = function(cb) { // eslint-disable-line no-unused-vars
throw (new CustomError());
};

@@ -361,3 +361,3 @@

specify('should not wrap typeback', function(done) {
typeback().caught(CustomError, function(e) {
typeback().caught(CustomError, function(e) { // eslint-disable-line no-unused-vars
done();

@@ -383,3 +383,3 @@ });

typethrow().error(assert.fail)
.caught(CustomError, function(e) {
.caught(CustomError, function(e) { // eslint-disable-line no-unused-vars
done();

@@ -386,0 +386,0 @@ });

@@ -126,5 +126,5 @@ 'use strict';

specify('should accept thenables in properties', function() {
var t1 = {then: function(cb) {cb(1);}};
var t2 = {then: function(cb) {cb(2);}};
var t3 = {then: function(cb) {cb(3);}};
var t1 = { then: function(cb) {cb(1);} };
var t2 = { then: function(cb) {cb(2);} };
var t3 = { then: function(cb) {cb(3);} };
var o = {

@@ -131,0 +131,0 @@ one: t1,

@@ -1,2 +0,2 @@

// jscs:disable maximumLineLength
/* eslint-disable max-len */
'use strict';

@@ -3,0 +3,0 @@

@@ -1,2 +0,2 @@

// jscs:disable maximumLineLength
/* eslint-disable max-len */
'use strict';

@@ -98,7 +98,2 @@

function addHandlersBack() {
for (var i = 0, len = h.length; i < len; ++i) {
process.addListener('uncaughtException', h[i]);
}
}
var e = new Error();

@@ -105,0 +100,0 @@ function thrower() {

@@ -1,2 +0,2 @@

// jscs:disable maximumLineLength
/* eslint-disable max-len */
'use strict';

@@ -3,0 +3,0 @@

@@ -6,5 +6,2 @@ 'use strict';

var fulfilled = Promise.resolve.bind(Promise);
var rejected = Promise.reject.bind(Promise);
function promised(val) {

@@ -11,0 +8,0 @@ return Promise.delay(val, 4);

@@ -1,2 +0,2 @@

// jscs:disable maximumLineLength
/* eslint-disable max-len */
'use strict';

@@ -7,6 +7,2 @@

var fulfilled = Promise.resolve.bind(Promise);
var rejected = Promise.reject.bind(Promise);
var pending = Promise.defer.bind(Promise);
describe('tap', function() {

@@ -42,3 +38,3 @@ specify('passes through value', function(done) {

called = true;
}).caught(function(value) {
}).caught(function(value) { // eslint-disable-line no-unused-vars
assert(!called);

@@ -45,0 +41,0 @@ done();

@@ -1,2 +0,2 @@

// jscs:disable maximumLineLength
/* eslint-disable max-len */
'use strict';

@@ -3,0 +3,0 @@

@@ -7,3 +7,2 @@ 'use strict';

var fulfilled = Promise.resolve.bind(Promise);
var rejected = Promise.reject.bind(Promise);
var pending = Promise.defer.bind(Promise);

@@ -113,3 +112,3 @@

return {
then: function(f, v) {
then: function(f, v) { // eslint-disable-line no-unused-vars
f(3);

@@ -116,0 +115,0 @@ },

@@ -1,2 +0,2 @@

// jscs:disable maximumLineLength
/* eslint-disable max-len */
'use strict';

@@ -3,0 +3,0 @@

@@ -1,2 +0,2 @@

// jscs:disable maximumLineLength
/* eslint-disable max-len */
'use strict';

@@ -93,3 +93,3 @@ /*

/* jshint elision: true */
var input = [, 1, , 1, 1 ];
var input = [, 1, , 1, 1];
return when.all(input).then(

@@ -104,3 +104,3 @@ function(results) {

/* jshint elision: true */
var input = [, 1, , 1, 1 ];
var input = [, 1, , 1, 1];
return resolved(input).all().then(

@@ -158,3 +158,3 @@ function(results) {

var caught = false;
return when.all(resolved(1)).caught(TypeError, function(e) {
return when.all(resolved(1)).caught(TypeError, function(e) { // eslint-disable-line no-unused-vars
caught = true;

@@ -161,0 +161,0 @@ }).then(function() {

@@ -1,2 +0,2 @@

// jscs:disable maximumLineLength
/* eslint-disable max-len */
'use strict';

@@ -34,18 +34,5 @@ /*

var when = Promise;
var resolved = Promise.resolve.bind(Promise);
var rejected = Promise.reject.bind(Promise);
var sentinel = {};
var other = {};
var refute = {
defined: function(val) {
assert(typeof val === 'undefined');
},
equals: function(a, b) {
assert.notDeepEqual(a, b);
},
};
function fakeResolved(val) {

@@ -52,0 +39,0 @@ return {

@@ -1,2 +0,2 @@

// jscs:disable maximumLineLength
/* eslint-disable max-len */
'use strict';

@@ -3,0 +3,0 @@ /*

@@ -1,2 +0,2 @@

// jscs:disable maximumLineLength
/* eslint-disable max-len */
'use strict';

@@ -132,3 +132,3 @@ /*

var caught = false;
return when.reduce([], plus).caught(TypeError, function(e) {
return when.reduce([], plus).caught(TypeError, function(e) { // eslint-disable-line no-unused-vars
caught = true;

@@ -275,3 +275,3 @@ }).then(function() {

var caught = false;
return when.reduceRight([], plus).caught(TypeError, function(e) {
return when.reduceRight([], plus).caught(TypeError, function(e) { // eslint-disable-line no-unused-vars
caught = true;

@@ -278,0 +278,0 @@ }).then(function() {

@@ -34,3 +34,3 @@ 'use strict';

var resolved = Promise.resolve.bind(Promise);
var rejected = Promise.reject.bind(Promise);
var rejected = Promise.reject.bind(Promise); // eslint-disable-line

@@ -37,0 +37,0 @@ describe('when.spread-test', function() {

{
"preset": "node-style-guide",
// allow some slop to account for legacy code
"validateQuoteMarks": { "mark": "'", "escape": true },
"requireCapitalizedComments": { "allExcept": ["jshint"] },
"excludeFiles": [
"node_modules/**",
"clean/**"
]
}

Sorry, the diff of this file is not supported yet

{
"predef": [ "describe", "specify", "it" ],
"node": true
}

Sorry, the diff of this file is not supported yet