defered-branch 2.2.8 → 2.2.10

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/index.cjs ADDED
@@ -0,0 +1,150 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class{_branch=null;add(e,t){if(typeof t!=`function`)throw TypeError(`DeferBranch: branch must be a function`);return e&&!this._branch&&(this._branch=t),this}nomatch(e){if(typeof e!=`function`)throw TypeError(`DeferBranch: branch must be a function`);return this._branch||e(),this}run(...e){if(this._branch){let t=this._branch.apply(null,e);return this._branch=null,t}}},t=class{_condranches=[];_branch=null;_nomatch=null;add(e,t){if(typeof e!=`function`)throw TypeError(`DeferBranch: condition must be a function`);if(typeof t!=`function`)throw TypeError(`DeferBranch: branch must be a function`);return this._condranches.push(e,t),this}nomatch(e){if(typeof e!=`function`)throw TypeError(`DeferBranch: handler must be a function`);return this._nomatch=e,this}predicate(...e){let t=this._condranches.length;for(let e=0;e<t;e+=2)if(this._condranches[e]()){this._branch=this._condranches[e+1];return}this._nomatch&&this._nomatch.apply(this,e)}run(...e){if(this._branch){let t=this._branch.apply(null,e);return this._branch=null,t}}},n=class{_condranches=[];_branches=[];_nomatch=null;add(e,t){if(typeof e!=`function`)throw TypeError(`DeferBranch: condition must be a function`);if(typeof t!=`function`)throw TypeError(`DeferBranch: branch must be a function`);return this._condranches.push(e,t),this}nomatch(e){if(typeof e!=`function`)throw TypeError(`DeferBranch: handler must be a function`);return this._nomatch=e,this}predicate(...e){let t=this._condranches.length;for(let e=0;e<t;e+=2)this._condranches[e]()&&this._branches.push(this._condranches[e+1]);this._nomatch&&this._branches.length===0&&this._nomatch.apply(this,e)}run(...e){let t=this._branches.length;if(t!==0){for(let n=0;n<t;n++)this._branches[n].apply(null,e);this._branches.length=0}}},r=class{_branches=[];add(e,t){if(typeof t!=`function`)throw TypeError(`DeferBranch: branch must be a function`);return e&&this._branches.push(t),this}nomatch(e){if(typeof e!=`function`)throw TypeError(`DeferBranch: branch must be a function`);return this._branches.length===0&&e(),this}run(...e){let t=this._branches.length;if(t!==0){for(let n=0;n<t;n++)this._branches[n].apply(null,e);this._branches.length=0}}};
2
+ /**
3
+ * ## Steps to use
4
+ * 1. const a = deferedBranch()
5
+ * 2. add branches by a.add(condition, branch)
6
+ * 3. (optional) add defered nomatch handler, or add and run at the same time by a.nomatch(handler)
7
+ * 4. ...run some other logic
8
+ * 5. run this branch by a.run();
9
+ *
10
+ * ## Type Annotation (optional)
11
+ * ```ts
12
+ * type BranchFn = (a: number) => void;
13
+ * type NoMatchFn = () => void;
14
+ * const a = deferedBranch<BranchFn, NoMatchFn>();
15
+ *
16
+ * // then we have restrictions:
17
+ * a.add(true, someFn satisfies BranchFn);
18
+ * a.nomatch(otherFn satisfies NoMatchFn);
19
+ *
20
+ * // some other logic
21
+ *
22
+ * a.run(...args); // input args are restricted to Parameters<BranchFn>
23
+ * ```
24
+ *
25
+ * ## About
26
+ * @package DeferedBranch
27
+ * @author Kasukabe Tsumugi <futami16237@gmail.com>
28
+ * @version 2.2.10 (Last Update: 2026.10.12 10:07:47.649)
29
+ * @license MIT
30
+ * @link git+https://github.com/baendlorel/tsumugi-lib.git
31
+ * @link https://baendlorel.github.io/ Welcome to my site!
32
+ * @description Sometimes we need to judge something with multiple cases, but the main job should be done later. So we have Defered Branch!
33
+ * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
34
+ */
35
+ const i=()=>new e,a=()=>new t,o=()=>new r,s=()=>new n
36
+ /**
37
+ * ## Steps to use
38
+ * 1. const a = deferedBranchDynamic()
39
+ * 2. add branches by a.add(condition, branch)
40
+ * 3. add nomatch handler by a.nomatch(handler)
41
+ * 4. call a.predicate(...) to find the matched branch
42
+ * 5. ...run some other logic
43
+ * 6. run this branch by a.run();
44
+ *
45
+ * ## Type Annotation (optional)
46
+ * ```ts
47
+ * type BranchFn = (a: number) => void;
48
+ * type NoMatchFn = () => void;
49
+ * // optional, you can customize the condition function type
50
+ * type ConditionFn = Predicate<BranchFn>;
51
+ * const a = deferedBranch<BranchFn, NoMatchFn, ConditionFn>();
52
+ *
53
+ * // then we have restrictions:
54
+ * a.add(someFn satisfies ConditionFn, secondFn satisfies BranchFn);
55
+ * a.nomatch(thirdFn satisfies NoMatchFn);
56
+ *
57
+ * // some other logic
58
+ *
59
+ * a.predicate(...args);
60
+ *
61
+ * // some other logic
62
+ *
63
+ * a.run(...args); // input args are restricted to Parameters<BranchFn>
64
+ * ```
65
+ *
66
+ * ## About
67
+ * @package DeferedBranch
68
+ * @author Kasukabe Tsumugi <futami16237@gmail.com>
69
+ * @version 2.2.10 (Last Update: 2026.10.12 10:07:47.649)
70
+ * @license MIT
71
+ * @link git+https://github.com/baendlorel/tsumugi-lib.git
72
+ * @link https://baendlorel.github.io/ Welcome to my site!
73
+ * @description Sometimes we need to judge something with multiple cases, but the main job should be done later. So we have Defered Branch!
74
+ * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
75
+ */
76
+ /**
77
+ * ## Steps to use
78
+ * 1. const a = deferedBranchAll()
79
+ * 2. add branches by a.add(condition, branch)
80
+ * 3. (optional) add defered nomatch handler, or add and run at the same time by a.nomatch(handler)
81
+ * 4. ...run some other logic
82
+ * 5. run all matched branches by a.run();
83
+ *
84
+ * ## Type Annotation (optional)
85
+ * ```ts
86
+ * type BranchFn = (a: number) => void;
87
+ * type NoMatchFn = () => void;
88
+ * const a = deferedBranchAll<BranchFn, NoMatchFn>();
89
+ *
90
+ * // then we have restrictions:
91
+ * a.add(true, someFn satisfies BranchFn);
92
+ * a.nomatch(otherFn satisfies NoMatchFn);
93
+ *
94
+ * // some other logic
95
+ *
96
+ * a.run(...args); // input args are restricted to Parameters<BranchFn>
97
+ * ```
98
+ *
99
+ * ## About
100
+ * @package DeferedBranch
101
+ * @author Kasukabe Tsumugi <futami16237@gmail.com>
102
+ * @version 2.2.10 (Last Update: 2026.10.12 10:07:47.649)
103
+ * @license MIT
104
+ * @link git+https://github.com/baendlorel/tsumugi-lib.git
105
+ * @link https://baendlorel.github.io/ Welcome to my site!
106
+ * @description Sometimes we need to judge something with multiple cases, but the main job should be done later. So we have Defered Branch!
107
+ * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
108
+ */
109
+ /**
110
+ * ## Steps to use
111
+ * 1. const a = deferedBranchAllDynamic()
112
+ * 2. add branches by a.add(condition, branch)
113
+ * 3. add nomatch handler by a.nomatch(handler)
114
+ * 4. call a.predicate(...) to find all matched branches
115
+ * 5. ...run some other logic
116
+ * 6. run all matched branches by a.run();
117
+ *
118
+ * ## Type Annotation (optional)
119
+ * ```ts
120
+ * type BranchFn = (a: number) => void;
121
+ * type NoMatchFn = () => void;
122
+ * // optional, you can customize the condition function type
123
+ * type ConditionFn = Predicate<BranchFn>;
124
+ * const a = deferedBranchAllDynamic<BranchFn, NoMatchFn, ConditionFn>();
125
+ *
126
+ * // then we have restrictions:
127
+ * a.add(someFn satisfies ConditionFn, secondFn satisfies BranchFn);
128
+ * a.nomatch(thirdFn satisfies NoMatchFn);
129
+ *
130
+ * // some other logic
131
+ *
132
+ * a.predicate(...args);
133
+ *
134
+ * // some other logic
135
+ *
136
+ * a.run(...args); // input args are restricted to Parameters<BranchFn>
137
+ * ```
138
+ *
139
+ * ## About
140
+ * @package DeferedBranch
141
+ * @author Kasukabe Tsumugi <futami16237@gmail.com>
142
+ * @version 2.2.10 (Last Update: 2026.10.12 10:07:47.649)
143
+ * @license MIT
144
+ * @link git+https://github.com/baendlorel/tsumugi-lib.git
145
+ * @link https://baendlorel.github.io/ Welcome to my site!
146
+ * @description Sometimes we need to judge something with multiple cases, but the main job should be done later. So we have Defered Branch!
147
+ * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
148
+ */
149
+ ;exports.deferedBranch=i,exports.deferedBranchAll=o,exports.deferedBranchAllDynamic=s,exports.deferedBranchDynamic=a;
150
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["DeferedBranch","branch","condition","handler","args","result","DeferedBranchDynamic","len","i","DeferedBranchAllDynamic","DeferedBranchAll","deferedBranch","deferedBranchDynamic","deferedBranchAll","deferedBranchAllDynamic"],"sources":["../src/core/default.ts","../src/core/dynamic.ts","../src/core/all-dynamic.ts","../src/core/all.ts","../src/index.ts"],"sourcesContent":["import { AnyFn } from '@defered-branch/global.js';\n\nexport class DeferedBranch<BranchFn extends AnyFn, NoMatchFn extends AnyFn> {\n private _branch: BranchFn | null = null;\n\n /**\n * Add a new entry\n * - **First truthy first served**.\n * @param condition the condition to match\n * @param branch the branch to run when matched\n * @returns this\n */\n add(condition: boolean, branch: BranchFn): this {\n if (typeof branch !== 'function') {\n throw new TypeError('DeferBranch: branch must be a function');\n }\n\n // & Preventing later branches from overwriting earlier matched branch\n if (condition && !this._branch) {\n this._branch = branch;\n }\n return this;\n }\n\n /**\n * Register a handler to be called when no branch matched\n * - This will be called **instantly and ignores later matched branches**\n * @param handler handle the exhausted case\n * @returns this\n */\n nomatch(handler: NoMatchFn): this {\n if (typeof handler !== 'function') {\n throw new TypeError('DeferBranch: branch must be a function');\n }\n\n if (!this._branch) {\n handler();\n }\n\n return this;\n }\n\n /**\n * Execute the first matched branch in order of addition\n * @param args arguments to pass to the matched branch or nomatch handler\n * @returns the return value of the matched branch or void\n */\n run(...args: Parameters<BranchFn>): ReturnType<BranchFn> | void {\n if (this._branch) {\n const result = this._branch.apply(null, args);\n this._branch = null;\n return result;\n }\n }\n}\n","import { AnyFn, Predicate } from '@defered-branch/global.js';\n\nexport class DeferedBranchDynamic<\n BranchFn extends AnyFn,\n NoMatchFn extends AnyFn,\n ConditionFn extends AnyFn = Predicate<BranchFn>,\n> {\n /**\n * & Compress conditions and branches into a single array since they are paired\n */\n private _condranches: AnyFn[] = [];\n private _branch: BranchFn | null = null;\n private _nomatch: NoMatchFn | null = null;\n\n /**\n * Add a new entry\n * - **First truthy first served**.\n * @param condition the condition to match\n * @param branch the branch to run when matched\n * @returns this\n */\n add(condition: ConditionFn, branch: BranchFn): this {\n if (typeof condition !== 'function') {\n throw new TypeError('DeferBranch: condition must be a function');\n }\n if (typeof branch !== 'function') {\n throw new TypeError('DeferBranch: branch must be a function');\n }\n\n this._condranches.push(condition, branch);\n return this;\n }\n\n /**\n * When calling `this.predicate` and no branch matched, run this handler\n * @param handler handle the exhausted case\n * @returns this\n */\n nomatch(handler: AnyFn): this {\n if (typeof handler !== 'function') {\n throw new TypeError('DeferBranch: handler must be a function');\n }\n\n this._nomatch = handler as NoMatchFn;\n return this;\n }\n\n /**\n * Run the condition to find the first matched branch\n */\n predicate(...args: Parameters<ConditionFn>): void {\n const len = this._condranches.length;\n for (let i = 0; i < len; i += 2) {\n if (this._condranches[i]()) {\n this._branch = this._condranches[i + 1] as BranchFn;\n return;\n }\n }\n\n if (this._nomatch) {\n this._nomatch.apply(this, args);\n }\n }\n\n /**\n * Execute the first matched branch in order of addition\n * @param args arguments to pass to the matched branch\n * @returns the return value of the matched branch or void\n */\n run(...args: Parameters<BranchFn>): ReturnType<BranchFn> | undefined {\n if (this._branch) {\n const result = this._branch.apply(null, args);\n this._branch = null;\n return result;\n }\n }\n}\n","import { AnyFn, Predicate } from '@defered-branch/global.js';\n\nexport class DeferedBranchAllDynamic<\n BranchFn extends AnyFn,\n NoMatchFn extends AnyFn,\n ConditionFn extends AnyFn = Predicate<BranchFn>,\n> {\n /**\n * & Compress conditions and branches into a single array since they are paired\n */\n private _condranches: AnyFn[] = [];\n private _branches: BranchFn[] = [];\n private _nomatch: NoMatchFn | null = null;\n\n /**\n * Add a new entry\n * - **All truthy branches will be executed**.\n * @param condition the condition to match\n * @param branch the branch to run when matched\n * @returns this\n */\n add(condition: ConditionFn, branch: BranchFn): this {\n if (typeof condition !== 'function') {\n throw new TypeError('DeferBranch: condition must be a function');\n }\n if (typeof branch !== 'function') {\n throw new TypeError('DeferBranch: branch must be a function');\n }\n\n this._condranches.push(condition, branch);\n return this;\n }\n\n /**\n * When calling `this.predicate` and no branch matched, run this handler\n * @param handler handle the exhausted case\n * @returns this\n */\n nomatch(handler: AnyFn): this {\n if (typeof handler !== 'function') {\n throw new TypeError('DeferBranch: handler must be a function');\n }\n\n this._nomatch = handler as NoMatchFn;\n return this;\n }\n\n /**\n * Run the conditions to find all matched branches\n */\n predicate(...args: Parameters<ConditionFn>): void {\n const len = this._condranches.length;\n for (let i = 0; i < len; i += 2) {\n if (this._condranches[i]()) {\n this._branches.push(this._condranches[i + 1] as BranchFn);\n }\n }\n\n if (this._nomatch && this._branches.length === 0) {\n this._nomatch.apply(this, args);\n }\n }\n\n /**\n * Execute all matched branches in order of addition\n * @param args arguments to pass to the matched branches\n */\n run(...args: Parameters<BranchFn>): ReturnType<BranchFn> | undefined {\n const len = this._branches.length;\n if (len === 0) {\n return;\n }\n for (let i = 0; i < len; i++) {\n this._branches[i].apply(null, args);\n }\n this._branches.length = 0;\n }\n}\n","import { AnyFn } from '@defered-branch/global.js';\n\nexport class DeferedBranchAll<BranchFn extends AnyFn, NoMatchFn extends AnyFn> {\n private _branches: BranchFn[] = [];\n\n /**\n * Add a new entry\n * - **All truthy branches will be executed**.\n * @param condition the condition to match\n * @param branch the branch to run when matched\n * @returns this\n */\n add(condition: boolean, branch: BranchFn): this {\n if (typeof branch !== 'function') {\n throw new TypeError('DeferBranch: branch must be a function');\n }\n\n // & Preventing later branches from overwriting earlier matched branch\n if (condition) {\n this._branches.push(branch);\n }\n return this;\n }\n\n /**\n * Register a handler to be called when no branch matched\n * - This will be called **instantly and ignores later matched branches**\n * @param handler handle the exhausted case\n * @returns this\n */\n nomatch(handler: NoMatchFn): this {\n if (typeof handler !== 'function') {\n throw new TypeError('DeferBranch: branch must be a function');\n }\n\n if (this._branches.length === 0) {\n handler();\n }\n\n return this;\n }\n\n /**\n * Execute all matched branches in order of addition\n * @param args arguments to pass to the matched branch or nomatch handler\n */\n run(...args: Parameters<BranchFn>): void {\n const len = this._branches.length;\n if (len === 0) {\n return;\n }\n for (let i = 0; i < len; i++) {\n this._branches[i].apply(null, args);\n }\n this._branches.length = 0;\n }\n}\n","import { DeferedBranch } from './core/default.js';\nimport { DeferedBranchDynamic } from './core/dynamic.js';\nimport { DeferedBranchAllDynamic } from './core/all-dynamic.js';\nimport { DeferedBranchAll } from './core/all.js';\nimport { AnyFn, Predicate } from './global.js';\n\n/**\n * ## Steps to use\n * 1. const a = deferedBranch()\n * 2. add branches by a.add(condition, branch)\n * 3. (optional) add defered nomatch handler, or add and run at the same time by a.nomatch(handler)\n * 4. ...run some other logic\n * 5. run this branch by a.run();\n *\n * ## Type Annotation (optional)\n * ```ts\n * type BranchFn = (a: number) => void;\n * type NoMatchFn = () => void;\n * const a = deferedBranch<BranchFn, NoMatchFn>();\n *\n * // then we have restrictions:\n * a.add(true, someFn satisfies BranchFn);\n * a.nomatch(otherFn satisfies NoMatchFn);\n *\n * // some other logic\n *\n * a.run(...args); // input args are restricted to Parameters<BranchFn>\n * ```\n *\n * __PKG_INFO__\n */\nexport const deferedBranch = <BranchFn extends AnyFn = AnyFn, NoMatchFn extends AnyFn = AnyFn>() =>\n new DeferedBranch<BranchFn, NoMatchFn>();\n\n/**\n * ## Steps to use\n * 1. const a = deferedBranchDynamic()\n * 2. add branches by a.add(condition, branch)\n * 3. add nomatch handler by a.nomatch(handler)\n * 4. call a.predicate(...) to find the matched branch\n * 5. ...run some other logic\n * 6. run this branch by a.run();\n *\n * ## Type Annotation (optional)\n * ```ts\n * type BranchFn = (a: number) => void;\n * type NoMatchFn = () => void;\n * // optional, you can customize the condition function type\n * type ConditionFn = Predicate<BranchFn>;\n * const a = deferedBranch<BranchFn, NoMatchFn, ConditionFn>();\n *\n * // then we have restrictions:\n * a.add(someFn satisfies ConditionFn, secondFn satisfies BranchFn);\n * a.nomatch(thirdFn satisfies NoMatchFn);\n *\n * // some other logic\n *\n * a.predicate(...args);\n *\n * // some other logic\n *\n * a.run(...args); // input args are restricted to Parameters<BranchFn>\n * ```\n *\n * __PKG_INFO__\n */\nexport const deferedBranchDynamic = <\n BranchFn extends AnyFn = AnyFn,\n NoMatchFn extends AnyFn = AnyFn,\n ConditionFn extends AnyFn = Predicate<BranchFn>,\n>() => new DeferedBranchDynamic<BranchFn, NoMatchFn, ConditionFn>();\n\n/**\n * ## Steps to use\n * 1. const a = deferedBranchAll()\n * 2. add branches by a.add(condition, branch)\n * 3. (optional) add defered nomatch handler, or add and run at the same time by a.nomatch(handler)\n * 4. ...run some other logic\n * 5. run all matched branches by a.run();\n *\n * ## Type Annotation (optional)\n * ```ts\n * type BranchFn = (a: number) => void;\n * type NoMatchFn = () => void;\n * const a = deferedBranchAll<BranchFn, NoMatchFn>();\n *\n * // then we have restrictions:\n * a.add(true, someFn satisfies BranchFn);\n * a.nomatch(otherFn satisfies NoMatchFn);\n *\n * // some other logic\n *\n * a.run(...args); // input args are restricted to Parameters<BranchFn>\n * ```\n *\n * __PKG_INFO__\n */\nexport const deferedBranchAll = <BranchFn extends AnyFn = AnyFn, NoMatchFn extends AnyFn = AnyFn>() =>\n new DeferedBranchAll<BranchFn, NoMatchFn>();\n\n/**\n * ## Steps to use\n * 1. const a = deferedBranchAllDynamic()\n * 2. add branches by a.add(condition, branch)\n * 3. add nomatch handler by a.nomatch(handler)\n * 4. call a.predicate(...) to find all matched branches\n * 5. ...run some other logic\n * 6. run all matched branches by a.run();\n *\n * ## Type Annotation (optional)\n * ```ts\n * type BranchFn = (a: number) => void;\n * type NoMatchFn = () => void;\n * // optional, you can customize the condition function type\n * type ConditionFn = Predicate<BranchFn>;\n * const a = deferedBranchAllDynamic<BranchFn, NoMatchFn, ConditionFn>();\n *\n * // then we have restrictions:\n * a.add(someFn satisfies ConditionFn, secondFn satisfies BranchFn);\n * a.nomatch(thirdFn satisfies NoMatchFn);\n *\n * // some other logic\n *\n * a.predicate(...args);\n *\n * // some other logic\n *\n * a.run(...args); // input args are restricted to Parameters<BranchFn>\n * ```\n *\n * __PKG_INFO__\n */\nexport const deferedBranchAllDynamic = <\n BranchFn extends AnyFn = AnyFn,\n NoMatchFn extends AnyFn = AnyFn,\n ConditionFn extends AnyFn = Predicate<BranchFn>,\n>() => new DeferedBranchAllDynamic<BranchFn, NoMatchFn, ConditionFn>();\n"],"mappings":"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"}
@@ -0,0 +1,244 @@
1
+ //#region src/global.d.ts
2
+ type AnyFn = (...args: any[]) => any;
3
+ type Predicate<Fn extends AnyFn> = (...args: Parameters<Fn>) => boolean;
4
+ //#endregion
5
+ //#region src/core/default.d.ts
6
+ declare class DeferedBranch<BranchFn extends AnyFn, NoMatchFn extends AnyFn> {
7
+ private _branch;
8
+ /**
9
+ * Add a new entry
10
+ * - **First truthy first served**.
11
+ * @param condition the condition to match
12
+ * @param branch the branch to run when matched
13
+ * @returns this
14
+ */
15
+ add(condition: boolean, branch: BranchFn): this;
16
+ /**
17
+ * Register a handler to be called when no branch matched
18
+ * - This will be called **instantly and ignores later matched branches**
19
+ * @param handler handle the exhausted case
20
+ * @returns this
21
+ */
22
+ nomatch(handler: NoMatchFn): this;
23
+ /**
24
+ * Execute the first matched branch in order of addition
25
+ * @param args arguments to pass to the matched branch or nomatch handler
26
+ * @returns the return value of the matched branch or void
27
+ */
28
+ run(...args: Parameters<BranchFn>): ReturnType<BranchFn> | void;
29
+ }
30
+ //#endregion
31
+ //#region src/core/dynamic.d.ts
32
+ declare class DeferedBranchDynamic<BranchFn extends AnyFn, NoMatchFn extends AnyFn, ConditionFn extends AnyFn = Predicate<BranchFn>> {
33
+ /**
34
+ * & Compress conditions and branches into a single array since they are paired
35
+ */
36
+ private _condranches;
37
+ private _branch;
38
+ private _nomatch;
39
+ /**
40
+ * Add a new entry
41
+ * - **First truthy first served**.
42
+ * @param condition the condition to match
43
+ * @param branch the branch to run when matched
44
+ * @returns this
45
+ */
46
+ add(condition: ConditionFn, branch: BranchFn): this;
47
+ /**
48
+ * When calling `this.predicate` and no branch matched, run this handler
49
+ * @param handler handle the exhausted case
50
+ * @returns this
51
+ */
52
+ nomatch(handler: AnyFn): this;
53
+ /**
54
+ * Run the condition to find the first matched branch
55
+ */
56
+ predicate(...args: Parameters<ConditionFn>): void;
57
+ /**
58
+ * Execute the first matched branch in order of addition
59
+ * @param args arguments to pass to the matched branch
60
+ * @returns the return value of the matched branch or void
61
+ */
62
+ run(...args: Parameters<BranchFn>): ReturnType<BranchFn> | undefined;
63
+ }
64
+ //#endregion
65
+ //#region src/core/all-dynamic.d.ts
66
+ declare class DeferedBranchAllDynamic<BranchFn extends AnyFn, NoMatchFn extends AnyFn, ConditionFn extends AnyFn = Predicate<BranchFn>> {
67
+ /**
68
+ * & Compress conditions and branches into a single array since they are paired
69
+ */
70
+ private _condranches;
71
+ private _branches;
72
+ private _nomatch;
73
+ /**
74
+ * Add a new entry
75
+ * - **All truthy branches will be executed**.
76
+ * @param condition the condition to match
77
+ * @param branch the branch to run when matched
78
+ * @returns this
79
+ */
80
+ add(condition: ConditionFn, branch: BranchFn): this;
81
+ /**
82
+ * When calling `this.predicate` and no branch matched, run this handler
83
+ * @param handler handle the exhausted case
84
+ * @returns this
85
+ */
86
+ nomatch(handler: AnyFn): this;
87
+ /**
88
+ * Run the conditions to find all matched branches
89
+ */
90
+ predicate(...args: Parameters<ConditionFn>): void;
91
+ /**
92
+ * Execute all matched branches in order of addition
93
+ * @param args arguments to pass to the matched branches
94
+ */
95
+ run(...args: Parameters<BranchFn>): ReturnType<BranchFn> | undefined;
96
+ }
97
+ //#endregion
98
+ //#region src/core/all.d.ts
99
+ declare class DeferedBranchAll<BranchFn extends AnyFn, NoMatchFn extends AnyFn> {
100
+ private _branches;
101
+ /**
102
+ * Add a new entry
103
+ * - **All truthy branches will be executed**.
104
+ * @param condition the condition to match
105
+ * @param branch the branch to run when matched
106
+ * @returns this
107
+ */
108
+ add(condition: boolean, branch: BranchFn): this;
109
+ /**
110
+ * Register a handler to be called when no branch matched
111
+ * - This will be called **instantly and ignores later matched branches**
112
+ * @param handler handle the exhausted case
113
+ * @returns this
114
+ */
115
+ nomatch(handler: NoMatchFn): this;
116
+ /**
117
+ * Execute all matched branches in order of addition
118
+ * @param args arguments to pass to the matched branch or nomatch handler
119
+ */
120
+ run(...args: Parameters<BranchFn>): void;
121
+ }
122
+ //#endregion
123
+ //#region src/index.d.ts
124
+ /**
125
+ * ## Steps to use
126
+ * 1. const a = deferedBranch()
127
+ * 2. add branches by a.add(condition, branch)
128
+ * 3. (optional) add defered nomatch handler, or add and run at the same time by a.nomatch(handler)
129
+ * 4. ...run some other logic
130
+ * 5. run this branch by a.run();
131
+ *
132
+ * ## Type Annotation (optional)
133
+ * ```ts
134
+ * type BranchFn = (a: number) => void;
135
+ * type NoMatchFn = () => void;
136
+ * const a = deferedBranch<BranchFn, NoMatchFn>();
137
+ *
138
+ * // then we have restrictions:
139
+ * a.add(true, someFn satisfies BranchFn);
140
+ * a.nomatch(otherFn satisfies NoMatchFn);
141
+ *
142
+ * // some other logic
143
+ *
144
+ * a.run(...args); // input args are restricted to Parameters<BranchFn>
145
+ * ```
146
+ *
147
+ * __PKG_INFO__
148
+ */
149
+ declare const deferedBranch: <BranchFn extends AnyFn = AnyFn, NoMatchFn extends AnyFn = AnyFn>() => DeferedBranch<BranchFn, NoMatchFn>;
150
+ /**
151
+ * ## Steps to use
152
+ * 1. const a = deferedBranchDynamic()
153
+ * 2. add branches by a.add(condition, branch)
154
+ * 3. add nomatch handler by a.nomatch(handler)
155
+ * 4. call a.predicate(...) to find the matched branch
156
+ * 5. ...run some other logic
157
+ * 6. run this branch by a.run();
158
+ *
159
+ * ## Type Annotation (optional)
160
+ * ```ts
161
+ * type BranchFn = (a: number) => void;
162
+ * type NoMatchFn = () => void;
163
+ * // optional, you can customize the condition function type
164
+ * type ConditionFn = Predicate<BranchFn>;
165
+ * const a = deferedBranch<BranchFn, NoMatchFn, ConditionFn>();
166
+ *
167
+ * // then we have restrictions:
168
+ * a.add(someFn satisfies ConditionFn, secondFn satisfies BranchFn);
169
+ * a.nomatch(thirdFn satisfies NoMatchFn);
170
+ *
171
+ * // some other logic
172
+ *
173
+ * a.predicate(...args);
174
+ *
175
+ * // some other logic
176
+ *
177
+ * a.run(...args); // input args are restricted to Parameters<BranchFn>
178
+ * ```
179
+ *
180
+ * __PKG_INFO__
181
+ */
182
+ declare const deferedBranchDynamic: <BranchFn extends AnyFn = AnyFn, NoMatchFn extends AnyFn = AnyFn, ConditionFn extends AnyFn = Predicate<BranchFn>>() => DeferedBranchDynamic<BranchFn, NoMatchFn, ConditionFn>;
183
+ /**
184
+ * ## Steps to use
185
+ * 1. const a = deferedBranchAll()
186
+ * 2. add branches by a.add(condition, branch)
187
+ * 3. (optional) add defered nomatch handler, or add and run at the same time by a.nomatch(handler)
188
+ * 4. ...run some other logic
189
+ * 5. run all matched branches by a.run();
190
+ *
191
+ * ## Type Annotation (optional)
192
+ * ```ts
193
+ * type BranchFn = (a: number) => void;
194
+ * type NoMatchFn = () => void;
195
+ * const a = deferedBranchAll<BranchFn, NoMatchFn>();
196
+ *
197
+ * // then we have restrictions:
198
+ * a.add(true, someFn satisfies BranchFn);
199
+ * a.nomatch(otherFn satisfies NoMatchFn);
200
+ *
201
+ * // some other logic
202
+ *
203
+ * a.run(...args); // input args are restricted to Parameters<BranchFn>
204
+ * ```
205
+ *
206
+ * __PKG_INFO__
207
+ */
208
+ declare const deferedBranchAll: <BranchFn extends AnyFn = AnyFn, NoMatchFn extends AnyFn = AnyFn>() => DeferedBranchAll<BranchFn, NoMatchFn>;
209
+ /**
210
+ * ## Steps to use
211
+ * 1. const a = deferedBranchAllDynamic()
212
+ * 2. add branches by a.add(condition, branch)
213
+ * 3. add nomatch handler by a.nomatch(handler)
214
+ * 4. call a.predicate(...) to find all matched branches
215
+ * 5. ...run some other logic
216
+ * 6. run all matched branches by a.run();
217
+ *
218
+ * ## Type Annotation (optional)
219
+ * ```ts
220
+ * type BranchFn = (a: number) => void;
221
+ * type NoMatchFn = () => void;
222
+ * // optional, you can customize the condition function type
223
+ * type ConditionFn = Predicate<BranchFn>;
224
+ * const a = deferedBranchAllDynamic<BranchFn, NoMatchFn, ConditionFn>();
225
+ *
226
+ * // then we have restrictions:
227
+ * a.add(someFn satisfies ConditionFn, secondFn satisfies BranchFn);
228
+ * a.nomatch(thirdFn satisfies NoMatchFn);
229
+ *
230
+ * // some other logic
231
+ *
232
+ * a.predicate(...args);
233
+ *
234
+ * // some other logic
235
+ *
236
+ * a.run(...args); // input args are restricted to Parameters<BranchFn>
237
+ * ```
238
+ *
239
+ * __PKG_INFO__
240
+ */
241
+ declare const deferedBranchAllDynamic: <BranchFn extends AnyFn = AnyFn, NoMatchFn extends AnyFn = AnyFn, ConditionFn extends AnyFn = Predicate<BranchFn>>() => DeferedBranchAllDynamic<BranchFn, NoMatchFn, ConditionFn>;
242
+ //#endregion
243
+ export { deferedBranch, deferedBranchAll, deferedBranchAllDynamic, deferedBranchDynamic };
244
+ //# sourceMappingURL=index.d.cts.map
@@ -1,120 +1,126 @@
1
+ //#region src/global.d.ts
1
2
  type AnyFn = (...args: any[]) => any;
