serial-task 1.0.0 → 1.1.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 CHANGED
@@ -44,7 +44,7 @@ console.log(result.results); // [6, 12, 11]
44
44
  The following diagram shows how functions are called in each iteration of the loop:
45
45
 
46
46
  <div style="text-align: center">
47
- <img src="https://raw.githubusercontent.com/baendlorel/serial-task/main/assets/flow.svg" alt="Execution Flow" width="360" />
47
+ <img src="https://raw.githubusercontent.com/baendlorel/serial-task/main/assets/flow.svg" alt="Execution Flow" width="80%" style="margin-left:10%; border:4px dashed #eee;border-radius:20px"/>
48
48
  </div>
49
49
 
50
50
  ## 📖 API Reference
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
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};
package/dist/index.d.ts CHANGED
@@ -1,55 +1,3 @@
1
- /**
2
- * ## Usage
3
- * Use this when you have async functions in tasks, conditions or result wrapper
4
- *
5
- * Creates an async serial task function that executes a series of functions in order
6
- * - all given functions(`options.tasks`) will be called in order
7
- * - generated task function will have the same length as the first task function
8
- * - you can appoint generated task function's name by `options.name`
9
- * - **Strongly Recommended**: all task functions have same input type and output type
10
- * - returned function.length will be the same as the first task function's length
11
- * @param opts Options for creating a serial task, details in `SerialTaskOptions`
12
- * @returns a funtcion that executes the tasks in order, returns `TaskReturn<OriginalReturn>`
13
- *
14
- * ## About
15
- * @package SerialTask
16
- * @author Kasukabe Tsumugi <futami16237@gmail.com>
17
- * @version 1.0.0 (Last Update: 2025.08.22 17:05:02.346)
18
- * @license MIT
19
- * @link https://github.com/baendlorel/serial-task
20
- * @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.
21
- * @copyright Copyright (c) 2025 Kasukabe Tsumugi. All rights reserved.
22
- */
23
- declare function createSerialTaskAsync<F extends Fn>(opts: SerialTaskOptions<F>): TaskifyAsync<F>;
24
-
25
- /**
26
- * ## Usage
27
- * **DO NOT Use** this when you have **async functions** in tasks, conditions or result wrapper
28
- *
29
- * Creates a serial task function that executes a series of functions in order.
30
- * - all given functions(`options.tasks`) will be called in order
31
- * - the returned value will be `options.resultWrapper`ed then passed to the next task
32
- * - generated task function will have the same length as the first task function
33
- * - you can appoint generated task function's name by `options.name`
34
- * - **Strongly Recommended**: all task functions have same input type and output type
35
- * - returned function.length will be the same as the first task function's length
36
- * @param opts Options for creating a serial task, details in `SerialTaskOptions`
37
- * @returns a funtcion that executes the tasks in order, returns `TaskReturn<OriginalReturn>`
38
- *
39
- * ## About
40
- * @package SerialTask
41
- * @author Kasukabe Tsumugi <futami16237@gmail.com>
42
- * @version 1.0.0 (Last Update: 2025.08.22 17:05:02.346)
43
- * @license MIT
44
- * @link https://github.com/baendlorel/serial-task
45
- * @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.
46
- * @copyright Copyright (c) 2025 Kasukabe Tsumugi. All rights reserved.
47
- */
48
- declare function createSerialTask<F extends Fn>(opts: SerialTaskOptions<F>): Taskify<F>;
49
-
50
- export { createSerialTask, createSerialTaskAsync };
51
-
52
- // # from: src/global.d.ts
53
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
54
2
  type Fn = (...args: any[]) => any;
55
3
 
@@ -134,13 +82,7 @@ interface SerialTaskOptions<F extends Fn> {
134
82
  * }
