ts-data-forge 14.6.2 → 14.6.3

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.
Files changed (182) hide show
  1. package/dist/array/impl/array-utils-creation.mjs +103 -103
  2. package/dist/array/impl/array-utils-element-access.mjs +46 -46
  3. package/dist/array/impl/array-utils-iterators.mjs +54 -54
  4. package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +49 -49
  5. package/dist/array/impl/array-utils-length-bounded-array-guard.mjs +40 -40
  6. package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs +42 -42
  7. package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs +46 -46
  8. package/dist/array/impl/array-utils-modification.mjs +4 -4
  9. package/dist/array/impl/array-utils-reducing-value.mjs +11 -11
  10. package/dist/array/impl/array-utils-search.mjs +6 -6
  11. package/dist/array/impl/array-utils-set-op.mjs +116 -116
  12. package/dist/array/impl/array-utils-size.mjs +6 -6
  13. package/dist/array/impl/array-utils-slice-clamped.mjs +1 -1
  14. package/dist/array/impl/array-utils-slicing.mjs +56 -56
  15. package/dist/array/impl/array-utils-transformation.mjs +156 -156
  16. package/dist/array/impl/array-utils-validation.mjs +36 -36
  17. package/dist/collections/imap-mapped.mjs +195 -195
  18. package/dist/collections/imap.mjs +143 -143
  19. package/dist/collections/iset-mapped.mjs +320 -320
  20. package/dist/collections/iset.mjs +207 -207
  21. package/dist/collections/queue.mjs +130 -130
  22. package/dist/collections/stack.mjs +125 -125
  23. package/dist/expect-type.mjs +68 -68
  24. package/dist/functional/async-result/impl/async-result-flat-map.mjs +3 -3
  25. package/dist/functional/async-result/impl/async-result-map-err.mjs +2 -2
  26. package/dist/functional/async-result/impl/async-result-map.mjs +2 -2
  27. package/dist/functional/async-result/impl/async-result-unwrap-or.mjs +31 -31
  28. package/dist/functional/optional/impl/optional-expect-to-be.mjs +1 -1
  29. package/dist/functional/optional/impl/optional-filter.mjs +1 -1
  30. package/dist/functional/optional/impl/optional-flat-map.mjs +1 -1
  31. package/dist/functional/optional/impl/optional-from-nullable.mjs +24 -24
  32. package/dist/functional/optional/impl/optional-is-none.mjs +19 -19
  33. package/dist/functional/optional/impl/optional-is-optional.mjs +18 -18
  34. package/dist/functional/optional/impl/optional-is-some.mjs +20 -20
  35. package/dist/functional/optional/impl/optional-map.mjs +2 -2
  36. package/dist/functional/optional/impl/optional-match.mjs +2 -2
  37. package/dist/functional/optional/impl/optional-none.mjs +16 -16
  38. package/dist/functional/optional/impl/optional-or-else.mjs +1 -1
  39. package/dist/functional/optional/impl/optional-some.mjs +19 -19
  40. package/dist/functional/optional/impl/optional-to-nullable.mjs +26 -26
  41. package/dist/functional/optional/impl/optional-unwrap-or.mjs +1 -1
  42. package/dist/functional/optional/impl/optional-unwrap-throw.mjs +28 -28
  43. package/dist/functional/optional/impl/optional-unwrap.mjs +1 -1
  44. package/dist/functional/optional/impl/optional-zip.mjs +32 -32
  45. package/dist/functional/optional/impl/tag.mjs +1 -1
  46. package/dist/functional/pipe.mjs +19 -19
  47. package/dist/functional/result/impl/result-err.mjs +25 -25
  48. package/dist/functional/result/impl/result-expect-to-be.mjs +2 -2
  49. package/dist/functional/result/impl/result-flat-map.mjs +4 -4
  50. package/dist/functional/result/impl/result-fold.mjs +4 -4
  51. package/dist/functional/result/impl/result-from-optional.mjs +2 -2
  52. package/dist/functional/result/impl/result-from-promise.mjs +34 -34
  53. package/dist/functional/result/impl/result-from-throwable.mjs +29 -29
  54. package/dist/functional/result/impl/result-is-err.mjs +19 -19
  55. package/dist/functional/result/impl/result-is-ok.mjs +19 -19
  56. package/dist/functional/result/impl/result-is-result.mjs +19 -19
  57. package/dist/functional/result/impl/result-map-err.mjs +4 -4
  58. package/dist/functional/result/impl/result-map.mjs +4 -4
  59. package/dist/functional/result/impl/result-match.mjs +3 -3
  60. package/dist/functional/result/impl/result-ok.mjs +25 -25
  61. package/dist/functional/result/impl/result-or-else.mjs +2 -2
  62. package/dist/functional/result/impl/result-safe-try.mjs +15 -15
  63. package/dist/functional/result/impl/result-safe-unwrap.mjs +33 -33
  64. package/dist/functional/result/impl/result-swap.mjs +20 -20
  65. package/dist/functional/result/impl/result-to-optional.mjs +27 -27
  66. package/dist/functional/result/impl/result-unwrap-err-or.mjs +2 -2
  67. package/dist/functional/result/impl/result-unwrap-err-throw.mjs +31 -31
  68. package/dist/functional/result/impl/result-unwrap-err.mjs +30 -30
  69. package/dist/functional/result/impl/result-unwrap-ok-or.mjs +2 -2
  70. package/dist/functional/result/impl/result-unwrap-ok.mjs +1 -1
  71. package/dist/functional/result/impl/result-unwrap-throw.mjs +31 -31
  72. package/dist/functional/result/impl/result-zip.mjs +29 -29
  73. package/dist/functional/result/impl/tag.mjs +1 -1
  74. package/dist/functional/ternary-result/impl/tag.mjs +2 -2
  75. package/dist/functional/ternary-result/impl/ternary-result-err.mjs +13 -13
  76. package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +4 -4
  77. package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +4 -4
  78. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +18 -18
  79. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +17 -17
  80. package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +17 -17
  81. package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +19 -19
  82. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +19 -19
  83. package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +18 -18
  84. package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +2 -2
  85. package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +3 -3
  86. package/dist/functional/ternary-result/impl/ternary-result-map.mjs +4 -4
  87. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +14 -14
  88. package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +19 -19
  89. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +19 -19
  90. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +17 -17
  91. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +1 -1
  92. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +20 -20
  93. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +18 -18
  94. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +17 -17
  95. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +16 -16
  96. package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +31 -31
  97. package/dist/functional/ternary-result/impl/variant-name.mjs +1 -1
  98. package/dist/guard/has-key.mjs +41 -41
  99. package/dist/guard/is-non-empty-string.mjs +37 -37
  100. package/dist/guard/is-non-null-object.mjs +34 -34
  101. package/dist/guard/is-primitive.mjs +31 -31
  102. package/dist/guard/is-record.mjs +86 -86
  103. package/dist/guard/is-type.mjs +387 -387
  104. package/dist/guard/key-is-in.mjs +40 -40
  105. package/dist/iterator/range.mjs +1 -1
  106. package/dist/json/json.mjs +289 -289
  107. package/dist/number/branded-types/finite-number.mjs +116 -116
  108. package/dist/number/branded-types/int.mjs +223 -223
  109. package/dist/number/branded-types/int16.mjs +116 -116
  110. package/dist/number/branded-types/int32.mjs +116 -116
  111. package/dist/number/branded-types/negative-finite-number.mjs +126 -126
  112. package/dist/number/branded-types/negative-int.mjs +104 -104
  113. package/dist/number/branded-types/negative-safe-int.mjs +104 -104
  114. package/dist/number/branded-types/non-negative-finite-number.mjs +132 -132
  115. package/dist/number/branded-types/non-negative-int16.mjs +113 -113
  116. package/dist/number/branded-types/non-negative-int32.mjs +113 -113
  117. package/dist/number/branded-types/non-positive-finite-number.mjs +116 -116
  118. package/dist/number/branded-types/non-positive-int.mjs +97 -97
  119. package/dist/number/branded-types/non-positive-safe-int.mjs +98 -98
  120. package/dist/number/branded-types/non-zero-finite-number.mjs +112 -112
  121. package/dist/number/branded-types/non-zero-int.mjs +82 -82
  122. package/dist/number/branded-types/non-zero-int16.mjs +95 -95
  123. package/dist/number/branded-types/non-zero-int32.mjs +95 -95
  124. package/dist/number/branded-types/non-zero-safe-int.mjs +99 -99
  125. package/dist/number/branded-types/non-zero-uint16.mjs +95 -95
  126. package/dist/number/branded-types/non-zero-uint32.mjs +95 -95
  127. package/dist/number/branded-types/positive-finite-number.mjs +134 -134
  128. package/dist/number/branded-types/positive-int.mjs +237 -237
  129. package/dist/number/branded-types/positive-int16.mjs +110 -110
  130. package/dist/number/branded-types/positive-int32.mjs +110 -110
  131. package/dist/number/branded-types/positive-safe-int.mjs +268 -268
  132. package/dist/number/branded-types/positive-uint16.mjs +110 -110
  133. package/dist/number/branded-types/positive-uint32.mjs +110 -110
  134. package/dist/number/branded-types/safe-int.mjs +259 -259
  135. package/dist/number/branded-types/safe-uint.mjs +111 -111
  136. package/dist/number/branded-types/uint.mjs +225 -225
  137. package/dist/number/branded-types/uint16.mjs +108 -108
  138. package/dist/number/branded-types/uint32.mjs +108 -108
  139. package/dist/number/enum/int8.mjs +118 -118
  140. package/dist/number/enum/uint8.mjs +109 -109
  141. package/dist/number/num-arithmetic-types.mjs +1 -1
  142. package/dist/number/num.mjs +478 -478
  143. package/dist/number/refined-number-utils.mjs +170 -170
  144. package/dist/object/object.mjs +234 -234
  145. package/dist/others/cast-mutable.mjs +33 -33
  146. package/dist/others/cast-readonly.mjs +32 -32
  147. package/dist/others/debounce-function.mjs +13 -13
  148. package/dist/others/fast-deep-equal.mjs +14 -14
  149. package/dist/others/if-then.mjs +29 -29
  150. package/dist/others/tuple.mjs +50 -50
  151. package/dist/others/unknown-to-string.mjs +38 -38
  152. package/dist/promise/promise.mjs +47 -47
  153. package/dist/string/str.mjs +177 -177
  154. package/dist/types.mjs +1 -1
  155. package/package.json +6 -6
  156. package/src/guard/is-type.test.mts +2 -2
  157. package/src/number/branded-types/finite-number.test.mts +1 -1
  158. package/src/number/branded-types/int.test.mts +1 -1
  159. package/src/number/branded-types/int16.test.mts +1 -1
  160. package/src/number/branded-types/int32.test.mts +1 -1
  161. package/src/number/branded-types/non-negative-finite-number.test.mts +1 -1
  162. package/src/number/branded-types/non-negative-int16.test.mts +1 -1
  163. package/src/number/branded-types/non-negative-int32.test.mts +1 -1
  164. package/src/number/branded-types/non-zero-finite-number.test.mts +1 -1
  165. package/src/number/branded-types/non-zero-int.test.mts +1 -1
  166. package/src/number/branded-types/non-zero-int16.test.mts +1 -1
  167. package/src/number/branded-types/non-zero-int32.test.mts +1 -1
  168. package/src/number/branded-types/non-zero-safe-int.test.mts +1 -1
  169. package/src/number/branded-types/non-zero-uint16.test.mts +1 -1
  170. package/src/number/branded-types/non-zero-uint32.test.mts +1 -1
  171. package/src/number/branded-types/positive-finite-number.test.mts +1 -1
  172. package/src/number/branded-types/positive-int.test.mts +1 -1
  173. package/src/number/branded-types/positive-int16.test.mts +1 -1
  174. package/src/number/branded-types/positive-int32.test.mts +1 -1
  175. package/src/number/branded-types/positive-safe-int.test.mts +1 -1
  176. package/src/number/branded-types/positive-uint16.test.mts +1 -1
  177. package/src/number/branded-types/positive-uint32.test.mts +1 -1
  178. package/src/number/branded-types/safe-int.test.mts +1 -1
  179. package/src/number/branded-types/safe-uint.test.mts +1 -1
  180. package/src/number/branded-types/uint.test.mts +1 -1
  181. package/src/number/branded-types/uint16.test.mts +1 -1
  182. package/src/number/branded-types/uint32.test.mts +1 -1