2
3
  type Predicate<Fn extends AnyFn> = (...args: Parameters<Fn>) => boolean;
3
-
4
+ //#endregion
5
+ //#region src/core/default.d.ts
4
6
  declare class DeferedBranch<BranchFn extends AnyFn, NoMatchFn extends AnyFn> {
5
- private _branch;
6
- /**
7
- * Add a new entry
8
- * - **First truthy first served**.
9
- * @param condition the condition to match
10
- * @param branch the branch to run when matched
11
- * @returns this
12
- */
13
- add(condition: boolean, branch: BranchFn): this;
14
- /**
15
- * Register a handler to be called when no branch matched
16
- * - This will be called **instantly and ignores later matched branches**
17
- * @param handler handle the exhausted case
18
- * @returns this
19
- */
20
- nomatch(handler: NoMatchFn): this;
21
- /**
22
- * Execute the first matched branch in order of addition
23
- * @param args arguments to pass to the matched branch or nomatch handler
24
- * @returns the return value of the matched branch or void
25
- */
26
- run(...args: Parameters<BranchFn>): ReturnType<BranchFn> | void;
7
+ private _branch;
8
+ /**
9
+ * Add a new entry
10
+ * - **First truthy first served**.
11
+ * @param condition the condition to match
12
+ * @param branch the branch to run when matched
13
+ * @returns this
14
+ */
15
+ add(condition: boolean, branch: BranchFn): this;
16
+ /**
17
+ * Register a handler to be called when no branch matched
18
+ * - This will be called **instantly and ignores later matched branches**
19
+ * @param handler handle the exhausted case
20
+ * @returns this
21
+ */
22
+ nomatch(handler: NoMatchFn): this;
23
+ /**
24
+ * Execute the first matched branch in order of addition
25
+ * @param args arguments to pass to the matched branch or nomatch handler
26
+ * @returns the return value of the matched branch or void
27
+ */
28
+ run(...args: Parameters<BranchFn>): ReturnType<BranchFn> | void;
27
29
  }
