defered-branch 1.0.0 → 1.0.1
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.d.ts +25 -23
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,38 +1,40 @@
|
|
|
1
1
|
declare class DeferBranch {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
private _branch;
|
|
3
|
+
private _nomatchHandler;
|
|
4
|
+
/**
|
|
5
|
+
* Add a new entry
|
|
6
|
+
* - will **override** the previous matched branch
|
|
7
|
+
* @param condition the condition to match
|
|
8
|
+
* @param branch the branch to run when matched
|
|
9
|
+
* @returns this
|
|
10
|
+
*/
|
|
11
|
+
add(condition: boolean, branch: Fn): DeferBranch;
|
|
12
|
+
/**
|
|
13
|
+
* When no branch matched, run this handler
|
|
14
|
+
* @param handler handle the exhausted case
|
|
15
|
+
* @returns this
|
|
16
|
+
*/
|
|
17
|
+
nomatch(handler: Fn): DeferBranch;
|
|
18
|
+
/**
|
|
19
|
+
* If some branch matched, return its returnValue
|
|
20
|
+
* - if no branch matched, return the nomatch handler returnValue
|
|
21
|
+
* - if no branch matched and no nomatch handler, return undefined
|
|
22
|
+
*/
|
|
23
|
+
run(): unknown;
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
26
|
* ## About
|
|
25
27
|
* @package DeferedBranch
|
|
26
28
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
27
|
-
* @version 1.0.
|
|
29
|
+
* @version 1.0.1 (Last Update: 2025.09.19 07:33:04.605)
|
|
28
30
|
* @license MIT
|
|
29
31
|
* @link https://github.com/baendlorel/defered-branch
|
|
30
32
|
* @description Sometimes we need to judge something with multiple cases, but the main job should be done later. So we have Defered Branch!
|
|
31
33
|
* @copyright Copyright (c) 2025 Kasukabe Tsumugi. All rights reserved.
|
|
32
34
|
*/
|
|
33
|
-
declare const
|
|
35
|
+
declare const deferedBranch: () => DeferBranch;
|
|
34
36
|
|
|
35
|
-
export {
|
|
37
|
+
export { deferedBranch };
|
|
36
38
|
|
|
37
39
|
// # from: src/global.d.ts
|
|
38
40
|
type Fn = (...args: unknown[]) => unknown;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class t{t=null;h=null;add(t,n){if("function"!=typeof n)throw new TypeError("Branch must be a function");return t&&(this.t=n),this}nomatch(t){if("function"!=typeof t)throw new TypeError("Branch must be a function");return this.h=t,this}run(){return this.t?this.t():this.h?this.h():void 0}}const n=()=>new t;export{n as
|
|
1
|
+
class t{t=null;h=null;add(t,n){if("function"!=typeof n)throw new TypeError("Branch must be a function");return t&&(this.t=n),this}nomatch(t){if("function"!=typeof t)throw new TypeError("Branch must be a function");return this.h=t,this}run(){return this.t?this.t():this.h?this.h():void 0}}const n=()=>new t;export{n as deferedBranch};
|