sequently 2.1.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/sequently.js +65 -108
- package/package.json +8 -7
- package/src/index.js +15 -2
- package/test/index.js +191 -0
- /package/{webpack.config.js → webpack.config.cjs} +0 -0
package/dist/sequently.js
CHANGED
|
@@ -1,133 +1,90 @@
|
|
|
1
|
-
var Sequently
|
|
2
|
-
/******/ (
|
|
3
|
-
/******/
|
|
4
|
-
/******/
|
|
5
|
-
/******/
|
|
6
|
-
/******/
|
|
7
|
-
|
|
8
|
-
/******/
|
|
9
|
-
/******/
|
|
10
|
-
/******/
|
|
11
|
-
/******/
|
|
12
|
-
/******/
|
|
13
|
-
/******/
|
|
14
|
-
/******/
|
|
15
|
-
/******/
|
|
16
|
-
/******/
|
|
17
|
-
/******/
|
|
18
|
-
/******/
|
|
19
|
-
/******/
|
|
20
|
-
/******/
|
|
21
|
-
/******/
|
|
22
|
-
/******/
|
|
23
|
-
/******/
|
|
24
|
-
/******/
|
|
25
|
-
/******/
|
|
26
|
-
/******/ // Return the exports of the module
|
|
27
|
-
/******/ return module.exports;
|
|
28
|
-
/******/ }
|
|
29
|
-
/******/
|
|
30
|
-
/******/
|
|
31
|
-
/******/ // expose the modules object (__webpack_modules__)
|
|
32
|
-
/******/ __webpack_require__.m = modules;
|
|
33
|
-
/******/
|
|
34
|
-
/******/ // expose the module cache
|
|
35
|
-
/******/ __webpack_require__.c = installedModules;
|
|
36
|
-
/******/
|
|
37
|
-
/******/ // define getter function for harmony exports
|
|
38
|
-
/******/ __webpack_require__.d = function(exports, name, getter) {
|
|
39
|
-
/******/ if(!__webpack_require__.o(exports, name)) {
|
|
40
|
-
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
|
1
|
+
var Sequently;
|
|
2
|
+
/******/ (() => { // webpackBootstrap
|
|
3
|
+
/******/ "use strict";
|
|
4
|
+
/******/ // The require scope
|
|
5
|
+
/******/ const __webpack_require__ = {};
|
|
6
|
+
/******/
|
|
7
|
+
/************************************************************************/
|
|
8
|
+
/******/ /* webpack/runtime/define property getters */
|
|
9
|
+
/******/ // define getter/value functions for harmony exports
|
|
10
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
11
|
+
/******/ if(Array.isArray(definition)) {
|
|
12
|
+
/******/ var i = 0;
|
|
13
|
+
/******/ while(i < definition.length) {
|
|
14
|
+
/******/ var key = definition[i++];
|
|
15
|
+
/******/ var binding = definition[i++];
|
|
16
|
+
/******/ var descriptor = binding === 0 ? { enumerable: true, value: definition[i++] } : { enumerable: true, get: binding };
|
|
17
|
+
/******/ if(!__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, descriptor);
|
|
18
|
+
/******/ }
|
|
19
|
+
/******/ } else {
|
|
20
|
+
/******/ for(var key in definition) {
|
|
21
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
22
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
23
|
+
/******/ }
|
|
24
|
+
/******/ }
|
|
41
25
|
/******/ }
|
|
42
26
|
/******/ };
|
|
43
|
-
/******/
|
|
27
|
+
/******/
|
|
28
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
29
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop));
|
|
30
|
+
/******/
|
|
31
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
44
32
|
/******/ // define __esModule on exports
|
|
45
|
-
/******/ __webpack_require__.r =
|
|
46
|
-
/******/
|
|
47
|
-
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
48
|
-
/******/ }
|
|
33
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
34
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
49
35
|
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
50
36
|
/******/ };
|
|
51
|
-
/******/
|
|
52
|
-
/******/ // create a fake namespace object
|
|
53
|
-
/******/ // mode & 1: value is a module id, require it
|
|
54
|
-
/******/ // mode & 2: merge all properties of value into the ns
|
|
55
|
-
/******/ // mode & 4: return value when already ns object
|
|
56
|
-
/******/ // mode & 8|1: behave like require
|
|
57
|
-
/******/ __webpack_require__.t = function(value, mode) {
|
|
58
|
-
/******/ if(mode & 1) value = __webpack_require__(value);
|
|
59
|
-
/******/ if(mode & 8) return value;
|
|
60
|
-
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
|
61
|
-
/******/ var ns = Object.create(null);
|
|
62
|
-
/******/ __webpack_require__.r(ns);
|
|
63
|
-
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
|
64
|
-
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
|
65
|
-
/******/ return ns;
|
|
66
|
-
/******/ };
|
|
67
|
-
/******/
|
|
68
|
-
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
69
|
-
/******/ __webpack_require__.n = function(module) {
|
|
70
|
-
/******/ var getter = module && module.__esModule ?
|
|
71
|
-
/******/ function getDefault() { return module['default']; } :
|
|
72
|
-
/******/ function getModuleExports() { return module; };
|
|
73
|
-
/******/ __webpack_require__.d(getter, 'a', getter);
|
|
74
|
-
/******/ return getter;
|
|
75
|
-
/******/ };
|
|
76
|
-
/******/
|
|
77
|
-
/******/ // Object.prototype.hasOwnProperty.call
|
|
78
|
-
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
|
79
|
-
/******/
|
|
80
|
-
/******/ // __webpack_public_path__
|
|
81
|
-
/******/ __webpack_require__.p = "";
|
|
82
|
-
/******/
|
|
83
|
-
/******/
|
|
84
|
-
/******/ // Load entry module and return exports
|
|
85
|
-
/******/ return __webpack_require__(__webpack_require__.s = 0);
|
|
86
|
-
/******/ })
|
|
37
|
+
/******/
|
|
87
38
|
/************************************************************************/
|
|
88
|
-
|
|
89
|
-
/* 0 */
|
|
90
|
-
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
91
|
-
|
|
92
|
-
"use strict";
|
|
39
|
+
let __webpack_exports__ = {};
|
|
93
40
|
__webpack_require__.r(__webpack_exports__);
|
|
94
41
|
|
|
95
42
|
|
|
96
|
-
/* harmony default export */
|
|
43
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
|
|
97
44
|
sequence: function (functions, args) {
|
|
98
|
-
let
|
|
99
|
-
let
|
|
45
|
+
let functionArgs;
|
|
46
|
+
let functionPrimes = [];
|
|
100
47
|
let incrementers = [];
|
|
101
|
-
let
|
|
102
|
-
|
|
48
|
+
let primeIndex = 0;
|
|
49
|
+
if (!Array.isArray(functions) || functions.length === 0) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
103
52
|
if (!Array.isArray(args)) {
|
|
104
|
-
|
|
53
|
+
functionArgs = Array(functions.length).fill([]);
|
|
105
54
|
} else {
|
|
106
|
-
|
|
55
|
+
functionArgs = [];
|
|
56
|
+
for (let i = 0; i < functions.length; i += 1) {
|
|
57
|
+
if (Array.isArray(args[i])) {
|
|
58
|
+
functionArgs.push(args[i]);
|
|
59
|
+
} else {
|
|
60
|
+
functionArgs.push([]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
107
63
|
}
|
|
108
|
-
|
|
109
64
|
for (let index = 0; index < functions.length; index += 1) {
|
|
110
65
|
let incrementer = function () {
|
|
111
|
-
|
|
112
|
-
|
|
66
|
+
primeIndex += 1;
|
|
67
|
+
if (primeIndex < functionPrimes.length) {
|
|
68
|
+
functionPrimes[primeIndex](incrementers[primeIndex]);
|
|
69
|
+
}
|
|
113
70
|
};
|
|
114
|
-
|
|
115
71
|
incrementers.push(incrementer);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
functions[prime_index](callback);
|
|
72
|
+
let functionPrime = function (callback) {
|
|
73
|
+
if (functionArgs[primeIndex].length === 0) {
|
|
74
|
+
functions[primeIndex](callback);
|
|
120
75
|
} else {
|
|
121
|
-
functions[
|
|
76
|
+
functions[primeIndex](functionArgs[primeIndex], callback);
|
|
122
77
|
}
|
|
123
78
|
};
|
|
124
|
-
|
|
125
|
-
function_primes.push(function_prime);
|
|
79
|
+
functionPrimes.push(functionPrime);
|
|
126
80
|
}
|
|
127
|
-
|
|
128
|
-
function_primes[0](incrementers[0], function_args[0]);
|
|
81
|
+
functionPrimes[0](incrementers[0], functionArgs[0]);
|
|
129
82
|
}
|
|
130
83
|
});
|
|
84
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, [
|
|
85
|
+
/* harmony export */ "default", 0, __WEBPACK_DEFAULT_EXPORT__
|
|
86
|
+
/* harmony export */ ]);
|
|
131
87
|
|
|
132
|
-
|
|
133
|
-
/******/
|
|
88
|
+
Sequently = __webpack_exports__;
|
|
89
|
+
/******/ })()
|
|
90
|
+
;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sequently",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Library for running asynchronous functions sequentially",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,15 +23,16 @@
|
|
|
23
23
|
"@babel/preset-env": "^7.4.5",
|
|
24
24
|
"babel-loader": "^8.0.6",
|
|
25
25
|
"standard": "^12.0.1",
|
|
26
|
-
"webpack": "^
|
|
27
|
-
"webpack-cli": "^
|
|
28
|
-
"webpack-dev-server": "^
|
|
26
|
+
"webpack": "^5.97.1",
|
|
27
|
+
"webpack-cli": "^6.0.1",
|
|
28
|
+
"webpack-dev-server": "^5.2.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"core-js": "3"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
}
|
|
34
|
+
"build": "webpack --mode production",
|
|
35
|
+
"test": "node --test test/*.js"
|
|
36
|
+
},
|
|
37
|
+
"type": "module"
|
|
37
38
|
}
|
package/src/index.js
CHANGED
|
@@ -7,16 +7,29 @@ export default {
|
|
|
7
7
|
let incrementers = []
|
|
8
8
|
let primeIndex = 0
|
|
9
9
|
|
|
10
|
+
if (!Array.isArray(functions) || functions.length === 0) {
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
|
|
10
14
|
if (!Array.isArray(args)) {
|
|
11
15
|
functionArgs = Array(functions.length).fill([])
|
|
12
16
|
} else {
|
|
13
|
-
functionArgs =
|
|
17
|
+
functionArgs = []
|
|
18
|
+
for (let i = 0; i < functions.length; i += 1) {
|
|
19
|
+
if (Array.isArray(args[i])) {
|
|
20
|
+
functionArgs.push(args[i])
|
|
21
|
+
} else {
|
|
22
|
+
functionArgs.push([])
|
|
23
|
+
}
|
|
24
|
+
}
|
|
14
25
|
}
|
|
15
26
|
|
|
16
27
|
for (let index = 0; index < functions.length; index += 1) {
|
|
17
28
|
let incrementer = function () {
|
|
18
29
|
primeIndex += 1
|
|
19
|
-
|
|
30
|
+
if (primeIndex < functionPrimes.length) {
|
|
31
|
+
functionPrimes[primeIndex](incrementers[primeIndex])
|
|
32
|
+
}
|
|
20
33
|
}
|
|
21
34
|
|
|
22
35
|
incrementers.push(incrementer)
|
package/test/index.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { strict as assert } from 'node:assert'
|
|
4
|
+
import { describe, it } from 'node:test'
|
|
5
|
+
import seq from '../src/index.js'
|
|
6
|
+
|
|
7
|
+
describe('sequence', () => {
|
|
8
|
+
it('executes functions in order', () => {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
const order = []
|
|
11
|
+
seq.sequence([
|
|
12
|
+
(cb) => { order.push(1); cb() },
|
|
13
|
+
(cb) => { order.push(2); cb() },
|
|
14
|
+
(cb) => { order.push(3); cb() }
|
|
15
|
+
])
|
|
16
|
+
// Allow async callbacks to complete
|
|
17
|
+
setTimeout(() => {
|
|
18
|
+
try {
|
|
19
|
+
assert.deepEqual(order, [1, 2, 3])
|
|
20
|
+
resolve()
|
|
21
|
+
} catch (e) {
|
|
22
|
+
reject(e)
|
|
23
|
+
}
|
|
24
|
+
}, 10)
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('passes arguments to functions when args array is provided', () => {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
const results = []
|
|
31
|
+
seq.sequence([
|
|
32
|
+
(args, cb) => { results.push(args[0]); cb() },
|
|
33
|
+
(args, cb) => { results.push(args[0]); cb() }
|
|
34
|
+
], [[10], [20]])
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
try {
|
|
37
|
+
assert.deepEqual(results, [10, 20])
|
|
38
|
+
resolve()
|
|
39
|
+
} catch (e) {
|
|
40
|
+
reject(e)
|
|
41
|
+
}
|
|
42
|
+
}, 10)
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('calls functions with no arguments when args is not an array', () => {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
const results = []
|
|
49
|
+
seq.sequence([
|
|
50
|
+
(cb) => { results.push('a'); cb() },
|
|
51
|
+
(cb) => { results.push('b'); cb() }
|
|
52
|
+
], 'not-an-array')
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
try {
|
|
55
|
+
assert.deepEqual(results, ['a', 'b'])
|
|
56
|
+
resolve()
|
|
57
|
+
} catch (e) {
|
|
58
|
+
reject(e)
|
|
59
|
+
}
|
|
60
|
+
}, 10)
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('handles a single function without throwing', () => {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
let called = false
|
|
67
|
+
seq.sequence([
|
|
68
|
+
(cb) => { called = true; cb() }
|
|
69
|
+
])
|
|
70
|
+
setTimeout(() => {
|
|
71
|
+
try {
|
|
72
|
+
assert.equal(called, true)
|
|
73
|
+
resolve()
|
|
74
|
+
} catch (e) {
|
|
75
|
+
reject(e)
|
|
76
|
+
}
|
|
77
|
+
}, 10)
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('handles empty function array', () => {
|
|
82
|
+
return new Promise((resolve, reject) => {
|
|
83
|
+
// Should not throw
|
|
84
|
+
seq.sequence([])
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
resolve()
|
|
87
|
+
}, 10)
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('passes callback as second argument when no args provided', () => {
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
const results = []
|
|
94
|
+
seq.sequence([
|
|
95
|
+
(cb) => { results.push('a'); cb() },
|
|
96
|
+
(cb) => { results.push('b'); cb() }
|
|
97
|
+
])
|
|
98
|
+
setTimeout(() => {
|
|
99
|
+
try {
|
|
100
|
+
assert.deepEqual(results, ['a', 'b'])
|
|
101
|
+
resolve()
|
|
102
|
+
} catch (e) {
|
|
103
|
+
reject(e)
|
|
104
|
+
}
|
|
105
|
+
}, 10)
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it('handles multiple functions with varying arg lengths', () => {
|
|
110
|
+
return new Promise((resolve, reject) => {
|
|
111
|
+
const results = []
|
|
112
|
+
seq.sequence([
|
|
113
|
+
(args, cb) => { results.push(args[0] + args[1]); cb() },
|
|
114
|
+
(args, cb) => { results.push(args[0]); cb() },
|
|
115
|
+
(cb) => { results.push('done'); cb() }
|
|
116
|
+
], [[1, 2], [3], []])
|
|
117
|
+
setTimeout(() => {
|
|
118
|
+
try {
|
|
119
|
+
assert.deepEqual(results, [3, 3, 'done'])
|
|
120
|
+
resolve()
|
|
121
|
+
} catch (e) {
|
|
122
|
+
reject(e)
|
|
123
|
+
}
|
|
124
|
+
}, 10)
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('does not throw TypeError on last function callback (bounds check)', () => {
|
|
129
|
+
return new Promise((resolve, reject) => {
|
|
130
|
+
let lastCalled = false
|
|
131
|
+
// This was the bug: the last function's callback would increment primeIndex
|
|
132
|
+
// beyond the array length and try to call undefined as a function
|
|
133
|
+
seq.sequence([
|
|
134
|
+
(cb) => { cb() },
|
|
135
|
+
(cb) => { lastCalled = true; cb() }
|
|
136
|
+
])
|
|
137
|
+
setTimeout(() => {
|
|
138
|
+
try {
|
|
139
|
+
assert.equal(lastCalled, true)
|
|
140
|
+
resolve()
|
|
141
|
+
} catch (e) {
|
|
142
|
+
reject(e)
|
|
143
|
+
}
|
|
144
|
+
}, 10)
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
it('handles short args array without throwing', () => {
|
|
149
|
+
return new Promise((resolve, reject) => {
|
|
150
|
+
const results = []
|
|
151
|
+
// Only 1 args entry for 3 functions — missing entries should default to []
|
|
152
|
+
seq.sequence([
|
|
153
|
+
(args, cb) => { results.push(args[0]); cb() },
|
|
154
|
+
(cb) => { results.push('no-args'); cb() },
|
|
155
|
+
(cb) => { results.push('no-args'); cb() }
|
|
156
|
+
], [[42]])
|
|
157
|
+
setTimeout(() => {
|
|
158
|
+
try {
|
|
159
|
+
assert.deepEqual(results, [42, 'no-args', 'no-args'])
|
|
160
|
+
resolve()
|
|
161
|
+
} catch (e) {
|
|
162
|
+
reject(e)
|
|
163
|
+
}
|
|
164
|
+
}, 10)
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it('handles null functions parameter without throwing', () => {
|
|
169
|
+
return new Promise((resolve, reject) => {
|
|
170
|
+
// Should not throw
|
|
171
|
+
assert.doesNotThrow(() => {
|
|
172
|
+
seq.sequence(null)
|
|
173
|
+
})
|
|
174
|
+
setTimeout(() => {
|
|
175
|
+
resolve()
|
|
176
|
+
}, 10)
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('handles non-array functions parameter without throwing', () => {
|
|
181
|
+
return new Promise((resolve, reject) => {
|
|
182
|
+
// Should not throw
|
|
183
|
+
assert.doesNotThrow(() => {
|
|
184
|
+
seq.sequence('not-an-array')
|
|
185
|
+
})
|
|
186
|
+
setTimeout(() => {
|
|
187
|
+
resolve()
|
|
188
|
+
}, 10)
|
|
189
|
+
})
|
|
190
|
+
})
|
|
191
|
+
})
|
|
File without changes
|