28
-
30
+ //#endregion
31
+ //#region src/core/dynamic.d.ts
29
32
  declare class DeferedBranchDynamic<BranchFn extends AnyFn, NoMatchFn extends AnyFn, ConditionFn extends AnyFn = Predicate<BranchFn>> {
30
- /**
31
- * & Compress conditions and branches into a single array since they are paired
32
- */
33
- private _condranches;
34
- private _branch;
35
- private _nomatch;
36
- /**
37
- * Add a new entry
38
- * - **First truthy first served**.
39
- * @param condition the condition to match
40
- * @param branch the branch to run when matched
41
- * @returns this
42
- */
43
- add(condition: ConditionFn, branch: BranchFn): this;
44
- /**
45
- * When calling `this.predicate` and no branch matched, run this handler
46
- * @param handler handle the exhausted case
47
- * @returns this
48
- */
49
- nomatch(handler: AnyFn): this;
50
- /**
51
- * Run the condition to find the first matched branch
52
- */
53
- predicate(...args: Parameters<ConditionFn>): void;
54
- /**
55
- * Execute the first matched branch in order of addition
56
- * @param args arguments to pass to the matched branch
57
- * @returns the return value of the matched branch or void
58
- */
59
- run(...args: Parameters<BranchFn>): ReturnType<BranchFn> | undefined;
33
+ /**
34
+ * & Compress conditions and branches into a single array since they are paired
35
+ */
36
+ private _condranches;
37
+ private _branch;
38
+ private _nomatch;
39
+ /**
40
+ * Add a new entry
41
+ * - **First truthy first served**.
42
+ * @param condition the condition to match
43
+ * @param branch the branch to run when matched
44
+ * @returns this
45
+ */
46
+ add(condition: ConditionFn, branch: BranchFn): this;
47
+ /**
48
+ * When calling `this.predicate` and no branch matched, run this handler
49
+ * @param handler handle the exhausted case
50
+ * @returns this
51
+ */
52
+ nomatch(handler: AnyFn): this;
53
+ /**
54
+ * Run the condition to find the first matched branch
55
+ */
56
+ predicate(...args: Parameters<ConditionFn>): void;
57
+ /**
58
+ * Execute the first matched branch in order of addition
59
+ * @param args arguments to pass to the matched branch
60
+ * @returns the return value of the matched branch or void
61
+ */
62
+ run(...args: Parameters<BranchFn>): ReturnType<BranchFn> | undefined;
60
63
  }
