Comparing version 0.2.10 to 0.3.0
@@ -32,2 +32,5 @@ 'use strict'; | ||
* | ||
* Alternatively, an object of type $[PromiseAdapter] can be passed in, which provides | ||
* compatibility with any promise library outside of the standard. | ||
* | ||
* Passing in a promise library that cannot be recognized will throw | ||
@@ -39,3 +42,3 @@ * `Invalid promise library specified.` | ||
* | ||
* @see $[batch], $[page], $[sequence], $[stream] | ||
* @see $[PromiseAdapter], $[batch], $[page], $[sequence], $[stream] | ||
*/ | ||
@@ -54,12 +57,8 @@ function main(promiseLib) { | ||
function addMethod(obj, method, path) { | ||
obj[method] = require('./ext/' + (path || '') + method)(config); | ||
} | ||
spex.batch = require('./ext/batch')(config); | ||
spex.page = require('./ext/page')(config); | ||
spex.sequence = require('./ext/sequence')(config); | ||
addMethod(spex, 'batch'); | ||
addMethod(spex, 'page'); | ||
addMethod(spex, 'sequence'); | ||
spex.stream = {}; | ||
addMethod(spex.stream, 'read', 'stream/'); | ||
spex.stream.read = require('./ext/stream/read')(config); | ||
@@ -78,15 +77,20 @@ config.utils.extend(spex, '$p', promise); | ||
if (lib) { | ||
var promise; | ||
if (lib instanceof main.PromiseAdapter) { | ||
promise = function (func) { | ||
return lib.create(func); | ||
}; | ||
promise.resolve = lib.resolve; | ||
promise.reject = lib.reject; | ||
return promise; | ||
} | ||
var t = typeof lib; | ||
if (t === 'function' || t === 'object') { | ||
var root = lib.Promise instanceof Function ? lib.Promise : lib, | ||
methods = ['resolve', 'reject'], // key promise methods; | ||
success = true; | ||
var promise = function (func) { | ||
var root = lib.Promise instanceof Function ? lib.Promise : lib; | ||
promise = function (func) { | ||
return new root(func); | ||
}; | ||
methods.forEach(function (m) { | ||
promise[m] = root[m]; | ||
success = success && root[m] instanceof Function; | ||
}); | ||
if (success) { | ||
promise.resolve = root.resolve; | ||
promise.reject = root.reject; | ||
if (promise.resolve instanceof Function && promise.reject instanceof Function) { | ||
return promise; | ||
@@ -99,2 +103,5 @@ } | ||
main.PromiseAdapter = require('./adapter'); | ||
Object.freeze(main); | ||
module.exports = main; |
{ | ||
"name": "spex", | ||
"version": "0.2.10", | ||
"version": "0.3.0", | ||
"description": "Specialized Promise Extensions", | ||
@@ -9,3 +9,4 @@ "main": "lib/index.js", | ||
"coverage": "istanbul cover ./node_modules/jasmine-node/bin/jasmine-node test", | ||
"travis": "istanbul cover ./node_modules/jasmine-node/bin/jasmine-node test --captureExceptions && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" | ||
"travis": "istanbul cover ./node_modules/jasmine-node/bin/jasmine-node test --captureExceptions && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage", | ||
"browserify": "browserify lib/index.js -s spexLib -o spex.js" | ||
}, | ||
@@ -48,4 +49,5 @@ "files": [ | ||
"istanbul": "0.4", | ||
"jasmine-node": "1.x" | ||
"jasmine-node": "1.x", | ||
"browserify": "11.x" | ||
} | ||
} |
@@ -41,2 +41,4 @@ # Specialized Promise Extensions | ||
See also: [client-side usage](docs/client.md). | ||
### API | ||
@@ -43,0 +45,0 @@ |
@@ -42,2 +42,16 @@ 'use strict'; | ||
}); | ||
describe("passing invalid adapter", function () { | ||
it("must throw an error", function () { | ||
expect(function () { | ||
new lib.main.PromiseAdapter(); | ||
}).toThrow('Adapter requires a function to create a promise.'); | ||
expect(function () { | ||
new lib.main.PromiseAdapter(dummy); | ||
}).toThrow('Adapter requires a function to resolve a promise.'); | ||
expect(function () { | ||
new lib.main.PromiseAdapter(dummy, dummy); | ||
}).toThrow('Adapter requires a function to reject a promise.'); | ||
}); | ||
}); | ||
}); | ||
@@ -53,2 +67,3 @@ | ||
it("must be complete", function () { | ||
expect(lib.main.PromiseAdapter instanceof Function).toBe(true); | ||
expect(inst && typeof inst === 'object').toBe(true); | ||
@@ -63,2 +78,19 @@ expect(inst.batch instanceof Function).toBe(true); | ||
}); | ||
describe("initializing with adapter", function () { | ||
var adapter, inst, p; | ||
beforeEach(function () { | ||
adapter = new lib.main.PromiseAdapter(function () { | ||
return 123; | ||
}, dummy, dummy); | ||
inst = lib.main(adapter); | ||
p = inst.$p(dummy); | ||
}); | ||
it("must not throw any error", function () { | ||
expect(adapter).toBeTruthy(); | ||
expect(inst).toBeTruthy(); | ||
expect(p).toBe(123); | ||
}); | ||
}); | ||
}); |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
67406
15
1741
64
1
7