diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index e1d50fb..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "env": { - "es6": true, - "node": true, - "jasmine": true - }, - "extends": "eslint:recommended", - "rules": { - "no-var": "error", - "prefer-const": "error", - "prefer-arrow-callback": "error", - "no-else-return": "error", - "no-multi-spaces": "error", - "no-whitespace-before-property": "error", - "camelcase": "error", - "new-cap": "error", - "no-console": "error", - "comma-dangle": "error", - "no-shadow": "error", - "indent": [ - "error", - 4, - { - "SwitchCase": 1 - } - ], - "quotes": [ - "error", - "single" - ], - "semi": [ - "error", - "always" - ] - } -} diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 0000000..76fb227 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,23 @@ +--- +name: Bug Report +about: New issues are for bug reports only. For everything else, use Discussions. +title: '' +labels: '' +assignees: '' + +--- + +### Expected behavior + + +### Actual behavior + + +### Steps to reproduce + + +### Environment + +* Version of spex: +* OS type (Linux/Windows/Mac): +* Version of Node.js: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bcf0be0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,27 @@ +name: ci + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + node-version: [14.x, 20.x] + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - run: npm install + - run: npm run lint + - run: npm run coverage diff --git a/README.md b/README.md index 6ffab7f..193628d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ -# Specialized Promise Extensions +SPEX +---- -[![Build Status](https://travis-ci.org/vitaly-t/spex.svg?branch=master)](https://travis-ci.org/vitaly-t/spex) -[![Coverage Status](https://coveralls.io/repos/vitaly-t/spex/badge.svg?branch=master)](https://coveralls.io/r/vitaly-t/spex?branch=master) -[![Join the chat at https://gitter.im/vitaly-t/spex](https://badges.gitter.im/vitaly-t/spex.svg)](https://gitter.im/vitaly-t/spex?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +Specialized Promise Extensions. + +[![Build Status](https://github.com/vitaly-t/spex/actions/workflows/ci.yml/badge.svg)](https://github.com/vitaly-t/spex/actions/workflows/ci.yml) +[![Node Version](https://img.shields.io/badge/nodejs-14%20--%2020-green.svg?logo=node.js&style=flat)](https://nodejs.org) [batch], [page], [sequence] - promise methods for the following patterns: * [Data Throttling & Load Balancing](http://vitaly-t.github.io/spex/tutorial-throttling.html) diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..3b31506 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,44 @@ +const js = require("@eslint/js"); +const globals = require("globals"); + +module.exports = [ + js.configs.recommended, + { + languageOptions: { + globals: { + ...globals.es6, + ...globals.node, + ...globals.jasmine, + ...globals.BigInt, + }, + parserOptions: { + ecmaFeatures: { globalReturn: true }, + }, + sourceType: "commonjs", + ecmaVersion: 2022, + }, + rules: { + "no-var": "error", + "prefer-const": "error", + "prefer-arrow-callback": "error", + "no-else-return": "error", + "no-multi-spaces": "error", + "no-whitespace-before-property": "error", + camelcase: "error", + "new-cap": "error", + "no-console": "error", + "comma-dangle": "error", + "no-shadow": "error", + "object-shorthand": ["error", "properties"], + indent: [ + "error", + 4, + { + SwitchCase: 1, + }, + ], + quotes: ["error", "single"], + semi: ["error", "always"], + }, + }, +]; diff --git a/lib/errors/batch.js b/lib/errors/batch.js index 5fb9020..eceb5f5 100644 --- a/lib/errors/batch.js +++ b/lib/errors/batch.js @@ -102,7 +102,7 @@ class BatchError extends Error { total: result.length, succeeded: result.length - e.length, failed: e.length, - duration: duration + duration }; this.getErrors = getErrors; @@ -170,4 +170,3 @@ npm.utils.addInspection(BatchError, function () { }); module.exports = {BatchError}; - diff --git a/lib/ext/page.js b/lib/ext/page.js index b5bfd26..a352148 100644 --- a/lib/ext/page.js +++ b/lib/ext/page.js @@ -117,7 +117,7 @@ function page(source, options, config) { .then(next) .catch(error => { fail({ - error: error, + error, dest: data }, 3, dest.name); }); @@ -130,9 +130,7 @@ function page(source, options, config) { return null; // this dummy return is just to prevent Bluebird warnings; }) .catch(error => { - fail({ - error: error - }, 0); + fail({error}, 0); }); } else { fail({ @@ -160,7 +158,7 @@ function page(source, options, config) { function success() { resolve({ pages: idx, - total: total, + total, duration: Date.now() - start }); } diff --git a/lib/ext/sequence.js b/lib/ext/sequence.js index 4888488..7bc6490 100644 --- a/lib/ext/sequence.js +++ b/lib/ext/sequence.js @@ -130,7 +130,7 @@ function sequence(source, options, config) { }) .catch(error => { fail({ - error: error, + error, dest: data }, 2, dest.name); }); diff --git a/lib/ext/stream/read.js b/lib/ext/stream/read.js index 563d1dd..78f7cfc 100644 --- a/lib/ext/stream/read.js +++ b/lib/ext/stream/read.js @@ -178,8 +178,8 @@ function read(stream, receiver, options, config) { cleanup(); resolve({ calls: index, - reads: reads, - length: length, + reads, + length, duration: Date.now() - start }); } diff --git a/lib/index.js b/lib/index.js index ac3baed..05d02fd 100644 --- a/lib/index.js +++ b/lib/index.js @@ -53,8 +53,8 @@ function main(promiseLib) { promise = parsePromiseLib(promiseLib); // promise library parsing; const config = { - spex: spex, - promise: promise, + spex, + promise, utils: npm.utils(promise) }; diff --git a/lib/utils/index.js b/lib/utils/index.js index 98f8d0d..2ed041b 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -10,8 +10,8 @@ module.exports = function ($p) { isReadableStream: npm.stat.isReadableStream, messageGap: npm.stat.messageGap, extend: npm.stat.extend, - resolve: resolve, - wrap: wrap + resolve, + wrap }; return exp; diff --git a/lib/utils/static.js b/lib/utils/static.js index 98cfb93..04e3dec 100644 --- a/lib/utils/static.js +++ b/lib/utils/static.js @@ -21,7 +21,7 @@ function isReadableStream(obj) { // Sets an object property as read-only and non-enumerable. function extend(obj, name, value) { Object.defineProperty(obj, name, { - value: value, + value, configurable: false, enumerable: false, writable: false @@ -65,10 +65,10 @@ function addInspection(type, cb) { } module.exports = { - addInspection: addInspection, - formatError: formatError, - isPromise: isPromise, - isReadableStream: isReadableStream, - messageGap: messageGap, - extend: extend + addInspection, + formatError, + isPromise, + isReadableStream, + messageGap, + extend }; diff --git a/package.json b/package.json index 5753680..a527411 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "spex", - "version": "3.3.0", + "version": "3.3.1", "description": "Specialized Promise Extensions", "main": "lib/index.js", "typings": "typescript/spex.d.ts", @@ -8,7 +8,6 @@ "test": "jasmine-node test", "doc": "jsdoc -c ./jsdoc/jsDoc.js ./jsdoc/README.md -u ./jsdoc/tutorials", "coverage": "istanbul cover ./node_modules/jasmine-node/bin/jasmine-node test", - "travis": "npm run lint && 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", "lint": "eslint ./lib ./test/**/*.spec.js" }, @@ -37,16 +36,17 @@ }, "license": "MIT", "engines": { - "node": ">=10.0.0" + "node": ">=14.0.0" }, "devDependencies": { + "@eslint/js": "9.12.0", "bluebird": "3.7.2", - "browserify": "17.0.0", + "browserify": "17.0.1", "coveralls": "3.1.1", - "eslint": "8.36.0", + "eslint": "9.12.0", "istanbul": "0.4.5", "jasmine-node": "3.0.0", - "jsdoc": "4.0.2", - "typescript": "5.0.2" + "jsdoc": "4.0.3", + "typescript": "5.6.3" } } diff --git a/test/ext/batch.spec.js b/test/ext/batch.spec.js index fb99d68..932393e 100644 --- a/test/ext/batch.spec.js +++ b/test/ext/batch.spec.js @@ -35,7 +35,7 @@ describe('Batch - negative', () => { throw err; } - spex.batch([1], {cb: cb}) + spex.batch([1], {cb}) .catch(reason => { r = reason; done(); @@ -62,7 +62,7 @@ describe('Batch - negative', () => { throw err; } - spex.batch([promise.reject(rejectError)], {cb: cb}) + spex.batch([promise.reject(rejectError)], {cb}) .catch(reason => { r = reason; done(); @@ -93,7 +93,7 @@ describe('Batch - negative', () => { return promise.reject(err); } - spex.batch([1, 2], {cb: cb}) + spex.batch([1, 2], {cb}) .catch(reason => { r = reason; done(); @@ -312,7 +312,7 @@ describe('Batch callback as generator', () => { } beforeEach(done => { - spex.batch.call(context, [1], {cb: cb}) + spex.batch.call(context, [1], {cb}) .then(data => { result = data; done(); diff --git a/test/ext/page.spec.js b/test/ext/page.spec.js index 9f199ff..6e17354 100644 --- a/test/ext/page.spec.js +++ b/test/ext/page.spec.js @@ -149,7 +149,7 @@ describe('Page - negative', () => { throw err; } - spex.page(source, {dest: dest}) + spex.page(source, {dest}) .catch(reason => { r = reason; done(); @@ -178,7 +178,7 @@ describe('Page - negative', () => { return promise.reject(err); } - spex.page(source, {dest: dest}) + spex.page(source, {dest}) .catch(reason => { r = reason; done(); @@ -303,7 +303,7 @@ describe('Page - positive', () => { } beforeEach(done => { - spex.page(source, {dest: dest}) + spex.page(source, {dest}) .then(data => { result = data; done(); @@ -330,7 +330,7 @@ describe('Page - positive', () => { } beforeEach(done => { - spex.page(source, {limit: limit}) + spex.page(source, {limit}) .then(data => { result = data; done(); @@ -382,7 +382,7 @@ describe('Page callbacks generators', () => { } beforeEach(done => { - spex.page.call(context, source, {dest: dest, limit: 1}) + spex.page.call(context, source, {dest, limit: 1}) .then(data => { result = data; done(); diff --git a/test/ext/read.spec.js b/test/ext/read.spec.js index 8ac08d8..a3b5e7d 100644 --- a/test/ext/read.spec.js +++ b/test/ext/read.spec.js @@ -173,11 +173,7 @@ describe('Stream/Read - positive', () => { }); function receiver(index, data, delay) { - r = { - index: index, - data: data, - delay: delay - }; + r = {index, data, delay}; } }); diff --git a/test/ext/sequence.spec.js b/test/ext/sequence.spec.js index 2422377..fbf4809 100644 --- a/test/ext/sequence.spec.js +++ b/test/ext/sequence.spec.js @@ -169,7 +169,7 @@ describe('Sequence - negative', () => { throw new Error(msg); } - spex.sequence(source, {dest: dest}) + spex.sequence(source, {dest}) .catch(e => { error = e; done(); @@ -198,7 +198,7 @@ describe('Sequence - negative', () => { return promise.reject(new Error(msg)); } - spex.sequence(source, {dest: dest}) + spex.sequence(source, {dest}) .catch(e => { r = e; done(); @@ -228,7 +228,7 @@ describe('Sequence - positive', () => { } beforeEach(done => { - spex.sequence(source, {limit: limit}) + spex.sequence(source, {limit}) .then(data => { result = data; }) @@ -261,7 +261,7 @@ describe('Sequence - positive', () => { } beforeEach(done => { - spex.sequence(source, {dest: dest, track: true}) + spex.sequence(source, {dest, track: true}) .then(data => { result = data; }) @@ -316,7 +316,7 @@ describe('Sequence callbacks generators', () => { } beforeEach(done => { - spex.sequence.call(context, source, {dest: dest, track: true}) + spex.sequence.call(context, source, {dest, track: true}) .then(data => { result = data; done();