61
-
64
+ //#endregion
65
+ //#region src/core/all-dynamic.d.ts
62
66
  declare class DeferedBranchAllDynamic<BranchFn extends AnyFn, NoMatchFn extends AnyFn, ConditionFn extends AnyFn = Predicate<BranchFn>> {
63
- /**
64
- * & Compress conditions and branches into a single array since they are paired
65
- */
66
- private _condranches;
67
- private _branches;
68
- private _nomatch;
69
- /**
70
- * Add a new entry
71
- * - **All truthy branches will be executed**.
72
- * @param condition the condition to match
73
- * @param branch the branch to run when matched
74
- * @returns this
75
- */
76
- add(condition: ConditionFn, branch: BranchFn): this;
77
- /**
78
- * When calling `this.predicate` and no branch matched, run this handler
79
- * @param handler handle the exhausted case
80
- * @returns this
81
- */
82
- nomatch(handler: AnyFn): this;
83
- /**
84
- * Run the conditions to find all matched branches
85
- */
86
- predicate(...args: Parameters<ConditionFn>): void;
87
- /**
88
- * Execute all matched branches in order of addition
89
- * @param args arguments to pass to the matched branches
90
- */
91
- run(...args: Parameters<BranchFn>): ReturnType<BranchFn> | undefined;
67
+ /**
68
+ * & Compress conditions and branches into a single array since they are paired
69
+ */
70
+ private _condranches;
71
+ private _branches;
72
+ private _nomatch;
73
+ /**
74
+ * Add a new entry
75
+ * - **All truthy branches will be executed**.
76
+ * @param condition the condition to match
77
+ * @param branch the branch to run when matched
78
+ * @returns this
79
+ */
80
+ add(condition: ConditionFn, branch: BranchFn): this;
81
+ /**
82
+ * When calling `this.predicate` and no branch matched, run this handler
83
+ * @param handler handle the exhausted case
84
+ * @returns this
85
+ */
86
+ nomatch(handler: AnyFn): this;
87
+ /**
88
+ * Run the conditions to find all matched branches
89
+ */
90
+ predicate(...args: Parameters<ConditionFn>): void;
91
+ /**
92
+ * Execute all matched branches in order of addition
93
+ * @param args arguments to pass to the matched branches
94
+ */
95
+ run(...args: Parameters<BranchFn>): ReturnType<BranchFn> | undefined;
92
96
  }
