Skip to content

Commit

Permalink
initial check-in.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Jul 3, 2017
1 parent 3492048 commit 4390b75
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 40 deletions.
27 changes: 27 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,27 @@
{
"env": {
"es6": false,
"node": true,
"jasmine": true
},
"extends": "eslint:recommended",
"parserOptions": {
},
"rules": {
"no-else-return": "error",
"no-multi-spaces": "error",
"no-whitespace-before-property": "error",
"camelcase": "error",
"new-cap": "error",
"no-console": "error",
"comma-dangle": "error",
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
}
14 changes: 7 additions & 7 deletions lib/errors/page.js
Expand Up @@ -7,12 +7,12 @@ var $npm = {
};

var errorReasons = {
0: "Page with index %d rejected.",
1: "Source %s returned a rejection at index %d.",
2: "Source %s threw an error at index %d.",
3: "Destination %s returned a rejection at index %d.",
4: "Destination %s threw an error at index %d.",
5: "Source %s returned a non-array value at index %d."
0: 'Page with index %d rejected.',
1: 'Source %s returned a rejection at index %d.',
2: 'Source %s threw an error at index %d.',
3: 'Destination %s returned a rejection at index %d.',
4: 'Destination %s threw an error at index %d.',
5: 'Source %s returned a non-array value at index %d.'
};

/**
Expand Down Expand Up @@ -82,7 +82,7 @@ function PageError(e, code, cbName, duration) {
}

if (code) {
cbName = cbName ? ("'" + cbName + "'") : '<anonymous>';
cbName = cbName ? ('\'' + cbName + '\'') : '<anonymous>';
this.reason = $npm.u.format(errorReasons[code], cbName, e.index);
} else {
this.reason = $npm.u.format(errorReasons[code], e.index);
Expand Down
10 changes: 5 additions & 5 deletions lib/errors/sequence.js
Expand Up @@ -7,10 +7,10 @@ var $npm = {
};

var errorReasons = {
0: "Source %s returned a rejection at index %d.",
1: "Source %s threw an error at index %d.",
2: "Destination %s returned a rejection at index %d.",
3: "Destination %s threw an error at index %d."
0: 'Source %s returned a rejection at index %d.',
1: 'Source %s threw an error at index %d.',
2: 'Destination %s returned a rejection at index %d.',
3: 'Destination %s threw an error at index %d.'
};

/**
Expand Down Expand Up @@ -75,7 +75,7 @@ function SequenceError(e, code, cbName, duration) {
this.dest = e.dest;
}

cbName = cbName ? ("'" + cbName + "'") : '<anonymous>';
cbName = cbName ? ('\'' + cbName + '\'') : '<anonymous>';
this.reason = $npm.u.format(errorReasons[code], cbName, e.index);

Error.captureStackTrace(this, SequenceError);
Expand Down
8 changes: 4 additions & 4 deletions lib/ext/batch.js
Expand Up @@ -58,7 +58,7 @@ function batch(values, cb, config) {
var $p = config.promise, $utils = config.utils;

if (!Array.isArray(values)) {
return $p.reject(new TypeError("Method 'batch' requires an array of values."));
return $p.reject(new TypeError('Method \'batch\' requires an array of values.'));
}

if (!values.length) {
Expand All @@ -82,6 +82,7 @@ function batch(values, cb, config) {
step(i, false, reason);
});
});

function step(idx, pass, data) {
if (cb) {
var cbResult, cbNow = Date.now(),
Expand Down Expand Up @@ -113,7 +114,7 @@ function batch(values, cb, config) {
errors.push(idx);
}
r.result = e;
r.origin = {success: pass, result: data}
r.origin = {success: pass, result: data};
}

function check() {
Expand Down Expand Up @@ -145,8 +146,7 @@ module.exports = function (config) {
return function (values, cb) {
if (cb && typeof cb === 'object') {
return batch.call(this, values, cb.cb, config);
} else {
return batch.call(this, values, cb, config);
}
return batch.call(this, values, cb, config);
};
};
7 changes: 3 additions & 4 deletions lib/ext/page.js
Expand Up @@ -75,7 +75,7 @@ function page(source, dest, limit, config) {
var $p = config.promise, $spex = config.spex, $utils = config.utils;

if (typeof source !== 'function') {
return $p.reject(new TypeError("Parameter 'source' must be a function."));
return $p.reject(new TypeError('Parameter \'source\' must be a function.'));
}

limit = (limit > 0) ? parseInt(limit) : 0;
Expand Down Expand Up @@ -136,7 +136,7 @@ function page(source, dest, limit, config) {
});
} else {
fail({
error: new Error("Unexpected data returned from the source."),
error: new Error('Unexpected data returned from the source.'),
source: request
}, 5, source.name);
}
Expand Down Expand Up @@ -179,8 +179,7 @@ module.exports = function (config) {
return function (source, dest, limit) {
if (dest && typeof dest === 'object') {
return page.call(this, source, dest.dest, dest.limit, config);
} else {
return page.call(this, source, dest, limit, config);
}
return page.call(this, source, dest, limit, config);
};
};
15 changes: 15 additions & 0 deletions lib/ext/reconnect.js
@@ -0,0 +1,15 @@
'use strict';

/**
* @method reconnect
* @description
*/
function reconnect(/*options, config*/) {
//var $p = config.promise;
}

module.exports = function (config) {
return function (options) {
return reconnect.call(this, options, config);
};
};
7 changes: 3 additions & 4 deletions lib/ext/sequence.js
Expand Up @@ -84,7 +84,7 @@ function sequence(source, dest, limit, track, config) {
var $p = config.promise, $utils = config.utils;

if (typeof source !== 'function') {
return $p.reject(new TypeError("Parameter 'source' must be a function."));
return $p.reject(new TypeError('Parameter \'source\' must be a function.'));
}

limit = (limit > 0) ? parseInt(limit) : 0;
Expand Down Expand Up @@ -170,7 +170,7 @@ function sequence(source, dest, limit, track, config) {
result = {
total: idx,
duration: length
}
};
}
resolve(result);
}
Expand All @@ -189,8 +189,7 @@ module.exports = function (config) {
return function (source, dest, limit, track) {
if (dest && typeof dest === 'object') {
return sequence.call(this, source, dest.dest, dest.limit, dest.track, config);
} else {
return sequence.call(this, source, dest, limit, track, config);
}
return sequence.call(this, source, dest, limit, track, config);
};
};
7 changes: 3 additions & 4 deletions lib/ext/stream/read.js
Expand Up @@ -66,11 +66,11 @@ function read(stream, receiver, closable, readSize, config) {
var $p = config.promise, $utils = config.utils;

if (!$utils.isReadableStream(stream)) {
return $p.reject(new TypeError("Readable stream is required."));
return $p.reject(new TypeError('Readable stream is required.'));
}

if (typeof receiver !== 'function') {
return $p.reject(new TypeError("Invalid stream receiver."));
return $p.reject(new TypeError('Invalid stream receiver.'));
}

readSize = (readSize > 0) ? parseInt(readSize) : null;
Expand Down Expand Up @@ -183,8 +183,7 @@ module.exports = function (config) {
return function (stream, receiver, closable, readSize) {
if (closable && typeof closable === 'object') {
return read.call(this, stream, receiver, closable.closable, closable.readSize, config);
} else {
return read.call(this, stream, receiver, closable, readSize, config);
}
return read.call(this, stream, receiver, closable, readSize, config);
};
};
10 changes: 5 additions & 5 deletions lib/index.js
Expand Up @@ -88,18 +88,18 @@ function parsePromiseLib(lib) {
}
var t = typeof lib;
if (t === 'function' || t === 'object') {
var root = typeof lib.Promise === 'function' ? lib.Promise : lib;
var Root = typeof lib.Promise === 'function' ? lib.Promise : lib;
promise = function (func) {
return new root(func);
return new Root(func);
};
promise.resolve = root.resolve;
promise.reject = root.reject;
promise.resolve = Root.resolve;
promise.reject = Root.reject;
if (typeof promise.resolve === 'function' && typeof promise.reject === 'function') {
return promise;
}
}
}
throw new TypeError("Invalid promise library specified.");
throw new TypeError('Invalid promise library specified.');
}

