happy-rusty 1.3.1 → 1.3.2
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.cn.md +7 -2
- package/README.md +7 -2
- package/dist/main.cjs.map +1 -1
- package/dist/main.mjs.map +1 -1
- package/dist/types.d.ts +24 -24
- package/docs/functions/Err.md +1 -1
- package/docs/functions/Ok.md +1 -1
- package/docs/functions/Some.md +1 -1
- package/docs/functions/isOption.md +1 -1
- package/docs/functions/isResult.md +1 -1
- package/docs/functions/promiseToAsyncResult.md +7 -7
- package/docs/interfaces/None.md +28 -28
- package/docs/interfaces/Option.md +27 -27
- package/docs/interfaces/Result.md +29 -29
- package/docs/type-aliases/AsyncIOResult.md +1 -1
- package/docs/type-aliases/AsyncOption.md +1 -1
- package/docs/type-aliases/AsyncResult.md +1 -1
- package/docs/type-aliases/IOResult.md +1 -1
- package/docs/variables/None.md +1 -1
- package/docs/variables/RESULT_FALSE.md +1 -1
- package/docs/variables/RESULT_TRUE.md +1 -1
- package/docs/variables/RESULT_ZERO.md +1 -1
- package/package.json +2 -1
- package/src/enum/extensions.ts +6 -6
- package/src/enum/mod.ts +1 -1
- package/src/enum/prelude.ts +1 -1
- /package/src/enum/{helpers.ts → utils.ts} +0 -0
|
@@ -29,7 +29,7 @@ pub enum Result<T, E> {
|
|
|
29
29
|
|
|
30
30
|
| Property | Type | Description | Defined in |
|
|
31
31
|
| ------ | ------ | ------ | ------ |
|
|
32
|
-
| `[toStringTag]` | `"Result"` | [object Result]. | [core.ts:304](https://github.com/JiangJie/happy-rusty/blob/
|
|
32
|
+
| `[toStringTag]` | `"Result"` | [object Result]. | [core.ts:304](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L304) |
|
|
33
33
|
|
|
34
34
|
## Methods
|
|
35
35
|
|
|
@@ -61,7 +61,7 @@ The passed `Result` if `this` is `Ok`, otherwise returns `this` (which is `Err`)
|
|
|
61
61
|
|
|
62
62
|
#### Defined in
|
|
63
63
|
|
|
64
|
-
[core.ts:489](https://github.com/JiangJie/happy-rusty/blob/
|
|
64
|
+
[core.ts:489](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L489)
|
|
65
65
|
|
|
66
66
|
***
|
|
67
67
|
|
|
@@ -93,7 +93,7 @@ The result of `fn` if `this` is `Ok`, otherwise `this` as `Err`.
|
|
|
93
93
|
|
|
94
94
|
#### Defined in
|
|
95
95
|
|
|
96
|
-
[core.ts:505](https://github.com/JiangJie/happy-rusty/blob/
|
|
96
|
+
[core.ts:505](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L505)
|
|
97
97
|
|
|
98
98
|
***
|
|
99
99
|
|
|
@@ -122,7 +122,7 @@ Just same as `result as unknown as Result<U, E>`.
|
|
|
122
122
|
|
|
123
123
|
#### Defined in
|
|
124
124
|
|
|
125
|
-
[core.ts:563](https://github.com/JiangJie/happy-rusty/blob/
|
|
125
|
+
[core.ts:563](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L563)
|
|
126
126
|
|
|
127
127
|
***
|
|
128
128
|
|
|
@@ -150,7 +150,7 @@ Just same as `result as unknown as Result<T, F>`.
|
|
|
150
150
|
|
|
151
151
|
#### Defined in
|
|
152
152
|
|
|
153
|
-
[core.ts:552](https://github.com/JiangJie/happy-rusty/blob/
|
|
153
|
+
[core.ts:552](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L552)
|
|
154
154
|
|
|
155
155
|
***
|
|
156
156
|
|
|
@@ -176,7 +176,7 @@ Tests whether `this` and `other` are both `Ok` containing equal values, or both
|
|
|
176
176
|
|
|
177
177
|
#### Defined in
|
|
178
178
|
|
|
179
|
-
[core.ts:540](https://github.com/JiangJie/happy-rusty/blob/
|
|
179
|
+
[core.ts:540](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L540)
|
|
180
180
|
|
|
181
181
|
***
|
|
182
182
|
|
|
@@ -196,7 +196,7 @@ If the result is `Ok`, returns `None`.
|
|
|
196
196
|
|
|
197
197
|
#### Defined in
|
|
198
198
|
|
|
199
|
-
[core.ts:413](https://github.com/JiangJie/happy-rusty/blob/
|
|
199
|
+
[core.ts:413](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L413)
|
|
200
200
|
|
|
201
201
|
***
|
|
202
202
|
|
|
@@ -224,7 +224,7 @@ Throws an error with the provided message if the result is an `Err`.
|
|
|
224
224
|
|
|
225
225
|
#### Defined in
|
|
226
226
|
|
|
227
|
-
[core.ts:356](https://github.com/JiangJie/happy-rusty/blob/
|
|
227
|
+
[core.ts:356](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L356)
|
|
228
228
|
|
|
229
229
|
***
|
|
230
230
|
|
|
@@ -252,7 +252,7 @@ Throws an error with the provided message if the result is an `Ok`.
|
|
|
252
252
|
|
|
253
253
|
#### Defined in
|
|
254
254
|
|
|
255
|
-
[core.ts:385](https://github.com/JiangJie/happy-rusty/blob/
|
|
255
|
+
[core.ts:385](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L385)
|
|
256
256
|
|
|
257
257
|
***
|
|
258
258
|
|
|
@@ -284,7 +284,7 @@ If the result is `Ok(Err(E))` or `Err(E)`, returns `Err(E)`.
|
|
|
284
284
|
|
|
285
285
|
#### Defined in
|
|
286
286
|
|
|
287
|
-
[core.ts:473](https://github.com/JiangJie/happy-rusty/blob/
|
|
287
|
+
[core.ts:473](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L473)
|
|
288
288
|
|
|
289
289
|
***
|
|
290
290
|
|
|
@@ -311,7 +311,7 @@ Does not modify the `Result`.
|
|
|
311
311
|
|
|
312
312
|
#### Defined in
|
|
313
313
|
|
|
314
|
-
[core.ts:523](https://github.com/JiangJie/happy-rusty/blob/
|
|
314
|
+
[core.ts:523](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L523)
|
|
315
315
|
|
|
316
316
|
***
|
|
317
317
|
|
|
@@ -338,7 +338,7 @@ Does not modify the `Result`.
|
|
|
338
338
|
|
|
339
339
|
#### Defined in
|
|
340
340
|
|
|
341
|
-
[core.ts:531](https://github.com/JiangJie/happy-rusty/blob/
|
|
341
|
+
[core.ts:531](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L531)
|
|
342
342
|
|
|
343
343
|
***
|
|
344
344
|
|
|
@@ -356,7 +356,7 @@ Returns `true` if the result is `Err`.
|
|
|
356
356
|
|
|
357
357
|
#### Defined in
|
|
358
358
|
|
|
359
|
-
[core.ts:329](https://github.com/JiangJie/happy-rusty/blob/
|
|
359
|
+
[core.ts:329](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L329)
|
|
360
360
|
|
|
361
361
|
***
|
|
362
362
|
|
|
@@ -380,7 +380,7 @@ Returns `true` if the result is `Err` and the provided predicate returns `true`
|
|
|
380
380
|
|
|
381
381
|
#### Defined in
|
|
382
382
|
|
|
383
|
-
[core.ts:341](https://github.com/JiangJie/happy-rusty/blob/
|
|
383
|
+
[core.ts:341](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L341)
|
|
384
384
|
|
|
385
385
|
***
|
|
386
386
|
|
|
@@ -398,7 +398,7 @@ Returns `true` if the result is `Ok`.
|
|
|
398
398
|
|
|
399
399
|
#### Defined in
|
|
400
400
|
|
|
401
|
-
[core.ts:324](https://github.com/JiangJie/happy-rusty/blob/
|
|
401
|
+
[core.ts:324](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L324)
|
|
402
402
|
|
|
403
403
|
***
|
|
404
404
|
|
|
@@ -422,7 +422,7 @@ Returns `true` if the result is `Ok` and the provided predicate returns `true` f
|
|
|
422
422
|
|
|
423
423
|
#### Defined in
|
|
424
424
|
|
|
425
|
-
[core.ts:335](https://github.com/JiangJie/happy-rusty/blob/
|
|
425
|
+
[core.ts:335](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L335)
|
|
426
426
|
|
|
427
427
|
***
|
|
428
428
|
|
|
@@ -453,7 +453,7 @@ leaving an `Err` value untouched.
|
|
|
453
453
|
|
|
454
454
|
#### Defined in
|
|
455
455
|
|
|
456
|
-
[core.ts:434](https://github.com/JiangJie/happy-rusty/blob/
|
|
456
|
+
[core.ts:434](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L434)
|
|
457
457
|
|
|
458
458
|
***
|
|
459
459
|
|
|
@@ -484,7 +484,7 @@ leaving an `Ok` value untouched.
|
|
|
484
484
|
|
|
485
485
|
#### Defined in
|
|
486
486
|
|
|
487
|
-
[core.ts:446](https://github.com/JiangJie/happy-rusty/blob/
|
|
487
|
+
[core.ts:446](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L446)
|
|
488
488
|
|
|
489
489
|
***
|
|
490
490
|
|
|
@@ -515,7 +515,7 @@ Maps a `Result<T, E>` to `U` by applying a function to the contained `Ok` value
|
|
|
515
515
|
|
|
516
516
|
#### Defined in
|
|
517
517
|
|
|
518
|
-
[core.ts:458](https://github.com/JiangJie/happy-rusty/blob/
|
|
518
|
+
[core.ts:458](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L458)
|
|
519
519
|
|
|
520
520
|
***
|
|
521
521
|
|
|
@@ -546,7 +546,7 @@ Maps a `Result<T, E>` to `U` by applying a function to the contained `Ok` value
|
|
|
546
546
|
|
|
547
547
|
#### Defined in
|
|
548
548
|
|
|
549
|
-
[core.ts:466](https://github.com/JiangJie/happy-rusty/blob/
|
|
549
|
+
[core.ts:466](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L466)
|
|
550
550
|
|
|
551
551
|
***
|
|
552
552
|
|
|
@@ -566,7 +566,7 @@ If the result is `Err`, returns `None`.
|
|
|
566
566
|
|
|
567
567
|
#### Defined in
|
|
568
568
|
|
|
569
|
-
[core.ts:406](https://github.com/JiangJie/happy-rusty/blob/
|
|
569
|
+
[core.ts:406](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L406)
|
|
570
570
|
|
|
571
571
|
***
|
|
572
572
|
|
|
@@ -598,7 +598,7 @@ Returns `this` if it is `Ok`, otherwise returns the passed `Result`.
|
|
|
598
598
|
|
|
599
599
|
#### Defined in
|
|
600
600
|
|
|
601
|
-
[core.ts:497](https://github.com/JiangJie/happy-rusty/blob/
|
|
601
|
+
[core.ts:497](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L497)
|
|
602
602
|
|
|
603
603
|
***
|
|
604
604
|
|
|
@@ -630,7 +630,7 @@ The result of `fn` if `this` is `Err`, otherwise `this` as `Ok`.
|
|
|
630
630
|
|
|
631
631
|
#### Defined in
|
|
632
632
|
|
|
633
|
-
[core.ts:513](https://github.com/JiangJie/happy-rusty/blob/
|
|
633
|
+
[core.ts:513](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L513)
|
|
634
634
|
|
|
635
635
|
***
|
|
636
636
|
|
|
@@ -648,7 +648,7 @@ Custom `toString` implementation that uses the `Result`'s contained value.
|
|
|
648
648
|
|
|
649
649
|
#### Defined in
|
|
650
650
|
|
|
651
|
-
[core.ts:568](https://github.com/JiangJie/happy-rusty/blob/
|
|
651
|
+
[core.ts:568](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L568)
|
|
652
652
|
|
|
653
653
|
***
|
|
654
654
|
|
|
@@ -682,7 +682,7 @@ Transposes a `Result` of an `Option` into an `Option` of a `Result`.
|
|
|
682
682
|
|
|
683
683
|
#### Defined in
|
|
684
684
|
|
|
685
|
-
[core.ts:422](https://github.com/JiangJie/happy-rusty/blob/
|
|
685
|
+
[core.ts:422](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L422)
|
|
686
686
|
|
|
687
687
|
***
|
|
688
688
|
|
|
@@ -704,7 +704,7 @@ Throws an error if the result is an `Err`.
|
|
|
704
704
|
|
|
705
705
|
#### Defined in
|
|
706
706
|
|
|
707
|
-
[core.ts:362](https://github.com/JiangJie/happy-rusty/blob/
|
|
707
|
+
[core.ts:362](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L362)
|
|
708
708
|
|
|
709
709
|
***
|
|
710
710
|
|
|
@@ -726,7 +726,7 @@ Throws an error if the result is an `Ok`.
|
|
|
726
726
|
|
|
727
727
|
#### Defined in
|
|
728
728
|
|
|
729
|
-
[core.ts:391](https://github.com/JiangJie/happy-rusty/blob/
|
|
729
|
+
[core.ts:391](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L391)
|
|
730
730
|
|
|
731
731
|
***
|
|
732
732
|
|
|
@@ -750,7 +750,7 @@ Returns the contained `Ok` value or a provided default.
|
|
|
750
750
|
|
|
751
751
|
#### Defined in
|
|
752
752
|
|
|
753
|
-
[core.ts:368](https://github.com/JiangJie/happy-rusty/blob/
|
|
753
|
+
[core.ts:368](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L368)
|
|
754
754
|
|
|
755
755
|
***
|
|
756
756
|
|
|
@@ -774,4 +774,4 @@ Returns the contained `Ok` value or computes it from a closure if the result is
|
|
|
774
774
|
|
|
775
775
|
#### Defined in
|
|
776
776
|
|
|
777
|
-
[core.ts:374](https://github.com/JiangJie/happy-rusty/blob/
|
|
777
|
+
[core.ts:374](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/core.ts#L374)
|
|
@@ -21,4 +21,4 @@ This is a promise that resolves to `Ok(T)` if the I/O operation was successful,
|
|
|
21
21
|
|
|
22
22
|
## Defined in
|
|
23
23
|
|
|
24
|
-
[defines.ts:38](https://github.com/JiangJie/happy-rusty/blob/
|
|
24
|
+
[defines.ts:38](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/defines.ts#L38)
|
|
@@ -21,4 +21,4 @@ This is a promise that resolves to either `Some(T)` if the value is present, or
|
|
|
21
21
|
|
|
22
22
|
## Defined in
|
|
23
23
|
|
|
24
|
-
[defines.ts:13](https://github.com/JiangJie/happy-rusty/blob/
|
|
24
|
+
[defines.ts:13](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/defines.ts#L13)
|
|
@@ -22,4 +22,4 @@ This is a promise that resolves to `Ok(T)` if the operation was successful, or `
|
|
|
22
22
|
|
|
23
23
|
## Defined in
|
|
24
24
|
|
|
25
|
-
[defines.ts:22](https://github.com/JiangJie/happy-rusty/blob/
|
|
25
|
+
[defines.ts:22](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/defines.ts#L22)
|
|
@@ -21,4 +21,4 @@ This is a result that is either `Ok(T)` if the operation was successful, or `Err
|
|
|
21
21
|
|
|
22
22
|
## Defined in
|
|
23
23
|
|
|
24
|
-
[defines.ts:30](https://github.com/JiangJie/happy-rusty/blob/
|
|
24
|
+
[defines.ts:30](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/defines.ts#L30)
|
package/docs/variables/None.md
CHANGED
|
@@ -15,4 +15,4 @@ This constant is frozen to ensure it is immutable and cannot be altered, preserv
|
|
|
15
15
|
|
|
16
16
|
## Defined in
|
|
17
17
|
|
|
18
|
-
[prelude.ts:10](https://github.com/JiangJie/happy-rusty/blob/
|
|
18
|
+
[prelude.ts:10](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/prelude.ts#L10)
|
|
@@ -15,4 +15,4 @@ Can be used anywhere due to immutability.
|
|
|
15
15
|
|
|
16
16
|
## Defined in
|
|
17
17
|
|
|
18
|
-
[constants.ts:19](https://github.com/JiangJie/happy-rusty/blob/
|
|
18
|
+
[constants.ts:19](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/constants.ts#L19)
|
|
@@ -15,4 +15,4 @@ Can be used anywhere due to immutability.
|
|
|
15
15
|
|
|
16
16
|
## Defined in
|
|
17
17
|
|
|
18
|
-
[constants.ts:13](https://github.com/JiangJie/happy-rusty/blob/
|
|
18
|
+
[constants.ts:13](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/constants.ts#L13)
|
|
@@ -15,4 +15,4 @@ Can be used anywhere due to immutability.
|
|
|
15
15
|
|
|
16
16
|
## Defined in
|
|
17
17
|
|
|
18
|
-
[constants.ts:25](https://github.com/JiangJie/happy-rusty/blob/
|
|
18
|
+
[constants.ts:25](https://github.com/JiangJie/happy-rusty/blob/d91a6123f053d528d1e11023507d8f0c72720848/src/enum/constants.ts#L25)
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Porting some excellent design implementations from Rust to JavaScript.",
|
|
4
4
|
"author": "jiang115jie@gmail.com",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
|
-
"version": "1.3.
|
|
6
|
+
"version": "1.3.2",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"source": "src/mod.ts",
|
|
9
9
|
"main": "dist/main.cjs",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"test:html": "deno test --coverage && deno coverage coverage && deno coverage coverage --html",
|
|
31
31
|
"predocs": "pnpm dlx rimraf docs",
|
|
32
32
|
"docs": "pnpm exec typedoc",
|
|
33
|
+
"eg": "deno run -A examples/main.ts",
|
|
33
34
|
"prepublishOnly": "pnpm run build"
|
|
34
35
|
},
|
|
35
36
|
"repository": {
|
package/src/enum/extensions.ts
CHANGED
|
@@ -13,12 +13,12 @@ import { Err, Ok } from './prelude.ts';
|
|
|
13
13
|
* @example
|
|
14
14
|
* ```ts
|
|
15
15
|
* async function example() {
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
16
|
+
* const result = await promiseToAsyncResult(fetchData());
|
|
17
|
+
* result.inspect(x => {
|
|
18
|
+
* console.log('Data:', x);
|
|
19
|
+
* }).inspectErr(err => {
|
|
20
|
+
* console.error('Error:', err);
|
|
21
|
+
* });
|
|
22
22
|
* }
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
package/src/enum/mod.ts
CHANGED
package/src/enum/prelude.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
2
|
import type { Option, Result } from './core.ts';
|
|
3
|
-
import { isOption, isResult } from './helpers.ts';
|
|
4
3
|
import { OptionKindSymbol, ResultKindSymbol } from './symbols.ts';
|
|
4
|
+
import { isOption, isResult } from './utils.ts';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Represents the absence of a value, as a specialized `Option` type.
|
|
File without changes
|