93
-
97
+ //#endregion
98
+ //#region src/core/all.d.ts
94
99
  declare class DeferedBranchAll<BranchFn extends AnyFn, NoMatchFn extends AnyFn> {
95
- private _branches;
96
- /**
97
- * Add a new entry
98
- * - **All truthy branches will be executed**.
99
- * @param condition the condition to match
100
- * @param branch the branch to run when matched
101
- * @returns this
102
- */
103
- add(condition: boolean, branch: BranchFn): this;
104
- /**
105
- * Register a handler to be called when no branch matched
106
- * - This will be called **instantly and ignores later matched branches**
107
- * @param handler handle the exhausted case
108
- * @returns this
109
- */
110
- nomatch(handler: NoMatchFn): this;
111
- /**
112
- * Execute all matched branches in order of addition
113
- * @param args arguments to pass to the matched branch or nomatch handler
114
- */
115
- run(...args: Parameters<BranchFn>): void;
100
+ private _branches;
101
+ /**
102
+ * Add a new entry
103
+ * - **All truthy branches will be executed**.
104
+ * @param condition the condition to match
105
+ * @param branch the branch to run when matched
106
+ * @returns this
107
+ */
108
+ add(condition: boolean, branch: BranchFn): this;
109
+ /**
110
+ * Register a handler to be called when no branch matched
111
+ * - This will be called **instantly and ignores later matched branches**
112
+ * @param handler handle the exhausted case
113
+ * @returns this
114
+ */
115
+ nomatch(handler: NoMatchFn): this;
116
+ /**
117
+ * Execute all matched branches in order of addition
118
+ * @param args arguments to pass to the matched branch or nomatch handler
119
+ */
120
+ run(...args: Parameters<BranchFn>): void;
116
121
  }
117
-
122
+ //#endregion
123
+ //#region src/index.d.ts
118
124
  /**
119
125
  * ## Steps to use
120
126
  * 1. const a = deferedBranch()
@@ -141,9 +147,9 @@ declare class DeferedBranchAll<BranchFn extends AnyFn, NoMatchFn extends AnyFn>
141
147
  * ## About
142
148
  * @package DeferedBranch
143
149
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
144
- * @version 2.2.8 (Last Update: 2026.02.17 18:50:28.466)
150
+ * @version 2.2.10 (Last Update: 2026.10.12 10:07:47.649)
145
151
  * @license MIT
146
- * @link git+https://github.com/baendlorel/kt-packages.git
152
+ * @link git+https://github.com/baendlorel/tsumugi-lib.git
147
153
  * @link https://baendlorel.github.io/ Welcome to my site!
148
154
  * @description Sometimes we need to judge something with multiple cases, but the main job should be done later. So we have Defered Branch!
149
155
  * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
@@ -182,9 +188,9 @@ declare const deferedBranch: <BranchFn extends AnyFn = AnyFn, NoMatchFn extends
182
188
  * ## About
183
189
  * @package DeferedBranch
184
190
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
185
- * @version 2.2.8 (Last Update: 2026.02.17 18:50:28.466)
191
+ * @version 2.2.10 (Last Update: 2026.10.12 10:07:47.649)
186
192
  * @license MIT
187
- * @link git+https://github.com/baendlorel/kt-packages.git
193
+ * @link git+https://github.com/baendlorel/tsumugi-lib.git
188
194
  * @link https://baendlorel.github.io/ Welcome to my site!
189
195
  * @description Sometimes we need to judge something with multiple cases, but the main job should be done later. So we have Defered Branch!
190
196
  * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
@@ -216,9 +222,9 @@ declare const deferedBranchDynamic: <BranchFn extends AnyFn = AnyFn, NoMatchFn e
216
222
  * ## About
217
223
  * @package DeferedBranch
218
224
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
219
- * @version 2.2.8 (Last Update: 2026.02.17 18:50:28.466)
225
+ * @version 2.2.10 (Last Update: 2026.10.12 10:07:47.649)
220
226
  * @license MIT
221
- * @link git+https://github.com/baendlorel/kt-packages.git
227
+ * @link git+https://github.com/baendlorel/tsumugi-lib.git
222
228
  * @link https://baendlorel.github.io/ Welcome to my site!
223
229
  * @description Sometimes we need to judge something with multiple cases, but the main job should be done later. So we have Defered Branch!
224
230
  * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
@@ -257,13 +263,14 @@ declare const deferedBranchAll: <BranchFn extends AnyFn = AnyFn, NoMatchFn exten
257
263
  * ## About
258
264
  * @package DeferedBranch
259
265
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
260
- * @version 2.2.8 (Last Update: 2026.02.17 18:50:28.466)
266
+ * @version 2.2.10 (Last Update: 2026.10.12 10:07:47.649)
261
267
  * @license MIT
262
- * @link git+https://github.com/baendlorel/kt-packages.git
268
+ * @link git+https://github.com/baendlorel/tsumugi-lib.git
263
269
  * @link https://baendlorel.github.io/ Welcome to my site!
264
270
  * @description Sometimes we need to judge something with multiple cases, but the main job should be done later. So we have Defered Branch!
265
271
  * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
266
272
  */