main.PromiseAdapter = require('./adapter');
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/index.js
Expand Up @@ -88,7 +88,7 @@ module.exports = function ($p) {
}

return handle(g.next());
}
};
}

};
14 changes: 8 additions & 6 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "spex",
"version": "1.2.0",
"version": "1.3.0",
"description": "Specialized Promise Extensions",
"main": "lib/index.js",
"typings": "typescript/spex.d.ts",
Expand All @@ -9,7 +9,8 @@
"doc": "./node_modules/.bin/jsdoc -c ./jsdoc/jsDoc.json ./jsdoc/README.md -u ./jsdoc/tutorials",
"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",
"browserify": "browserify lib/index.js -s spexLib -o spex.js"
"browserify": "browserify lib/index.js -s spexLib -o spex.js",
"lint": "./node_modules/.bin/eslint ./lib"
},
"files": [
"lib",
Expand Down Expand Up @@ -40,12 +41,13 @@
"npm": ">=1.4"
},
"devDependencies": {
"bluebird": "3.x",
"browserify": "13.x",
"coveralls": "2.x",
"eslint": "^4.1.1",
"bluebird": "3.5",
"browserify": "14.x",
"coveralls": "2.11",
"istanbul": "0.4",
"jasmine-node": "1.x",
"jsdoc": "3.x",
"typescript": "2.x"
"typescript": "2.4"
}
}

0 comments on commit 4390b75

Please sign in to comment.