serial-task 1.1.0 → 1.2.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/README.md +3 -2
- package/dist/index.d.ts +6 -6
- package/dist/index.mjs +1 -1
- package/package.json +2 -21
- package/dist/index.cjs +0 -1
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ pnpm add serial-task
|
|
|
21
21
|
## 🎯 Quick Start
|
|
22
22
|
|
|
23
23
|
> Note: For async functions(tasks/resultWrapper/conditions), use `createSerialTaskAsync` instead.
|
|
24
|
+
> Note: Relies on native `Promise.try` for async tasks, which is currently only supported in Node.js 20+ and modern browsers. For older environments, consider using a polyfill or transpiler that supports this feature.
|
|
24
25
|
|
|
25
26
|
```typescript
|
|
26
27
|
import { createSerialTask } from 'serial-task';
|
|
@@ -62,8 +63,7 @@ Creates a sync/async serial task function.
|
|
|
62
63
|
- **skipCondition?**: `function` - Function that determines when to skip a task (default: `() => false`)
|
|
63
64
|
- **resultWrapper?**: `function` - Function that transforms input between tasks, default(means the first task gets original args, subsequent tasks get the last return value):
|
|
64
65
|
```ts
|
|
65
|
-
(_task: Fn, index: number, _tasks: Fn[], args: unknown[], lastReturn: unknown) =>
|
|
66
|
-
index === 0 ? args : [lastReturn];
|
|
66
|
+
(_task: Fn, index: number, _tasks: Fn[], args: unknown[], lastReturn: unknown) => (index === 0 ? args : [lastReturn]);
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
#### Returns
|
|
@@ -312,6 +312,7 @@ const dynamicTask = createSerialTask({
|
|
|
312
312
|
## 🔄 Async Support
|
|
313
313
|
|
|
314
314
|
For async functions, use `createSerialTaskAsync`:
|
|
315
|
+
`createSerialTaskAsync` uses native `Promise.try`.
|
|
315
316
|
|
|
316
317
|
```typescript
|
|
317
318
|
import { createSerialTaskAsync } from 'serial-task';
|
package/dist/index.d.ts
CHANGED
|
@@ -125,14 +125,14 @@ interface SerialTaskOptions<F extends Fn> {
|
|
|
125
125
|
* @returns a funtcion that executes the tasks in order, returns `TaskReturn<OriginalReturn>`
|
|
126
126
|
*
|
|
127
127
|
* ## About
|
|
128
|
-
* @package
|
|
128
|
+
* @package SerialTask
|
|
129
129
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
130
|
-
* @version 1.
|
|
130
|
+
* @version 1.2.0 (Last Update: 2026.02.13 16:27:40.250)
|
|
131
131
|
* @license MIT
|
|
132
132
|
* @link https://github.com/baendlorel/serial-task
|
|
133
133
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
134
134
|
* @description Put a list of functions in and get a composed task function. Similar to functional programming's compose (function composition), but with more fine-grained and precise control, and the generated task incurs almost no runtime overhead. Supports both synchronous and asynchronous functions.
|
|
135
|
-
* @copyright Copyright (c)
|
|
135
|
+
* @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
|
|
136
136
|
*/
|
|
137
137
|
declare function createSerialTaskAsync<F extends Fn>(opts: SerialTaskOptions<F>): TaskifyAsync<F>;
|
|
138
138
|
|
|
@@ -151,14 +151,14 @@ declare function createSerialTaskAsync<F extends Fn>(opts: SerialTaskOptions<F>)
|
|
|
151
151
|
* @returns a funtcion that executes the tasks in order, returns `TaskReturn<OriginalReturn>`
|
|
152
152
|
*
|
|
153
153
|
* ## About
|
|
154
|
-
* @package
|
|
154
|
+
* @package SerialTask
|
|
155
155
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
156
|
-
* @version 1.
|
|
156
|
+
* @version 1.2.0 (Last Update: 2026.02.13 16:27:40.250)
|
|
157
157
|
* @license MIT
|
|
158
158
|
* @link https://github.com/baendlorel/serial-task
|
|
159
159
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
160
160
|
* @description Put a list of functions in and get a composed task function. Similar to functional programming's compose (function composition), but with more fine-grained and precise control, and the generated task incurs almost no runtime overhead. Supports both synchronous and asynchronous functions.
|
|
161
|
-
* @copyright Copyright (c)
|
|
161
|
+
* @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
|
|
162
162
|
*/
|
|
163
163
|
declare function createSerialTask<F extends Fn>(opts: SerialTaskOptions<F>): Taskify<F>;
|
|
164
164
|
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const e=Reflect.defineProperty,t=Array.isArray,r=()=>!1,n=r,o=(e,t,r,n,o)=>0===t?n:[o];function i(e){if("object"!=typeof e||null===e)throw new TypeError("[SerialTask] 'options' must be an object");const{name:i="",tasks:a,breakCondition:s=r,skipCondition:u=n,resultWrapper:l=o}=e;if("string"!=typeof i)throw new TypeError("[SerialTask] 'name' must be a string or omitted");if(!t(a)||a.some(e=>"function"!=typeof e))throw new TypeError("[SerialTask] 'tasks' must be a function array");if("function"!=typeof s)throw new TypeError("[SerialTask] 'breakCondition' must be a function or omitted");if("function"!=typeof u)throw new TypeError("[SerialTask] 'skipCondition' must be a function or omitted");if("function"!=typeof l)throw new TypeError("[SerialTask] 'resultWrapper' must be a function or omitted");return{name:i,tasks:a,breakCondition:s,skipCondition:u,resultWrapper:l}}function a(t){const{name:r,tasks:n,breakCondition:o,skipCondition:a,resultWrapper:s}=i(t);if(0===n.length){const t=()=>({value:void 0,results:[],trivial:!0,breakAt:-1,skipped:[]});return e(t,"name",{value:r,configurable:!0}),t}const u=async function(...e){let t;const r=new Array(n.length);let i=-1;const u=[];for(let l=0;l<n.length;l++){const f=n[l],c=await Promise.try(s,f,l,n,e,t);if(await Promise.try(o,f,l,n,e,t)){i=l;break}await Promise.try(a,f,l,n,e,t)?u.push(l):(t=await Promise.try(f,...c),r[l]=t)}return{value:t,results:r,trivial:!1,breakAt:i,skipped:u}};return r&&e(u,"name",{value:r,configurable:!0}),e(u,"length",{value:n[0].length,configurable:!0}),u}function s(t){const{name:r,tasks:n,breakCondition:o,skipCondition:a,resultWrapper:s}=i(t);if(0===n.length){const t=()=>({value:void 0,results:[],trivial:!0,breakAt:-1,skipped:[]});return e(t,"name",{value:r,configurable:!0}),t}const u=function(...e){let t;const r=new Array(n.length);let i=-1;const u=[];for(let l=0;l<n.length;l++){const f=n[l],c=s(f,l,n,e,t);if(o(f,l,n,e,t)){i=l;break}a(f,l,n,e,t)?u.push(l):(t=f.apply(null,c),r[l]=t)}return{value:t,results:r,trivial:!1,breakAt:i,skipped:u}};return r&&e(u,"name",{value:r,configurable:!0}),e(u,"length",{value:n[0].length,configurable:!0}),u}export{s as createSerialTask,a as createSerialTaskAsync};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "serial-task",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Kasukabe Tsumugi",
|
|
6
6
|
"email": "futami16237@gmail.com"
|
|
@@ -36,24 +36,5 @@
|
|
|
36
36
|
"build": "tsx ./.scripts/rollup.ts"
|
|
37
37
|
},
|
|
38
38
|
"license": "MIT",
|
|
39
|
-
"devDependencies": {
|
|
40
|
-
"@rollup/plugin-alias": "^5.1.1",
|
|
41
|
-
"@rollup/plugin-babel": "^6.0.4",
|
|
42
|
-
"@rollup/plugin-commonjs": "^28.0.6",
|
|
43
|
-
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
44
|
-
"@rollup/plugin-replace": "^6.0.2",
|
|
45
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
46
|
-
"@rollup/plugin-typescript": "^12.1.4",
|
|
47
|
-
"@types/node": "^24.3.0",
|
|
48
|
-
"@vitest/coverage-v8": "^3.2.4",
|
|
49
|
-
"oxlint": "^1.12.0",
|
|
50
|
-
"prettier": "^3.6.2",
|
|
51
|
-
"rimraf": "^6.0.1",
|
|
52
|
-
"rollup": "^4.47.1",
|
|
53
|
-
"rollup-plugin-dts": "^6.2.3",
|
|
54
|
-
"rollup-plugin-dts-merger": "^1.2.3",
|
|
55
|
-
"tslib": "^2.8.1",
|
|
56
|
-
"typescript": "^5.9.2",
|
|
57
|
-
"vitest": "^3.2.4"
|
|
58
|
-
}
|
|
39
|
+
"devDependencies": {}
|
|
59
40
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const t=Reflect.defineProperty,n=Array.isArray,e=Promise.resolve.bind(Promise),r=Promise.reject.bind(Promise),o=t=>("object"==typeof t&&null!==t||"function"==typeof t)&&("then"in t&&"function"==typeof t.then),i=()=>!1,a=i,s=(t,n,e,r,o)=>0===n?r:[o];function u(t){if("object"!=typeof t||null===t)throw new TypeError(": 'options' must be an object");const{name:e="kskbTask",tasks:r,breakCondition:o=i,skipCondition:u=a,resultWrapper:l=s}=t;if("string"!=typeof e)throw new TypeError(": 'name' must be a string or omitted");if(!n(r)||r.some(t=>"function"!=typeof t))throw new TypeError(": 'tasks' must be a function array");if("function"!=typeof o)throw new TypeError(": 'breakCondition' must be a function or omitted");if("function"!=typeof u)throw new TypeError(": 'skipCondition' must be a function or omitted");if("function"!=typeof l)throw new TypeError(": 'resultWrapper' must be a function or omitted");return{name:e,tasks:r,breakCondition:o,skipCondition:u,resultWrapper:l}}function l(t,n,...i){try{const r=t.apply(n,i);return o(r)?r:e(r)}catch(t){return r(t)}}function c(t,n,i){try{const r=t.apply(n,i);return o(r)?r:e(r)}catch(t){return r(t)}}exports.createSerialTask=function(n){const{name:e,tasks:r,breakCondition:o,skipCondition:i,resultWrapper:a}=u(n);if(0===r.length){const n=()=>({value:void 0,results:[],trivial:!0,breakAt:-1,skipped:[]});return t(n,"name",{value:e,configurable:!0}),n}const s=function(...t){let n;const e=new Array(r.length);let s=-1;const u=[];for(let l=0;l<r.length;l++){const c=r[l],f=a(c,l,r,t,n);if(o(c,l,r,t,n)){s=l;break}i(c,l,r,t,n)?u.push(l):(n=c.apply(null,f),e[l]=n)}return{value:n,results:e,trivial:!1,breakAt:s,skipped:u}};return t(s,"name",{value:e,configurable:!0}),t(s,"length",{value:r[0].length,configurable:!0}),s},exports.createSerialTaskAsync=function(n){const{name:e,tasks:r,breakCondition:o,skipCondition:i,resultWrapper:a}=u(n);if(0===r.length){const n=()=>({value:void 0,results:[],trivial:!0,breakAt:-1,skipped:[]});return t(n,"name",{value:e,configurable:!0}),n}const s=async function(...t){let n;const e=new Array(r.length);let s=-1;const u=[];for(let f=0;f<r.length;f++){const p=r[f],k=await l(a,null,p,f,r,t,n);if(await l(o,null,p,f,r,t,n)){s=f;break}await l(i,null,p,f,r,t,n)?u.push(f):(n=await c(p,null,k),e[f]=n)}return{value:n,results:e,trivial:!1,breakAt:s,skipped:u}};return t(s,"name",{value:e,configurable:!0}),t(s,"length",{value:r[0].length,configurable:!0}),s};
|