267
273
  declare const deferedBranchAllDynamic: <BranchFn extends AnyFn = AnyFn, NoMatchFn extends AnyFn = AnyFn, ConditionFn extends AnyFn = Predicate<BranchFn>>() => DeferedBranchAllDynamic<BranchFn, NoMatchFn, ConditionFn>;
268
-
274
+ //#endregion
269
275
  export { deferedBranch, deferedBranchAll, deferedBranchAllDynamic, deferedBranchDynamic };
276
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -1,93 +1,150 @@
1
- class t {
2
- t=null;
3
- add(t, n) {
4
- if ("function" != typeof n) throw new TypeError("DeferBranch: branch must be a function");
5
- return t && !this.t && (this.t = n), this;
6
- }
7
- nomatch(t) {
8
- if ("function" != typeof t) throw new TypeError("DeferBranch: branch must be a function");
9
- return this.t || t(), this;
10
- }
11
- run(...t) {
12
- if (this.t) {
13
- const n = this.t.apply(null, t);
14
- return this.t = null, n;
15
- }
16
- }
17
- }
18
-
19
- class n {
20
- i=[];
21
- t=null;
22
- h=null;
23
- add(t, n) {
24
- if ("function" != typeof t) throw new TypeError("DeferBranch: condition must be a function");
25
- if ("function" != typeof n) throw new TypeError("DeferBranch: branch must be a function");
26
- return this.i.push(t, n), this;
27
- }
28
- nomatch(t) {
29
- if ("function" != typeof t) throw new TypeError("DeferBranch: handler must be a function");
30
- return this.h = t, this;
31
- }
32
- predicate(...t) {
33
- const n = this.i.length;
34
- for (let t = 0; t < n; t += 2) if (this.i[t]()) return void (this.t = this.i[t + 1]);
35
- this.h && this.h.apply(this, t);
36
- }
37
- run(...t) {
38
- if (this.t) {
39
- const n = this.t.apply(null, t);
40
- return this.t = null, n;
41
- }
42
- }
43
- }
44
-
45
- class r {
46
- i=[];
47
- o=[];
48
- h=null;
49
- add(t, n) {
50
- if ("function" != typeof t) throw new TypeError("DeferBranch: condition must be a function");
51
- if ("function" != typeof n) throw new TypeError("DeferBranch: branch must be a function");
52
- return this.i.push(t, n), this;
53
- }
54
- nomatch(t) {
55
- if ("function" != typeof t) throw new TypeError("DeferBranch: handler must be a function");
56
- return this.h = t, this;
57
- }
58
- predicate(...t) {
59
- const n = this.i.length;
60
- for (let t = 0; t < n; t += 2) this.i[t]() && this.o.push(this.i[t + 1]);
61
- this.h && 0 === this.o.length && this.h.apply(this, t);
62
- }
63
- run(...t) {
64
- const n = this.o.length;
65
- if (0 !== n) {
66
- for (let r = 0; r < n; r++) this.o[r].apply(null, t);
67
- this.o.length = 0;
68
- }
69
- }
70
- }
71
-
72
- class e {
73
- o=[];
74
- add(t, n) {
75
- if ("function" != typeof n) throw new TypeError("DeferBranch: branch must be a function");
76
- return t && this.o.push(n), this;
77
- }
78
- nomatch(t) {
79
- if ("function" != typeof t) throw new TypeError("DeferBranch: branch must be a function");
80
- return 0 === this.o.length && t(), this;
81
- }
82
- run(...t) {
83
- const n = this.o.length;
84
- if (0 !== n) {
85
- for (let r = 0; r < n; r++) this.o[r].apply(null, t);
86
- this.o.length = 0;
87
- }
88
- }
89
- }
90
-
91
- const i = () => new t, h = () => new n, o = () => new e, s = () => new r;
92
-
93
- export { i as deferedBranch, o as deferedBranchAll, s as deferedBranchAllDynamic, h as deferedBranchDynamic };
1
+ var e=class{_branch=null;add(e,t){if(typeof t!=`function`)throw TypeError(`DeferBranch: branch must be a function`);return e&&!this._branch&&(this._branch=t),this}nomatch(e){if(typeof e!=`function`)throw TypeError(`DeferBranch: branch must be a function`);return this._branch||e(),this}run(...e){if(this._branch){let t=this._branch.apply(null,e);return this._branch=null,t}}},t=class{_condranches=[];_branch=null;_nomatch=null;add(e,t){if(typeof e!=`function`)throw TypeError(`DeferBranch: condition must be a function`);if(typeof t!=`function`)throw TypeError(`DeferBranch: branch must be a function`);return this._condranches.push(e,t),this}nomatch(e){if(typeof e!=`function`)throw TypeError(`DeferBranch: handler must be a function`);return this._nomatch=e,this}predicate(...e){let t=this._condranches.length;for(let e=0;e<t;e+=2)if(this._condranches[e]()){this._branch=this._condranches[e+1];return}this._nomatch&&this._nomatch.apply(this,e)}run(...e){if(this._branch){let t=this._branch.apply(null,e);return this._branch=null,t}}},n=class{_condranches=[];_branches=[];_nomatch=null;add(e,t){if(typeof e!=`function`)throw TypeError(`DeferBranch: condition must be a function`);if(typeof t!=`function`)throw TypeError(`DeferBranch: branch must be a function`);return this._condranches.push(e,t),this}nomatch(e){if(typeof e!=`function`)throw TypeError(`DeferBranch: handler must be a function`);return this._nomatch=e,this}predicate(...e){let t=this._condranches.length;for(let e=0;e<t;e+=2)this._condranches[e]()&&this._branches.push(this._condranches[e+1]);this._nomatch&&this._branches.length===0&&this._nomatch.apply(this,e)}run(...e){let t=this._branches.length;if(t!==0){for(let n=0;n<t;n++)this._branches[n].apply(null,e);this._branches.length=0}}},r=class{_branches=[];add(e,t){if(typeof t!=`function`)throw TypeError(`DeferBranch: branch must be a function`);return e&&this._branches.push(t),this}nomatch(e){if(typeof e!=`function`)throw TypeError(`DeferBranch: branch must be a function`);return this._branches.length===0&&e(),this}run(...e){let t=this._branches.length;if(t!==0){for(let n=0;n<t;n++)this._branches[n].apply(null,e);this._branches.length=0}}};
2
+ /**
3
+ * ## Steps to use
4
+ * 1. const a = deferedBranch()
5
+ * 2. add branches by a.add(condition, branch)
6
+ * 3. (optional) add defered nomatch handler, or add and run at the same time by a.nomatch(handler)
7
+ * 4. ...run some other logic
8
+ * 5. run this branch by a.run();
9
+ *
10
+ * ## Type Annotation (optional)
11
+ * ```ts
12
+ * type BranchFn = (a: number) => void;
13
+ * type NoMatchFn = () => void;
14
+ * const a = deferedBranch<BranchFn, NoMatchFn>();
15
+ *
16
+ * // then we have restrictions:
17
+ * a.add(true, someFn satisfies BranchFn);
18
+ * a.nomatch(otherFn satisfies NoMatchFn);
19
+ *
20
+ * // some other logic
21
+ *
22
+ * a.run(...args); // input args are restricted to Parameters<BranchFn>
23
+ * ```
24
+ *
25
+ * ## About
26
+ * @package DeferedBranch
27
+ * @author Kasukabe Tsumugi <futami16237@gmail.com>
28
+ * @version 2.2.10 (Last Update: 2026.10.12 10:07:47.649)
29
+ * @license MIT
30
+ * @link git+https://github.com/baendlorel/tsumugi-lib.git
31
+ * @link https://baendlorel.github.io/ Welcome to my site!
32
+ * @description Sometimes we need to judge something with multiple cases, but the main job should be done later. So we have Defered Branch!
33
+ * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
34
+ */
35
+ const i=()=>new e,a=()=>new t,o=()=>new r,s=()=>new n
36
+ /**
37
+ * ## Steps to use
38
+ * 1. const a = deferedBranchDynamic()
39
+ * 2. add branches by a.add(condition, branch)
40
+ * 3. add nomatch handler by a.nomatch(handler)
41
+ * 4. call a.predicate(...) to find the matched branch
42
+ * 5. ...run some other logic
43
+ * 6. run this branch by a.run();
44
+ *
45
+ * ## Type Annotation (optional)
46
+ * ```ts
47
+ * type BranchFn = (a: number) => void;
48
+ * type NoMatchFn = () => void;
49
+ * // optional, you can customize the condition function type
50
+ * type ConditionFn = Predicate<BranchFn>;
51
+ * const a = deferedBranch<BranchFn, NoMatchFn, ConditionFn>();
52
+ *
53
+ * // then we have restrictions:
54
+ * a.add(someFn satisfies ConditionFn, secondFn satisfies BranchFn);
55
+ * a.nomatch(thirdFn satisfies NoMatchFn);
56
+ *
57
+ * // some other logic
58
+ *
59
+ * a.predicate(...args);
60
+ *
61
+ * // some other logic
62
+ *
63
+ * a.run(...args); // input args are restricted to Parameters<BranchFn>
64
+ * ```
65
+ *
66
+ * ## About
67
+ * @package DeferedBranch
68
+ * @author Kasukabe Tsumugi <futami16237@gmail.com>
69
+ * @version 2.2.10 (Last Update: 2026.10.12 10:07:47.649)
70
+ * @license MIT
71
+ * @link git+https://github.com/baendlorel/tsumugi-lib.git
72
+ * @link https://baendlorel.github.io/ Welcome to my site!
73
+ * @description Sometimes we need to judge something with multiple cases, but the main job should be done later. So we have Defered Branch!
74
+ * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
75
+ */
76
+ /**
77
+ * ## Steps to use
78
+ * 1. const a = deferedBranchAll()
79
+ * 2. add branches by a.add(condition, branch)
80
+ * 3. (optional) add defered nomatch handler, or add and run at the same time by a.nomatch(handler)
81
+ * 4. ...run some other logic
82
+ * 5. run all matched branches by a.run();
83
+ *
84
+ * ## Type Annotation (optional)
85
+ * ```ts
86
+ * type BranchFn = (a: number) => void;
87
+ * type NoMatchFn = () => void;
88
+ * const a = deferedBranchAll<BranchFn, NoMatchFn>();
89
+ *
90
+ * // then we have restrictions:
91
+ * a.add(true, someFn satisfies BranchFn);
92
+ * a.nomatch(otherFn satisfies NoMatchFn);
93
+ *
94
+ * // some other logic
95
+ *
96
+ * a.run(...args); // input args are restricted to Parameters<BranchFn>
97
+ * ```
98
+ *
99
+ * ## About
100
+ * @package DeferedBranch
101
+ * @author Kasukabe Tsumugi <futami16237@gmail.com>
102
+ * @version 2.2.10 (Last Update: 2026.10.12 10:07:47.649)
103
+ * @license MIT
104
+ * @link git+https://github.com/baendlorel/tsumugi-lib.git
105
+ * @link https://baendlorel.github.io/ Welcome to my site!
106
+ * @description Sometimes we need to judge something with multiple cases, but the main job should be done later. So we have Defered Branch!
107
+ * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
108
+ */
109
+ /**
110
+ * ## Steps to use
111
+ * 1. const a = deferedBranchAllDynamic()
112
+ * 2. add branches by a.add(condition, branch)
113
+ * 3. add nomatch handler by a.nomatch(handler)
114
+ * 4. call a.predicate(...) to find all matched branches
115
+ * 5. ...run some other logic
116
+ * 6. run all matched branches by a.run();
117
+ *
118
+ * ## Type Annotation (optional)
119
+ * ```ts
120
+ * type BranchFn = (a: number) => void;
121
+ * type NoMatchFn = () => void;
122
+ * // optional, you can customize the condition function type
123
+ * type ConditionFn = Predicate<BranchFn>;
124
+ * const a = deferedBranchAllDynamic<BranchFn, NoMatchFn, ConditionFn>();
125
+ *
126
+ * // then we have restrictions:
127
+ * a.add(someFn satisfies ConditionFn, secondFn satisfies BranchFn);
128
+ * a.nomatch(thirdFn satisfies NoMatchFn);
129
+ *
130
+ * // some other logic
131
+ *
132
+ * a.predicate(...args);
133
+ *
134
+ * // some other logic
135
+ *
136
+ * a.run(...args); // input args are restricted to Parameters<BranchFn>
137
+ * ```
138
+ *
139
+ * ## About
140
+ * @package DeferedBranch
141
+ * @author Kasukabe Tsumugi <futami16237@gmail.com>
142
+ * @version 2.2.10 (Last Update: 2026.10.12 10:07:47.649)
143
+ * @license MIT
144
+ * @link git+https://github.com/baendlorel/tsumugi-lib.git
145
+ * @link https://baendlorel.github.io/ Welcome to my site!
146
+ * @description Sometimes we need to judge something with multiple cases, but the main job should be done later. So we have Defered Branch!
147
+ * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
148
+ */
149
+ ;export{i as deferedBranch,o as deferedBranchAll,s as deferedBranchAllDynamic,a as deferedBranchDynamic};
150
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["DeferedBranch","branch","condition","handler","args","result","DeferedBranchDynamic","len","i","DeferedBranchAllDynamic","DeferedBranchAll","deferedBranch","deferedBranchDynamic","deferedBranchAll","deferedBranchAllDynamic"],"sources":["../src/core/default.ts","../src/core/dynamic.ts","../src/core/all-dynamic.ts","../src/core/all.ts","../src/index.ts"],"sourcesContent":["import { AnyFn } from '@defered-branch/global.js';\n\nexport class DeferedBranch<BranchFn extends AnyFn, NoMatchFn extends AnyFn> {\n private _branch: BranchFn | null = null;\n\n /**\n * Add a new entry\n * - **First truthy first served**.\n * @param condition the condition to match\n * @param branch the branch to run when matched\n * @returns this\n */\n add(condition: boolean, branch: BranchFn): this {\n if (typeof branch !== 'function') {\n throw new TypeError('DeferBranch: branch must be a function');\n }\n\n // & Preventing later branches from overwriting earlier matched branch\n if (condition && !this._branch) {\n this._branch = branch;\n }\n return this;\n }\n\n /**\n * Register a handler to be called when no branch matched\n * - This will be called **instantly and ignores later matched branches**\n * @param handler handle the exhausted case\n * @returns this\n */\n nomatch(handler: NoMatchFn): this {\n if (typeof handler !== 'function') {\n throw new TypeError('DeferBranch: branch must be a function');\n }\n\n if (!this._branch) {\n handler();\n }\n\n return this;\n }\n\n /**\n * Execute the first matched branch in order of addition\n * @param args arguments to pass to the matched branch or nomatch handler\n * @returns the return value of the matched branch or void\n */\n run(...args: Parameters<BranchFn>): ReturnType<BranchFn> | void {\n if (this._branch) {\n const result = this._branch.apply(null, args);\n this._branch = null;\n return result;\n }\n }\n}\n","import { AnyFn, Predicate } from '@defered-branch/global.js';\n\nexport class DeferedBranchDynamic<\n BranchFn extends AnyFn,\n NoMatchFn extends AnyFn,\n ConditionFn extends AnyFn = Predicate<BranchFn>,\n> {\n /**\n * & Compress conditions and branches into a single array since they are paired\n */\n private _condranches: AnyFn[] = [];\n private _branch: BranchFn | null = null;\n private _nomatch: NoMatchFn | null = null;\n\n /**\n * Add a new entry\n * - **First truthy first served**.\n * @param condition the condition to match\n * @param branch the branch to run when matched\n * @returns this\n */\n add(condition: ConditionFn, branch: BranchFn): this {\n if (typeof condition !== 'function') {\n throw new TypeError('DeferBranch: condition must be a function');\n }\n if (typeof branch !== 'function') {\n throw new TypeError('DeferBranch: branch must be a function');\n }\n\n this._condranches.push(condition, branch);\n return this;\n }\n\n /**\n * When calling `this.predicate` and no branch matched, run this handler\n * @param handler handle the exhausted case\n * @returns this\n */\n nomatch(handler: AnyFn): this {\n if (typeof handler !== 'function') {\n throw new TypeError('DeferBranch: handler must be a function');\n }\n\n this._nomatch = handler as NoMatchFn;\n return this;\n }\n\n /**\n * Run the condition to find the first matched branch\n */\n predicate(...args: Parameters<ConditionFn>): void {\n const len = this._condranches.length;\n for (let i = 0; i < len; i += 2) {\n if (this._condranches[i]()) {\n this._branch = this._condranches[i + 1] as BranchFn;\n return;\n }\n }\n\n if (this._nomatch) {\n this._nomatch.apply(this, args);\n }\n }\n\n /**\n * Execute the first matched branch in order of addition\n * @param args arguments to pass to the matched branch\n * @returns the return value of the matched branch or void\n */\n run(...args: Parameters<BranchFn>): ReturnType<BranchFn> | undefined {\n if (this._branch) {\n const result = this._branch.apply(null, args);\n this._branch = null;\n return result;\n }\n }\n}\n","import { AnyFn, Predicate } from '@defered-branch/global.js';\n\nexport class DeferedBranchAllDynamic<\n BranchFn extends AnyFn,\n NoMatchFn extends AnyFn,\n ConditionFn extends AnyFn = Predicate<BranchFn>,\n> {\n /**\n * & Compress conditions and branches into a single array since they are paired\n */\n private _condranches: AnyFn[] = [];\n private _branches: BranchFn[] = [];\n private _nomatch: NoMatchFn | null = null;\n\n /**\n * Add a new entry\n * - **All truthy branches will be executed**.\n * @param condition the condition to match\n * @param branch the branch to run when matched\n * @returns this\n */\n add(condition: ConditionFn, branch: BranchFn): this {\n if (typeof condition !== 'function') {\n throw new TypeError('DeferBranch: condition must be a function');\n }\n if (typeof branch !== 'function') {\n throw new TypeError('DeferBranch: branch must be a function');\n }\n\n this._condranches.push(condition, branch);\n return this;\n }\n\n /**\n * When calling `this.predicate` and no branch matched, run this handler\n * @param handler handle the exhausted case\n * @returns this\n */\n nomatch(handler: AnyFn): this {\n if (typeof handler !== 'function') {\n throw new TypeError('DeferBranch: handler must be a function');\n }\n\n this._nomatch = handler as NoMatchFn;\n return this;\n }\n\n /**\n * Run the conditions to find all matched branches\n */\n predicate(...args: Parameters<ConditionFn>): void {\n const len = this._condranches.length;\n for (let i = 0; i < len; i += 2) {\n if (this._condranches[i]()) {\n this._branches.push(this._condranches[i + 1] as BranchFn);\n }\n }\n\n if (this._nomatch && this._branches.length === 0) {\n this._nomatch.apply(this, args);\n }\n }\n\n /**\n * Execute all matched branches in order of addition\n * @param args arguments to pass to the matched branches\n */\n run(...args: Parameters<BranchFn>): ReturnType<BranchFn> | undefined {\n const len = this._branches.length;\n if (len === 0) {\n return;\n }\n for (let i = 0; i < len; i++) {\n this._branches[i].apply(null, args);\n }\n this._branches.length = 0;\n }\n}\n","import { AnyFn } from '@defered-branch/global.js';\n\nexport class DeferedBranchAll<BranchFn extends AnyFn, NoMatchFn extends AnyFn> {\n private _branches: BranchFn[] = [];\n\n /**\n * Add a new entry\n * - **All truthy branches will be executed**.\n * @param condition the condition to match\n * @param branch the branch to run when matched\n * @returns this\n */\n add(condition: boolean, branch: BranchFn): this {\n if (typeof branch !== 'function') {\n throw new TypeError('DeferBranch: branch must be a function');\n }\n\n // & Preventing later branches from overwriting earlier matched branch\n if (condition) {\n this._branches.push(branch);\n }\n return this;\n }\n\n /**\n * Register a handler to be called when no branch matched\n * - This will be called **instantly and ignores later matched branches**\n * @param handler handle the exhausted case\n * @returns this\n */\n nomatch(handler: NoMatchFn): this {\n if (typeof handler !== 'function') {\n throw new TypeError('DeferBranch: branch must be a function');\n }\n\n if (this._branches.length === 0) {\n handler();\n }\n\n return this;\n }\n\n /**\n * Execute all matched branches in order of addition\n * @param args arguments to pass to the matched branch or nomatch handler\n */\n run(...args: Parameters<BranchFn>): void {\n const len = this._branches.length;\n if (len === 0) {\n return;\n }\n for (let i = 0; i < len; i++) {\n this._branches[i].apply(null, args);\n }\n this._branches.length = 0;\n }\n}\n","import { DeferedBranch } from './core/default.js';\nimport { DeferedBranchDynamic } from './core/dynamic.js';\nimport { DeferedBranchAllDynamic } from './core/all-dynamic.js';\nimport { DeferedBranchAll } from './core/all.js';\nimport { AnyFn, Predicate } from './global.js';\n\n/**\n * ## Steps to use\n * 1. const a = deferedBranch()\n * 2. add branches by a.add(condition, branch)\n * 3. (optional) add defered nomatch handler, or add and run at the same time by a.nomatch(handler)\n * 4. ...run some other logic\n * 5. run this branch by a.run();\n *\n * ## Type Annotation (optional)\n * ```ts\n * type BranchFn = (a: number) => void;\n * type NoMatchFn = () => void;\n * const a = deferedBranch<BranchFn, NoMatchFn>();\n *\n * // then we have restrictions:\n * a.add(true, someFn satisfies BranchFn);\n * a.nomatch(otherFn satisfies NoMatchFn);\n *\n * // some other logic\n *\n * a.run(...args); // input args are restricted to Parameters<BranchFn>\n * ```\n *\n * __PKG_INFO__\n */\nexport const deferedBranch = <BranchFn extends AnyFn = AnyFn, NoMatchFn extends AnyFn = AnyFn>() =>\n new DeferedBranch<BranchFn, NoMatchFn>();\n\n/**\n * ## Steps to use\n * 1. const a = deferedBranchDynamic()\n * 2. add branches by a.add(condition, branch)\n * 3. add nomatch handler by a.nomatch(handler)\n * 4. call a.predicate(...) to find the matched branch\n * 5. ...run some other logic\n * 6. run this branch by a.run();\n *\n * ## Type Annotation (optional)\n * ```ts\n * type BranchFn = (a: number) => void;\n * type NoMatchFn = () => void;\n * // optional, you can customize the condition function type\n * type ConditionFn = Predicate<BranchFn>;\n * const a = deferedBranch<BranchFn, NoMatchFn, ConditionFn>();\n *\n * // then we have restrictions:\n * a.add(someFn satisfies ConditionFn, secondFn satisfies BranchFn);\n * a.nomatch(thirdFn satisfies NoMatchFn);\n *\n * // some other logic\n *\n * a.predicate(...args);\n *\n * // some other logic\n *\n * a.run(...args); // input args are restricted to Parameters<BranchFn>\n * ```\n *\n * __PKG_INFO__\n */\nexport const deferedBranchDynamic = <\n BranchFn extends AnyFn = AnyFn,\n NoMatchFn extends AnyFn = AnyFn,\n ConditionFn extends AnyFn = Predicate<BranchFn>,\n>() => new DeferedBranchDynamic<BranchFn, NoMatchFn, ConditionFn>();\n\n/**\n * ## Steps to use\n * 1. const a = deferedBranchAll()\n * 2. add branches by a.add(condition, branch)\n * 3. (optional) add defered nomatch handler, or add and run at the same time by a.nomatch(handler)\n * 4. ...run some other logic\n * 5. run all matched branches by a.run();\n *\n * ## Type Annotation (optional)\n * ```ts\n * type BranchFn = (a: number) => void;\n * type NoMatchFn = () => void;\n * const a = deferedBranchAll<BranchFn, NoMatchFn>();\n *\n * // then we have restrictions:\n * a.add(true, someFn satisfies BranchFn);\n * a.nomatch(otherFn satisfies NoMatchFn);\n *\n * // some other logic\n *\n * a.run(...args); // input args are restricted to Parameters<BranchFn>\n * ```\n *\n * __PKG_INFO__\n */\nexport const deferedBranchAll = <BranchFn extends AnyFn = AnyFn, NoMatchFn extends AnyFn = AnyFn>() =>\n new DeferedBranchAll<BranchFn, NoMatchFn>();\n\n/**\n * ## Steps to use\n * 1. const a = deferedBranchAllDynamic()\n * 2. add branches by a.add(condition, branch)\n * 3. add nomatch handler by a.nomatch(handler)\n * 4. call a.predicate(...) to find all matched branches\n * 5. ...run some other logic\n * 6. run all matched branches by a.run();\n *\n * ## Type Annotation (optional)\n * ```ts\n * type BranchFn = (a: number) => void;\n * type NoMatchFn = () => void;\n * // optional, you can customize the condition function type\n * type ConditionFn = Predicate<BranchFn>;\n * const a = deferedBranchAllDynamic<BranchFn, NoMatchFn, ConditionFn>();\n *\n * // then we have restrictions:\n * a.add(someFn satisfies ConditionFn, secondFn satisfies BranchFn);\n * a.nomatch(thirdFn satisfies NoMatchFn);\n *\n * // some other logic\n *\n * a.predicate(...args);\n *\n * // some other logic\n *\n * a.run(...args); // input args are restricted to Parameters<BranchFn>\n * ```\n *\n * __PKG_INFO__\n */\nexport const deferedBranchAllDynamic = <\n BranchFn extends AnyFn = AnyFn,\n NoMatchFn extends AnyFn = AnyFn,\n ConditionFn extends AnyFn = Predicate<BranchFn>,\n>() => new DeferedBranchAllDynamic<BranchFn, NoMatchFn, ConditionFn>();\n"],"mappings":"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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "defered-branch",
3
- "version": "2.2.8",
3
+ "version": "2.2.10",
4
4
  "author": {
5
5
  "name": "Kasukabe Tsumugi",
6
6
  "email": "futami16237@gmail.com"
@@ -19,10 +19,10 @@
19
19
  "files": [
20
20
  "dist"
21
21
  ],
22
- "homepage": "https://github.com/baendlorel/kt-packages/tree/main/packages/defered-branch#readme",
22
+ "homepage": "https://github.com/baendlorel/tsumugi-lib/tree/main/packages/defered-branch#readme",
23
23
  "repository": {
24
24
  "type": "git",
25
- "url": "git+https://github.com/baendlorel/kt-packages.git",
25
+ "url": "git+https://github.com/baendlorel/tsumugi-lib.git",
26
26
  "directory": "packages/defered-branch"
27
27
  },
28
28
  "keywords": [
@@ -33,6 +33,6 @@
33
33
  ],
34
34
  "license": "MIT",
35
35
  "bugs": {
36
- "url": "https://github.com/baendlorel/kt-packages/issues"
36
+ "url": "https://github.com/baendlorel/tsumugi-lib/issues"
37
37
  }
38
- }
38
+ }