135
83
  * ```
136
84
  */
137
- resultWrapper?: (
138
- task: F,
139
- index: number,
140
- tasks: F[],
141
- args: Parameters<F>,
142
- lastReturn: ReturnType<F>
143
- ) => unknown[];
85
+ resultWrapper?: (task: F, index: number, tasks: F[], args: Parameters<F>, lastReturn: ReturnType<F>) => unknown[];
144
86
 
145
87
  /**
146
88
  * Break the loop and return the last result immediately when this function returns `true`
@@ -153,13 +95,7 @@ interface SerialTaskOptions<F extends Fn> {
153
95
  * @param args input value of the whole serial task
154
96
  * @param lastReturn returned value of the last task function
155
97
  */
156
- breakCondition?: (
157
- task: F,
158
- index: number,
159
- tasks: F[],
160
- args: Parameters<F>,
161
- lastReturn: ReturnType<F>
162
- ) => boolean;
98
+ breakCondition?: (task: F, index: number, tasks: F[], args: Parameters<F>, lastReturn: ReturnType<F>) => boolean;
163
99
 
164
100
  /**
165
101
  * Give `true` to skip this task item
@@ -172,13 +108,59 @@ interface SerialTaskOptions<F extends Fn> {
172
108
  * @param args input value of the whole serial task
173
109
  * @param lastReturn returned value of the last task function
174
110
  */
175
- skipCondition?: (
176
- task: F,
177
- index: number,
178
- tasks: F[],
179
- args: Parameters<F>,
180
- lastReturn: ReturnType<F>
181
- ) => boolean;
111
+ skipCondition?: (task: F, index: number, tasks: F[], args: Parameters<F>, lastReturn: ReturnType<F>) => boolean;
182
112
  }
183
113
 
184
- type StrictSerialTaskOptions<F extends Fn> = Required<SerialTaskOptions<F>>;
114
+ /**
115
+ * ## Usage
116
+ * Use this when you have async functions in tasks, conditions or result wrapper
117
+ *
118
+ * Creates an async serial task function that executes a series of functions in order
119
+ * - all given functions(`options.tasks`) will be called in order
120
+ * - generated task function will have the same length as the first task function
121
+ * - you can appoint generated task function's name by `options.name`
122
+ * - **Strongly Recommended**: all task functions have same input type and output type
123
+ * - returned function.length will be the same as the first task function's length
124
+ * @param opts Options for creating a serial task, details in `SerialTaskOptions`
125
+ * @returns a funtcion that executes the tasks in order, returns `TaskReturn<OriginalReturn>`
126
+ *
127
+ * ## About
128
+ * @package
129
+ * @author Kasukabe Tsumugi <futami16237@gmail.com>
130
+ * @version 1.1.0 (Last Update: 2025.10.20 21:39:55.158)
131
+ * @license MIT
132
+ * @link https://github.com/baendlorel/serial-task
133
+ * @link https://baendlorel.github.io/ Welcome to my site!
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) 2025 Kasukabe Tsumugi. All rights reserved.
136
+ */
137
+ declare function createSerialTaskAsync<F extends Fn>(opts: SerialTaskOptions<F>): TaskifyAsync<F>;
138
+
139
+ /**
140
+ * ## Usage
141
+ * **DO NOT Use** this when you have **async functions** in tasks, conditions or result wrapper
142
+ *
143
+ * Creates a serial task function that executes a series of functions in order.
144
+ * - all given functions(`options.tasks`) will be called in order
145
+ * - the returned value will be `options.resultWrapper`ed then passed to the next task
146
+ * - generated task function will have the same length as the first task function
147
+ * - you can appoint generated task function's name by `options.name`
148
+ * - **Strongly Recommended**: all task functions have same input type and output type
149
+ * - returned function.length will be the same as the first task function's length
150
+ * @param opts Options for creating a serial task, details in `SerialTaskOptions`
151
+ * @returns a funtcion that executes the tasks in order, returns `TaskReturn<OriginalReturn>`
152
+ *
153
+ * ## About
154
+ * @package
155
+ * @author Kasukabe Tsumugi <futami16237@gmail.com>
156
+ * @version 1.1.0 (Last Update: 2025.10.20 21:39:55.158)
157
+ * @license MIT
158
+ * @link https://github.com/baendlorel/serial-task
159
+ * @link https://baendlorel.github.io/ Welcome to my site!
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) 2025 Kasukabe Tsumugi. All rights reserved.
162
+ */
163
+ declare function createSerialTask<F extends Fn>(opts: SerialTaskOptions<F>): Taskify<F>;
164
+
165
+ export { createSerialTask, createSerialTaskAsync };
166
+ export type { SerialTaskOptions, TaskReturn, Taskify, TaskifyAsync };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- const t=Reflect.defineProperty,e=Array.isArray,n=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,e,n,r,o)=>0===e?r:[o];function u(t){if("object"!=typeof t||null===t)throw new TypeError("SerialTask: 'options' must be an object");const{name:n="kskbTask",tasks:r,breakCondition:o=i,skipCondition:u=a,resultWrapper:l=s}=t;if("string"!=typeof n)throw new TypeError("SerialTask: 'name' must be a string or omitted");if(!e(r)||r.some(t=>"function"!=typeof t))throw new TypeError("SerialTask: 'tasks' must be a function array");if("function"!=typeof o)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:n,tasks:r,breakCondition:o,skipCondition:u,resultWrapper:l}}function l(t,e,...i){try{const r=t.apply(e,i);return o(r)?r:n(r)}catch(t){return r(t)}}function c(t,e,i){try{const r=t.apply(e,i);return o(r)?r:n(r)}catch(t){return r(t)}}function f(e){const{name:n,tasks:r,breakCondition:o,skipCondition:i,resultWrapper:a}=u(e);if(0===r.length){const e=()=>({value:void 0,results:[],trivial:!0,breakAt:-1,skipped:[]});return t(e,"name",{value:n,configurable:!0}),e}const s=async function(...t){let e;const n=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,e);if(await l(o,null,p,f,r,t,e)){s=f;break}await l(i,null,p,f,r,t,e)?u.push(f):(e=await c(p,null,k),n[f]=e)}return{value:e,results:n,trivial:!1,breakAt:s,skipped:u}};return t(s,"name",{value:n,configurable:!0}),t(s,"length",{value:r[0].length,configurable:!0}),s}function p(e){const{name:n,tasks:r,breakCondition:o,skipCondition:i,resultWrapper:a}=u(e);if(0===r.length){const e=()=>({value:void 0,results:[],trivial:!0,breakAt:-1,skipped:[]});return t(e,"name",{value:n,configurable:!0}),e}const s=function(...t){let e;const n=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,e);if(o(c,l,r,t,e)){s=l;break}i(c,l,r,t,e)?u.push(l):(e=c.apply(null,f),n[l]=e)}return{value:e,results:n,trivial:!1,breakAt:s,skipped:u}};return t(s,"name",{value:n,configurable:!0}),t(s,"length",{value:r[0].length,configurable:!0}),s}export{p as createSerialTask,f as createSerialTaskAsync};
1
+ 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,u=(t,n,e,r,o)=>0===n?r:[o];function s(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:s=a,resultWrapper:l=u}=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 s)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:s,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)}}function f(n){const{name:e,tasks:r,breakCondition:o,skipCondition:i,resultWrapper:a}=s(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 u=async function(...t){let n;const e=new Array(r.length);let u=-1;const s=[];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)){u=f;break}await l(i,null,p,f,r,t,n)?s.push(f):(n=await c(p,null,k),e[f]=n)}return{value:n,results:e,trivial:!1,breakAt:u,skipped:s}};return t(u,"name",{value:e,configurable:!0}),t(u,"length",{value:r[0].length,configurable:!0}),u}function p(n){const{name:e,tasks:r,breakCondition:o,skipCondition:i,resultWrapper:a}=s(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 u=function(...t){let n;const e=new Array(r.length);let u=-1;const s=[];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)){u=l;break}i(c,l,r,t,n)?s.push(l):(n=c.apply(null,f),e[l]=n)}return{value:n,results:e,trivial:!1,breakAt:u,skipped:s}};return t(u,"name",{value:e,configurable:!0}),t(u,"length",{value:r[0].length,configurable:!0}),u}export{p as createSerialTask,f as createSerialTaskAsync};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serial-task",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "author": {
5
5
  "name": "Kasukabe Tsumugi",
6
6
  "email": "futami16237@gmail.com"
@@ -29,15 +29,14 @@
29
29
  "javascript"
30
30
  ],
31
31
  "scripts": {
32
+ "lines": "clear && find ./src -type f \\( -name \"*.ts\" -o -name \"*.tsx\" -o -name \"*.js\" -o -name \"*.mjs\" -o -name \"*.cjs\" -o -name \"*.cpp\" -o -name \"*.h\" -o -name \"*.py\" -o -name \"*.css\" -o -name \"*.rs\" -o -name \"*.rc\" \\) | xargs wc -l",
32
33
  "test": "clear & vitest",
33
34
  "lint": "oxlint .",
34
35
  "cover": "clear & vitest --coverage",
35
- "build": "node ./scripts/rollup.mjs"
36
+ "build": "tsx ./.scripts/rollup.ts"
36
37
  },
37
38
  "license": "MIT",
38
39
  "devDependencies": {
39
- "@babel/plugin-proposal-decorators": "^7.28.0",
40
- "@babel/preset-env": "^7.28.3",
41
40
  "@rollup/plugin-alias": "^5.1.1",
42
41
  "@rollup/plugin-babel": "^6.0.4",
43
42
  "@rollup/plugin-commonjs": "^28.0.6",