@@ -6,15 +6,15 @@ export function match(...args) {
6
6
  return matchImpl(result, cases);
7
7
  }
8
8
  case 1: {
9
- // Curried version: the only argument is the case handlers
9
+
10
10
  const [cases] = args;
11
11
  return (result) => matchImpl(result, cases);
12
12
  }
13
13
  }
14
14
  }
15
15
  const matchImpl = (result, cases) => isOk(result)
16
- ? // eslint-disable-next-line total-functions/no-unsafe-type-assertion
16
+ ?
17
17
  cases.ok(result.value)
18
- : // eslint-disable-next-line total-functions/no-unsafe-type-assertion
18
+ :
19
19
  cases.err(result.value);
20
20
  //# sourceMappingURL=result-match.mjs.map
@@ -1,29 +1,29 @@
1
1
  import { OkTypeTagName } from './tag.mjs';
2
- /**
3
- * Creates a `Result.Ok` containing the given success value.
4
- *
5
- * Use this constructor when an operation succeeds and you want to wrap the
6
- * successful result in a Result type for consistent error handling.
7
- *
8
- * @example
9
- *
10
- * ```ts
11
- * const success = Result.ok({ id: 1 });
12
- *
13
- * const failure = Result.err(new Error('missing data'));
14
- *
15
- * assert.deepStrictEqual(success, {
16
- * $$tag: 'ts-data-forge::Result.ok',
17
- * value: { id: 1 },
18
- * });
19
- *
20
- * assert.isTrue(Result.isErr(failure));
21
- * ```
22
- *
23
- * @template S The type of the success value.
24
- * @param value The success value.
25
- * @returns A `Result.Ok<S>` containing the value.
26
- */
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
27
  export const ok = (value) => ({
28
28
  $$tag: OkTypeTagName,
29
29
  value,
@@ -2,12 +2,12 @@ import { isOk } from './result-is-ok.mjs';
2
2
  export function orElse(...args) {
3
3
  switch (args.length) {
4
4
  case 2: {
5
- // Direct version: first argument is result
5
+
6
6
  const [result, alternative] = args;
7
7
  return orElseImpl(result, alternative);
8
8
  }
9
9
  case 1: {
10
- // Curried version
10
+
11
11
  const [alternative] = args;
12
12
  return (result) => orElseImpl(result, alternative);
13
13
  }
@@ -1,15 +1,15 @@
1
1
  import { hasKey, isRecord } from '../../../guard/index.mjs';
2
2
  export function safeTry(body) {
3
3
  const generator = body();
4
- // A yielded `Err` and a returned `Result` are both already the final
5
- // answer, so the first step's `value` is the result in either case: the
6
- // generator is closed rather than resumed after yielding.
4
+
5
+
6
+
7
7
  const step = generator.next();
8
8
  if (isSyncStep(step)) {
9
- // Dropping a suspended generator would skip the `finally` blocks and
10
- // `using` disposals still pending in the body; closing it runs them
11
- // before the short-circuited `Err` is handed back. `isSyncGenerator` is
12
- // what makes `return()` here synchronous rather than a floating promise.
9
+
10
+
11
+
12
+
13
13
  if (step.done !== true && isSyncGenerator(generator, step)) {
14
14
  generator.return(step.value);
15
15
  }
@@ -22,14 +22,14 @@ export function safeTry(body) {
22
22
  return asyncStep.value;
23
23
  });
24
24
  }
25
- // A sync generator's `next()` returns a plain `{ value, done }` object with
26
- // own properties, while an async generator's returns a `Promise`, whose
27
- // `then` lives on the prototype — so an own-key check on `done` separates the
28
- // two.
25
+
26
+
27
+
28
+
29
29
  const isSyncStep = (value) => isRecord(value) && hasKey(value, 'done');
30
- // The generator-side counterpart of `isSyncStep`: a step in the sync form can
31
- // only have come from a sync generator, so the step is what narrows the
32
- // generator that produced it — hence the predicate reads its second argument
33
- // and not its first.
30
+
31
+
32
+
33
+
34
34
  const isSyncGenerator = (_generator, step) => isSyncStep(step);
35
35
  //# sourceMappingURL=result-safe-try.mjs.map
@@ -1,42 +1,42 @@
1
1
  import { isErr } from './result-is-err.mjs';
2
- /**
3
- * Unwraps a `Result` inside a {@link Result.safeTry} generator body via
4
- * `yield*`, emulating Rust's `?` operator.
5
- *
6
- * If the `Result` is `Ok`, the `yield*` expression evaluates to the contained
7
- * value and execution continues. If it is `Err`, the error is yielded to
8
- * {@link Result.safeTry}, which returns it immediately — the rest of the
9
- * generator body never runs.
10
- *
11
- * This generator must only be delegated to (`yield*`) inside a
12
- * {@link Result.safeTry} body; resuming it after it has yielded an `Err`
13
- * throws.
14
- *
15
- * @example
16
- *
17
- * ```ts
18
- * const result = Result.safeTry(function* () {
19
- * const x = yield* Result.safeUnwrap(Result.ok(2));
20
- *
21
- * const y = yield* Result.safeUnwrap(Result.ok(3));
22
- *
23
- * return Result.ok(x + y);
24
- * });
25
- *
26
- * assert.deepStrictEqual(result, Result.ok(5));
27
- * ```
28
- *
29
- * @template R The input `UnknownResult` type.
30
- * @param result The `Result` to unwrap.
31
- * @returns A generator that yields the `Err` (if any) and returns the `Ok`
32
- * value.
33
- */
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
34
  export function* safeUnwrap(result) {
35
35
  if (isErr(result)) {
36
36
  yield result;
37
37
  throw new Error('`safeUnwrap()` generator was resumed after yielding an `Err`; it must only be used via `yield*` inside `safeTry()`');
38
38
  }
39
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
39
+
40
40
  return result.value;
41
41
  }
42
42
  //# sourceMappingURL=result-safe-unwrap.mjs.map
@@ -2,26 +2,26 @@ import { err } from './result-err.mjs';
2
2
  import { isOk } from './result-is-ok.mjs';
3
3
  import { ok } from './result-ok.mjs';
4
4
  import { unwrapOk } from './result-unwrap-ok.mjs';
5
- /**
6
- * Swaps the success and error values of a `Result`.
7
- *
8
- * @example
9
- *
10
- * ```ts
11
- * const okValue = Result.ok('value');
12
- *
13
- * const errValue = Result.err('error');
14
- *
15
- * assert.deepStrictEqual(Result.swap(okValue), Result.err('value'));
16
- *
17
- * assert.deepStrictEqual(Result.swap(errValue), Result.ok('error'));
18
- * ```
19
- *
20
- * @template R The input `UnknownResult` type.
21
- * @param result The `Result` to swap.
22
- * @returns A new `Result` with success and error swapped.
23
- */
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
24
  export const swap = (result) =>
25
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
25
+
26
26
  isOk(result) ? err(unwrapOk(result)) : ok(result.value);
27
27
  //# sourceMappingURL=result-swap.mjs.map
@@ -1,32 +1,32 @@
1
1
  import { Optional } from '../../optional/index.mjs';
2
2
  import { isOk } from './result-is-ok.mjs';
3
3
  import { unwrapOk } from './result-unwrap-ok.mjs';
4
- /**
5
- * Converts a `Result` to an `Optional`.
6
- *
7
- * This conversion is useful when you want to discard error information and
8
- * only care about whether an operation succeeded. The error information is
9
- * lost in this conversion, so use it when error details are not needed.
10
- *
11
- * If the `Result` is `Ok`, returns `Some` with the value. If the `Result` is
12
- * `Err`, returns `None`.
13
- *
14
- * @example
15
- *
16
- * ```ts
17
- * const okValue = Result.ok(7);
18
- *
19
- * const errValue = Result.err('fail');
20
- *
21
- * assert.deepStrictEqual(Result.toOptional(okValue), Optional.some(7));
22
- *
23
- * assert.deepStrictEqual(Result.toOptional(errValue), Optional.none);
24
- * ```
25
- *
26
- * @template R The input `UnknownResult` type.
27
- * @param result The `Result` to convert.
28
- * @returns An `Optional<UnwrapOk<R>>` containing the success value or
29
- * representing `None`.
30
- */
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
31
  export const toOptional = (result) => isOk(result) ? Optional.some(unwrapOk(result)) : Optional.none;
32
32
  //# sourceMappingURL=result-to-optional.mjs.map
@@ -2,12 +2,12 @@ import { unwrapErr } from './result-unwrap-err.mjs';
2
2
  export function unwrapErrOr(...args) {
3
3
  switch (args.length) {
4
4
  case 2: {
5
- // Direct version: first argument is result
5
+
6
6
  const [result, defaultValue] = args;
7
7
  return unwrapErrOrImpl(result, defaultValue);
8
8
  }
9
9
  case 1: {
10
- // Curried version
10
+
11
11
  const [defaultValue] = args;
12
12
  return (result) => unwrapErrOrImpl(result, defaultValue);
13
13
  }
@@ -1,38 +1,38 @@
1
1
  import { unknownToString } from '../../../others/index.mjs';
2
2
  import { match } from '../../match.mjs';
3
3
  import { isErr } from './result-is-err.mjs';
4
- /**
5
- * Unwraps a `Result`, returning the error value. Throws an error if the
6
- * `Result` is `Result.Ok`.
7
- *
8
- * This function is used when you expect a Result to be an error and want to
9
- * extract the error value. If the Result is unexpectedly Ok, it will throw an
10
- * error with information about the unexpected success value.
11
- *
12
- * @example
13
- *
14
- * ```ts
15
- * const errResult = Result.err(new Error('broken'));
16
- *
17
- * const okResult = Result.ok('value');
18
- *
19
- * assert.isTrue(Result.unwrapErrThrow(errResult).message === 'broken');
20
- *
21
- * assert.throws(() => Result.unwrapErrThrow(okResult), /Expected Err/u);
22
- * ```
23
- *
24
- * @template R The `UnknownResult` type to unwrap.
25
- * @param result The `Result` to unwrap.
26
- * @param toStr An optional function to convert the success value to a string
27
- * for the error message when the Result is unexpectedly Ok. Defaults to
28
- * `String`.
29
- * @returns The error value if `Result.Err`.
30
- * @throws {Error} Error with message "Expected Err but got Ok: {value}" if
31
- * the `Result` is `Result.Ok`.
32
- */
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
33
  export const unwrapErrThrow = (result, toStr = unknownToString) => {
34
34
  if (isErr(result)) {
35
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
35
+
36
36
  return result.value;
37
37
  }
38
38
  const variant = match(result.$$tag, {
@@ -40,7 +40,7 @@ export const unwrapErrThrow = (result, toStr = unknownToString) => {
40
40
  'ts-data-forge::Result.err': 'Err',
41
41
  });
42
42
  throw new Error(`Expected Err but got ${variant}: ${toStr(
43
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
43
+
44
44
  result.value)}`);
45
45
  };
46
46
  //# sourceMappingURL=result-unwrap-err-throw.mjs.map
@@ -1,34 +1,34 @@
1
1
  import { isErr } from './result-is-err.mjs';
2
- /**
3
- * Unwraps a `Result`, returning the error value or `undefined` if it is
4
- * `Result.Ok`.
5
- *
6
- * This provides a safe way to extract error values from Results without
7
- * throwing exceptions. Useful for error handling patterns where you want to
8
- * check for specific error conditions.
9
- *
10
- * @example
11
- *
12
- * ```ts
13
- * const okResult = Result.ok('data');
14
- *
15
- * const errResult = Result.err('problem');
16
- *
17
- * // Result.unwrapErr returns undefined for Ok results
18
- *
19
- * // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
20
- * assert.isTrue(Result.unwrapErr(okResult) === undefined);
21
- *
22
- * // Result.unwrapErr returns the error value for Err results
23
- *
24
- * assert.isTrue(Result.unwrapErr(errResult) === 'problem');
25
- * ```
26
- *
27
- * @template R The `UnknownResult` type to unwrap.
28
- * @param result The `Result` to unwrap.
29
- * @returns The error value if `Result.Err`, otherwise `undefined`.
30
- */
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
31
  export const unwrapErr = (result) =>
32
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
32
+
33
33
  isErr(result) ? result.value : undefined;
34
34
  //# sourceMappingURL=result-unwrap-err.mjs.map
@@ -2,12 +2,12 @@ import { unwrapOk } from './result-unwrap-ok.mjs';
2
2
  export function unwrapOkOr(...args) {
3
3
  switch (args.length) {
4
4
  case 2: {
5
- // Direct version: first argument is result
5
+
6
6
  const [result, defaultValue] = args;
7
7
  return unwrapOkOrImpl(result, defaultValue);
8
8
  }
9
9
  case 1: {
10
- // Curried version
10
+
11
11
  const [defaultValue] = args;
12
12
  return (result) => unwrapOkOrImpl(result, defaultValue);
13
13
  }
@@ -1,7 +1,7 @@
1
1
  import { isOk } from './result-is-ok.mjs';
2
2
  export function unwrapOk(result) {
3
3
  return isOk(result)
4
- ? // eslint-disable-next-line total-functions/no-unsafe-type-assertion
4
+ ?
5
5
  result.value
6
6
  : undefined;
7
7
  }
@@ -1,40 +1,40 @@
1
1
  import { unknownToString } from '../../../others/index.mjs';
2
2
  import { isErr } from './result-is-err.mjs';
3
- /**
4
- * Unwraps a `Result`, returning the success value. Throws an error if the
5
- * `Result` is `Result.Err`.
6
- *
7
- * This is useful when you're confident that a Result should contain a success
8
- * value and want to treat errors as exceptional conditions. The error message
9
- * will be constructed from the error value using the provided string
10
- * conversion function.
11
- *
12
- * @example
13
- *
14
- * ```ts
15
- * const okResult = Result.ok('data');
16
- *
17
- * const errResult = Result.err(new Error('fail'));
18
- *
19
- * assert.isTrue(Result.unwrapThrow(okResult) === 'data');
20
- *
21
- * assert.throws(() => Result.unwrapThrow(errResult), Error, 'fail');
22
- * ```
23
- *
24
- * @template R The `UnknownResult` type to unwrap.
25
- * @param result The `Result` to unwrap.
26
- * @param toStr An optional function to convert the error value to a string
27
- * for the error message. Defaults to `String`.
28
- * @returns The success value if `Result.Ok`.
29
- * @throws {Error} Error with the stringified error value if the `Result` is
30
- * `Result.Err`.
31
- */
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
32
  export const unwrapThrow = (result, toStr = unknownToString) => {
33
33
  if (isErr(result)) {
34
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
34
+
35
35
  throw new Error(toStr(result.value));
36
36
  }
37
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
37
+
38
38
  return result.value;
39
39
  };
40
40
  //# sourceMappingURL=result-unwrap-throw.mjs.map
@@ -1,34 +1,34 @@
1
1
  import { isOk } from './result-is-ok.mjs';
2
2
  import { ok } from './result-ok.mjs';
3
- /**
4
- * Combines two `Result` values into a single `Result` containing a tuple. If
5
- * either `Result` is `Err`, returns the first `Err` encountered.
6
- *
7
- * @example
8
- *
9
- * ```ts
10
- * const first = Result.ok('left');
11
- *
12
- * const second = Result.ok(1);
13
- *
14
- * const expected = ['left', 1] as const;
15
- *
16
- * assert.deepStrictEqual(Result.zip(first, second), Result.ok(expected));
17
- *
18
- * assert.deepStrictEqual(
19
- * Result.zip(first, Result.err('error')),
20
- * Result.err('error'),
21
- * );
22
- * ```
23
- *
24
- * @template S1 The success type of the first `Result`.
25
- * @template E1 The error type of the first `Result`.
26
- * @template S2 The success type of the second `Result`.
27
- * @template E2 The error type of the second `Result`.
28
- * @param resultA The first `Result`.
29
- * @param resultB The second `Result`.
30
- * @returns A `Result` containing a tuple of both values, or the first `Err`.
31
- */
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
32
  export const zip = (resultA, resultB) => isOk(resultA)
33
33
  ? isOk(resultB)
34
34
  ? ok([resultA.value, resultB.value])
@@ -1,4 +1,4 @@
1
1
  export const OkTypeTagName = 'ts-data-forge::Result.ok';
2
- /** @internal Tag identifying the Err variant. */
2
+
3
3
  export const ErrTypeTagName = 'ts-data-forge::Result.err';
4
4
  //# sourceMappingURL=tag.mjs.map
@@ -1,6 +1,6 @@
1
1
  export const OkTypeTagName = 'ts-data-forge::Result.ok';
2
- /** @internal Tag identifying the Warn variant. */
2
+
3
3
  export const WarnTypeTagName = 'ts-data-forge::Result.warn';
4
- /** @internal Tag identifying the Err variant. */
4
+
5
5
  export const ErrTypeTagName = 'ts-data-forge::Result.err';
6
6
  //# sourceMappingURL=tag.mjs.map