@ls-stack/utils 2.14.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/assertions.cjs +5 -5
  2. package/dist/assertions.d.cts +2 -2
  3. package/dist/assertions.d.ts +2 -2
  4. package/dist/assertions.js +1 -1
  5. package/dist/cache.cjs +13 -10
  6. package/dist/cache.d.cts +6 -6
  7. package/dist/cache.d.ts +6 -6
  8. package/dist/cache.js +11 -11
  9. package/dist/castValues.cjs +12 -4
  10. package/dist/castValues.js +1 -1
  11. package/dist/{chunk-4UGSP3L3.js → chunk-2TIVYE43.js} +5 -5
  12. package/dist/{chunk-T5WDDPFI.js → chunk-4DCLNY64.js} +1 -1
  13. package/dist/{chunk-KBFP7INB.js → chunk-55DQGPY3.js} +67 -38
  14. package/dist/{chunk-RK6PT7JY.js → chunk-5MNYPLZI.js} +1 -1
  15. package/dist/chunk-II4R3VVX.js +25 -0
  16. package/dist/createThrottleController.js +4 -4
  17. package/dist/enhancedMap.js +2 -2
  18. package/dist/exhaustiveMatch.cjs +13 -2
  19. package/dist/exhaustiveMatch.d.cts +4 -1
  20. package/dist/exhaustiveMatch.d.ts +4 -1
  21. package/dist/exhaustiveMatch.js +11 -1
  22. package/dist/getValueStableKey.cjs +83 -0
  23. package/dist/getValueStableKey.d.cts +10 -0
  24. package/dist/getValueStableKey.d.ts +10 -0
  25. package/dist/getValueStableKey.js +55 -0
  26. package/dist/interpolate.js +1 -1
  27. package/dist/main.d.ts +2 -2
  28. package/dist/parallelAsyncCalls.cjs +51 -18
  29. package/dist/parallelAsyncCalls.d.cts +1 -2
  30. package/dist/parallelAsyncCalls.d.ts +1 -2
  31. package/dist/parallelAsyncCalls.js +5 -5
  32. package/dist/testUtils.js +1 -1
  33. package/dist/time.cjs +12 -4
  34. package/dist/time.js +2 -2
  35. package/dist/{rsResult.cjs → tsResult.cjs} +74 -43
  36. package/dist/{rsResult.d.cts → tsResult.d.cts} +34 -23
  37. package/dist/{rsResult.d.ts → tsResult.d.ts} +34 -23
  38. package/dist/tsResult.js +16 -0
  39. package/dist/typingTestUtils.cjs +4 -1
  40. package/dist/typingTestUtils.d.cts +26 -0
  41. package/dist/typingTestUtils.d.ts +26 -0
  42. package/dist/typingTestUtils.js +4 -1
  43. package/dist/typingUtils.d.cts +4 -1
  44. package/dist/typingUtils.d.ts +4 -1
  45. package/dist/yamlStringify.js +1 -1
  46. package/package.json +15 -15
  47. package/dist/chunk-GBFS2I67.js +0 -17
  48. package/dist/getObjStableKey.cjs +0 -83
  49. package/dist/getObjStableKey.d.cts +0 -3
  50. package/dist/getObjStableKey.d.ts +0 -3
  51. package/dist/getObjStableKey.js +0 -44
  52. package/dist/rsResult.js +0 -20
@@ -34,15 +34,15 @@ __export(assertions_exports, {
34
34
  module.exports = __toCommonJS(assertions_exports);
35
35
  var undefErrMsg = "not undefined assertion failed";
36
36
  var nullishErrMsg = "not nullish assertion failed";
37
- function notUndefined(value) {
37
+ function notUndefined(value, message = undefErrMsg) {
38
38
  if (value === void 0) {
39
- throw new Error(undefErrMsg);
39
+ throw new Error(message);
40
40
  }
41
41
  return value;
42
42
  }
43
- function notNullish(value) {
43
+ function notNullish(value, message = nullishErrMsg) {
44
44
  if (value === void 0 || value === null) {
45
- throw new Error(nullishErrMsg);
45
+ throw new Error(message);
46
46
  }
47
47
  return value;
48
48
  }
@@ -71,7 +71,7 @@ function isFunction(value) {
71
71
  return typeof value === "function";
72
72
  }
73
73
  function isPromise(value) {
74
- return isObject(value) && "then" in value;
74
+ return isObject(value) && "then" in value && isFunction(value.then);
75
75
  }
76
76
  function isPlainObject(value) {
77
77
  if (!value || typeof value !== "object") return false;
@@ -1,8 +1,8 @@
1
1
  type NotUndefined<T> = T extends undefined ? never : T;
2
2
  type StrictNonUndefined<T, N = unknown> = undefined extends T ? NotUndefined<T> : N;
3
- declare function notUndefined<T>(value: T): StrictNonUndefined<T>;
3
+ declare function notUndefined<T>(value: T, message?: string): StrictNonUndefined<T>;
4
4
  type StrictNonNullable<T, N = unknown> = undefined extends T ? NonNullable<T> : null extends T ? NonNullable<T> : N;
5
- declare function notNullish<T>(value: T): StrictNonNullable<T>;
5
+ declare function notNullish<T>(value: T, message?: string): StrictNonNullable<T>;
6
6
  declare function assertIsNotNullish<T>(value: T, errorMsg?: string): asserts value is StrictNonNullable<T, never>;
7
7
  declare function assertIsNotUndefined<T>(value: T, errorMsg?: string): asserts value is StrictNonUndefined<T, never>;
8
8
  /** Use this function to assert that a certain condition is always true. */
@@ -1,8 +1,8 @@
1
1
  type NotUndefined<T> = T extends undefined ? never : T;
2
2
  type StrictNonUndefined<T, N = unknown> = undefined extends T ? NotUndefined<T> : N;
3
- declare function notUndefined<T>(value: T): StrictNonUndefined<T>;
3
+ declare function notUndefined<T>(value: T, message?: string): StrictNonUndefined<T>;
4
4
  type StrictNonNullable<T, N = unknown> = undefined extends T ? NonNullable<T> : null extends T ? NonNullable<T> : N;
5
- declare function notNullish<T>(value: T): StrictNonNullable<T>;
5
+ declare function notNullish<T>(value: T, message?: string): StrictNonNullable<T>;
6
6
  declare function assertIsNotNullish<T>(value: T, errorMsg?: string): asserts value is StrictNonNullable<T, never>;
7
7
  declare function assertIsNotUndefined<T>(value: T, errorMsg?: string): asserts value is StrictNonUndefined<T, never>;
8
8
  /** Use this function to assert that a certain condition is always true. */
@@ -9,7 +9,7 @@ import {
9
9
  isPromise,
10
10
  notNullish,
11
11
  notUndefined
12
- } from "./chunk-4UGSP3L3.js";
12
+ } from "./chunk-2TIVYE43.js";
13
13
  export {
14
14
  assertIsNotNullish,
15
15
  assertIsNotUndefined,
package/dist/cache.cjs CHANGED
@@ -20,7 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/cache.ts
21
21
  var cache_exports = {};
22
22
  __export(cache_exports, {
23
- RejectValue: () => RejectValue,
23
+ SkipCaching: () => SkipCaching,
24
24
  WithExpiration: () => WithExpiration,
25
25
  cachedGetter: () => cachedGetter,
26
26
  createCache: () => createCache
@@ -31,8 +31,11 @@ module.exports = __toCommonJS(cache_exports);
31
31
  function isObject(value) {
32
32
  return typeof value === "object" && value !== null && !Array.isArray(value);
33
33
  }
34
+ function isFunction(value) {
35
+ return typeof value === "function";
36
+ }
34
37
  function isPromise(value) {
35
- return isObject(value) && "then" in value;
38
+ return isObject(value) && "then" in value && isFunction(value.then);
36
39
  }
37
40
 
38
41
  // src/time.ts
@@ -61,7 +64,7 @@ function cachedGetter(getter) {
61
64
  }
62
65
  };
63
66
  }
64
- var RejectValue = class {
67
+ var SkipCaching = class {
65
68
  value;
66
69
  constructor(value) {
67
70
  this.value = value;
@@ -126,7 +129,7 @@ function createCache({
126
129
  return { value, timestamp: now, expiration: void 0 };
127
130
  }
128
131
  const utils = {
129
- reject: (value) => new RejectValue(value),
132
+ skipCaching: (value) => new SkipCaching(value),
130
133
  withExpiration: (value, expiration) => {
131
134
  return new WithExpiration(value, expiration);
132
135
  }
@@ -137,10 +140,10 @@ function createCache({
137
140
  const entry = cache.get(cacheKey);
138
141
  if (!entry || isExpired(entry, now)) {
139
142
  const value = val(utils);
140
- if (value instanceof RejectValue) {
143
+ if (value instanceof SkipCaching) {
141
144
  return value.value;
142
145
  }
143
- if (options?.rejectWhen?.(value)) {
146
+ if (options?.skipCachingWhen?.(value)) {
144
147
  return value;
145
148
  }
146
149
  const unwrappedValue = unwrapValue(value, now);
@@ -166,14 +169,14 @@ function createCache({
166
169
  return entry.value;
167
170
  }
168
171
  const promise = val(utils).then((result) => {
169
- if (result instanceof RejectValue) {
172
+ if (result instanceof SkipCaching) {
170
173
  const cacheValue = cache.get(cacheKey);
171
174
  if (cacheValue?.value === promise) {
172
175
  cache.delete(cacheKey);
173
176
  }
174
177
  return result.value;
175
178
  }
176
- if (options?.rejectWhen?.(result)) {
179
+ if (options?.skipCachingWhen?.(result)) {
177
180
  const cacheValue = cache.get(cacheKey);
178
181
  if (cacheValue?.value === promise) {
179
182
  cache.delete(cacheKey);
@@ -223,7 +226,7 @@ function createCache({
223
226
  },
224
227
  async setAsync(cacheKey, value) {
225
228
  const promise = value(utils).then((result) => {
226
- if (result instanceof RejectValue) {
229
+ if (result instanceof SkipCaching) {
227
230
  const cacheValue = cache.get(cacheKey);
228
231
  if (cacheValue?.value === promise) {
229
232
  cache.delete(cacheKey);
@@ -253,7 +256,7 @@ function createCache({
253
256
  }
254
257
  // Annotate the CommonJS export names for ESM import in node:
255
258
  0 && (module.exports = {
256
- RejectValue,
259
+ SkipCaching,
257
260
  WithExpiration,
258
261
  cachedGetter,
259
262
  createCache
package/dist/cache.d.cts CHANGED
@@ -20,7 +20,7 @@ type Options = {
20
20
  */
21
21
  expirationThrottle?: number;
22
22
  };
23
- declare class RejectValue<T> {
23
+ declare class SkipCaching<T> {
24
24
  value: T;
25
25
  constructor(value: T);
26
26
  }
@@ -34,7 +34,7 @@ declare class WithExpiration<T> {
34
34
  constructor(value: T, expiration: DurationObj);
35
35
  }
36
36
  type Utils<T> = {
37
- reject: (value: T) => RejectValue<T>;
37
+ skipCaching: (value: T) => SkipCaching<T>;
38
38
  /**
39
39
  * Create a new WithExpiration object with the given value and expiration time.
40
40
  * @param value - The value to store in the cache.
@@ -49,11 +49,11 @@ type GetOptions<T> = {
49
49
  * @param value The value to check
50
50
  * @returns true if the value should be rejected, false otherwise
51
51
  */
52
- rejectWhen?: (value: T) => boolean;
52
+ skipCachingWhen?: (value: T) => boolean;
53
53
  };
54
54
  type Cache<T> = {
55
- getOrInsert: (cacheKey: string, val: (utils: Utils<T>) => T | RejectValue<T>, options?: GetOptions<T>) => T;
56
- getOrInsertAsync: (cacheKey: string, val: (utils: Utils<T>) => Promise<T | RejectValue<T>>, options?: GetOptions<T>) => Promise<T>;
55
+ getOrInsert: (cacheKey: string, val: (utils: Utils<T>) => T | SkipCaching<T>, options?: GetOptions<T>) => T;
56
+ getOrInsertAsync: (cacheKey: string, val: (utils: Utils<T>) => Promise<T | SkipCaching<T>>, options?: GetOptions<T>) => Promise<T>;
57
57
  clear: () => void;
58
58
  get: (cacheKey: string) => T | undefined;
59
59
  set: (cacheKey: string, value: T | WithExpiration<T>) => void;
@@ -69,4 +69,4 @@ type Cache<T> = {
69
69
  };
70
70
  declare function createCache<T>({ maxCacheSize, maxItemAge, expirationThrottle, }?: Options): Cache<T>;
71
71
 
72
- export { type Cache, RejectValue, WithExpiration, cachedGetter, createCache };
72
+ export { type Cache, SkipCaching, WithExpiration, cachedGetter, createCache };
package/dist/cache.d.ts CHANGED
@@ -20,7 +20,7 @@ type Options = {
20
20
  */
21
21
  expirationThrottle?: number;
22
22
  };
23
- declare class RejectValue<T> {
23
+ declare class SkipCaching<T> {
24
24
  value: T;
25
25
  constructor(value: T);
26
26
  }
@@ -34,7 +34,7 @@ declare class WithExpiration<T> {
34
34
  constructor(value: T, expiration: DurationObj);
35
35
  }
36
36
  type Utils<T> = {
37
- reject: (value: T) => RejectValue<T>;
37
+ skipCaching: (value: T) => SkipCaching<T>;
38
38
  /**
39
39
  * Create a new WithExpiration object with the given value and expiration time.
40
40
  * @param value - The value to store in the cache.
@@ -49,11 +49,11 @@ type GetOptions<T> = {
49
49
  * @param value The value to check
50
50
  * @returns true if the value should be rejected, false otherwise
51
51
  */
52
- rejectWhen?: (value: T) => boolean;
52
+ skipCachingWhen?: (value: T) => boolean;
53
53
  };
54
54
  type Cache<T> = {
55
- getOrInsert: (cacheKey: string, val: (utils: Utils<T>) => T | RejectValue<T>, options?: GetOptions<T>) => T;
56
- getOrInsertAsync: (cacheKey: string, val: (utils: Utils<T>) => Promise<T | RejectValue<T>>, options?: GetOptions<T>) => Promise<T>;
55
+ getOrInsert: (cacheKey: string, val: (utils: Utils<T>) => T | SkipCaching<T>, options?: GetOptions<T>) => T;
56
+ getOrInsertAsync: (cacheKey: string, val: (utils: Utils<T>) => Promise<T | SkipCaching<T>>, options?: GetOptions<T>) => Promise<T>;
57
57
  clear: () => void;
58
58
  get: (cacheKey: string) => T | undefined;
59
59
  set: (cacheKey: string, value: T | WithExpiration<T>) => void;
@@ -69,4 +69,4 @@ type Cache<T> = {
69
69
  };
70
70
  declare function createCache<T>({ maxCacheSize, maxItemAge, expirationThrottle, }?: Options): Cache<T>;
71
71
 
72
- export { type Cache, RejectValue, WithExpiration, cachedGetter, createCache };
72
+ export { type Cache, SkipCaching, WithExpiration, cachedGetter, createCache };
package/dist/cache.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  durationObjToMs
3
- } from "./chunk-RK6PT7JY.js";
3
+ } from "./chunk-5MNYPLZI.js";
4
4
  import "./chunk-HTCYUMDR.js";
5
5
  import {
6
6
  isPromise
7
- } from "./chunk-4UGSP3L3.js";
8
- import "./chunk-GBFS2I67.js";
7
+ } from "./chunk-2TIVYE43.js";
8
+ import "./chunk-II4R3VVX.js";
9
9
 
10
10
  // src/cache.ts
11
11
  function cachedGetter(getter) {
@@ -17,7 +17,7 @@ function cachedGetter(getter) {
17
17
  }
18
18
  };
19
19
  }
20
- var RejectValue = class {
20
+ var SkipCaching = class {
21
21
  value;
22
22
  constructor(value) {
23
23
  this.value = value;
@@ -82,7 +82,7 @@ function createCache({
82
82
  return { value, timestamp: now, expiration: void 0 };
83
83
  }
84
84
  const utils = {
85
- reject: (value) => new RejectValue(value),
85
+ skipCaching: (value) => new SkipCaching(value),
86
86
  withExpiration: (value, expiration) => {
87
87
  return new WithExpiration(value, expiration);
88
88
  }
@@ -93,10 +93,10 @@ function createCache({
93
93
  const entry = cache.get(cacheKey);
94
94
  if (!entry || isExpired(entry, now)) {
95
95
  const value = val(utils);
96
- if (value instanceof RejectValue) {
96
+ if (value instanceof SkipCaching) {
97
97
  return value.value;
98
98
  }
99
- if (options?.rejectWhen?.(value)) {
99
+ if (options?.skipCachingWhen?.(value)) {
100
100
  return value;
101
101
  }
102
102
  const unwrappedValue = unwrapValue(value, now);
@@ -122,14 +122,14 @@ function createCache({
122
122
  return entry.value;
123
123
  }
124
124
  const promise = val(utils).then((result) => {
125
- if (result instanceof RejectValue) {
125
+ if (result instanceof SkipCaching) {
126
126
  const cacheValue = cache.get(cacheKey);
127
127
  if (cacheValue?.value === promise) {
128
128
  cache.delete(cacheKey);
129
129
  }
130
130
  return result.value;
131
131
  }
132
- if (options?.rejectWhen?.(result)) {
132
+ if (options?.skipCachingWhen?.(result)) {
133
133
  const cacheValue = cache.get(cacheKey);
134
134
  if (cacheValue?.value === promise) {
135
135
  cache.delete(cacheKey);
@@ -179,7 +179,7 @@ function createCache({
179
179
  },
180
180
  async setAsync(cacheKey, value) {
181
181
  const promise = value(utils).then((result) => {
182
- if (result instanceof RejectValue) {
182
+ if (result instanceof SkipCaching) {
183
183
  const cacheValue = cache.get(cacheKey);
184
184
  if (cacheValue?.value === promise) {
185
185
  cache.delete(cacheKey);
@@ -208,7 +208,7 @@ function createCache({
208
208
  };
209
209
  }
210
210
  export {
211
- RejectValue,
211
+ SkipCaching,
212
212
  WithExpiration,
213
213
  cachedGetter,
214
214
  createCache
@@ -29,11 +29,19 @@ function castToString(value) {
29
29
  return valueType === "string" || valueType === "number" || valueType === "boolean" || valueType === "bigint" ? String(value) : null;
30
30
  }
31
31
  function castToNumber(value) {
32
- return isNumeric(value) ? Number(value) : null;
32
+ return isFiniteNumeric(value) ? Number(value) : null;
33
33
  }
34
- function isNumeric(num) {
35
- const str = String(num);
36
- return !isNaN(str) && !isNaN(parseFloat(str));
34
+ function isFiniteNumeric(num) {
35
+ switch (typeof num) {
36
+ case "number":
37
+ return num - num === 0;
38
+ case "string":
39
+ return num.trim() !== "" && Number.isFinite(+num);
40
+ case "bigint":
41
+ return Number.isFinite(Number(num));
42
+ default:
43
+ return false;
44
+ }
37
45
  }
38
46
  // Annotate the CommonJS export names for ESM import in node:
39
47
  0 && (module.exports = {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  castToNumber,
3
3
  castToString
4
- } from "./chunk-GBFS2I67.js";
4
+ } from "./chunk-II4R3VVX.js";
5
5
  export {
6
6
  castToNumber,
7
7
  castToString
@@ -1,15 +1,15 @@
1
1
  // src/assertions.ts
2
2
  var undefErrMsg = "not undefined assertion failed";
3
3
  var nullishErrMsg = "not nullish assertion failed";
4
- function notUndefined(value) {
4
+ function notUndefined(value, message = undefErrMsg) {
5
5
  if (value === void 0) {
6
- throw new Error(undefErrMsg);
6
+ throw new Error(message);
7
7
  }
8
8
  return value;
9
9
  }
10
- function notNullish(value) {
10
+ function notNullish(value, message = nullishErrMsg) {
11
11
  if (value === void 0 || value === null) {
12
- throw new Error(nullishErrMsg);
12
+ throw new Error(message);
13
13
  }
14
14
  return value;
15
15
  }
@@ -38,7 +38,7 @@ function isFunction(value) {
38
38
  return typeof value === "function";
39
39
  }
40
40
  function isPromise(value) {
41
- return isObject(value) && "then" in value;
41
+ return isObject(value) && "then" in value && isFunction(value.then);
42
42
  }
43
43
  function isPlainObject(value) {
44
44
  if (!value || typeof value !== "object") return false;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  isFunction
3
- } from "./chunk-4UGSP3L3.js";
3
+ } from "./chunk-2TIVYE43.js";
4
4
 
5
5
  // src/enhancedMap.ts
6
6
  var enhancedMapReject = Symbol();
@@ -2,10 +2,12 @@ import {
2
2
  safeJsonStringify
3
3
  } from "./chunk-VAAMRG4K.js";
4
4
  import {
5
- isObject
6
- } from "./chunk-4UGSP3L3.js";
5
+ isFunction,
6
+ isObject,
7
+ isPromise
8
+ } from "./chunk-2TIVYE43.js";
7
9
 
8
- // src/rsResult.ts
10
+ // src/tsResult.ts
9
11
  function okUnwrapOr() {
10
12
  return this.value;
11
13
  }
@@ -24,28 +26,40 @@ function mapOkAndErr({
24
26
  function returnResult() {
25
27
  return this;
26
28
  }
29
+ function okOnOk(fn) {
30
+ if (this.ok) {
31
+ fn(this.value);
32
+ }
33
+ return this;
34
+ }
35
+ function errOnErr(fn) {
36
+ if (!this.ok) {
37
+ fn(this.error);
38
+ }
39
+ return this;
40
+ }
27
41
  function ok(value = void 0) {
28
- return {
29
- ok: true,
30
- error: false,
31
- value,
42
+ const methods = {
32
43
  unwrapOrNull: okUnwrapOr,
33
44
  unwrapOr: okUnwrapOr,
34
45
  unwrap: okUnwrapOr,
35
46
  mapOk: okMap,
36
47
  mapErr: returnResult,
37
- mapOkAndErr
48
+ mapOkAndErr,
49
+ ifOk: okOnOk,
50
+ ifErr: returnResult
51
+ };
52
+ return {
53
+ ok: true,
54
+ error: false,
55
+ value,
56
+ ...methods
38
57
  };
39
58
  }
40
59
  function err(error) {
41
- return {
42
- ok: false,
43
- error,
60
+ const methods = {
44
61
  unwrapOrNull: () => null,
45
62
  unwrapOr: (defaultValue) => defaultValue,
46
- errorResult() {
47
- return err(error);
48
- },
49
63
  unwrap: () => {
50
64
  if (error instanceof Error) {
51
65
  throw error;
@@ -54,7 +68,17 @@ function err(error) {
54
68
  },
55
69
  mapOk: returnResult,
56
70
  mapErr: errMap,
57
- mapOkAndErr
71
+ mapOkAndErr,
72
+ ifOk: returnResult,
73
+ ifErr: errOnErr
74
+ };
75
+ return {
76
+ ok: false,
77
+ error,
78
+ errorResult() {
79
+ return err(error);
80
+ },
81
+ ...methods
58
82
  };
59
83
  }
60
84
  function unknownToResultError(error) {
@@ -94,20 +118,27 @@ var Result = {
94
118
  err,
95
119
  unknownToError: unknownToResultError,
96
120
  asyncUnwrap,
97
- asyncMap
121
+ asyncMap,
122
+ getOkErr
98
123
  };
99
124
  function resultify(fn, errorNormalizer) {
100
- try {
101
- return ok(fn());
102
- } catch (error) {
103
- return err(
104
- errorNormalizer ? errorNormalizer(error) : unknownToError(error)
125
+ if (!isFunction(fn)) {
126
+ return fn.then((value) => ok(value)).catch(
127
+ (error) => err(
128
+ errorNormalizer ? errorNormalizer(error) : unknownToError(error)
129
+ )
105
130
  );
106
131
  }
107
- }
108
- async function asyncResultify(fn, errorNormalizer) {
109
132
  try {
110
- return ok(await fn());
133
+ const result = fn();
134
+ if (isPromise(result)) {
135
+ return result.then((value) => ok(value)).catch(
136
+ (error) => err(
137
+ errorNormalizer ? errorNormalizer(error) : unknownToError(error)
138
+ )
139
+ );
140
+ }
141
+ return ok(result);
111
142
  } catch (error) {
112
143
  return err(
113
144
  errorNormalizer ? errorNormalizer(error) : unknownToError(error)
@@ -129,23 +160,21 @@ function unknownToError(error) {
129
160
  cause: error
130
161
  });
131
162
  }
132
- function normalizeError(error) {
133
- return unknownToError(error);
134
- }
135
- var safeJsonStringify2 = safeJsonStringify;
136
- function createTypedResult() {
137
- return {
138
- ok,
139
- err
140
- };
163
+ var typedResult = {
164
+ ok,
165
+ err,
166
+ get _type() {
167
+ throw new Error("usage as value is not allowed");
168
+ }
169
+ };
170
+ function getOkErr() {
171
+ return typedResult;
141
172
  }
142
173
 
143
174
  export {
175
+ ok,
176
+ err,
144
177
  Result,
145
178
  resultify,
146
- asyncResultify,
147
- unknownToError,
148
- normalizeError,
149
- safeJsonStringify2 as safeJsonStringify,
150
- createTypedResult
179
+ unknownToError
151
180
  };
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-HTCYUMDR.js";
4
4
  import {
5
5
  castToNumber
6
- } from "./chunk-GBFS2I67.js";
6
+ } from "./chunk-II4R3VVX.js";
7
7
 
8
8
  // src/time.ts
9
9
  var MINUTE_AS_MS = 60 * 1e3;
@@ -0,0 +1,25 @@
1
+ // src/castValues.ts
2
+ function castToString(value) {
3
+ const valueType = typeof value;
4
+ return valueType === "string" || valueType === "number" || valueType === "boolean" || valueType === "bigint" ? String(value) : null;
5
+ }
6
+ function castToNumber(value) {
7
+ return isFiniteNumeric(value) ? Number(value) : null;
8
+ }
9
+ function isFiniteNumeric(num) {
10
+ switch (typeof num) {
11
+ case "number":
12
+ return num - num === 0;
13
+ case "string":
14
+ return num.trim() !== "" && Number.isFinite(+num);
15
+ case "bigint":
16
+ return Number.isFinite(Number(num));
17
+ default:
18
+ return false;
19
+ }
20
+ }
21
+
22
+ export {
23
+ castToString,
24
+ castToNumber
25
+ };
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  EnhancedMap
3
- } from "./chunk-T5WDDPFI.js";
3
+ } from "./chunk-4DCLNY64.js";
4
4
  import {
5
5
  durationObjToMs
6
- } from "./chunk-RK6PT7JY.js";
6
+ } from "./chunk-5MNYPLZI.js";
7
7
  import "./chunk-HTCYUMDR.js";
8
- import "./chunk-4UGSP3L3.js";
9
- import "./chunk-GBFS2I67.js";
8
+ import "./chunk-2TIVYE43.js";
9
+ import "./chunk-II4R3VVX.js";
10
10
 
11
11
  // src/createThrottleController.ts
12
12
  function createThrottleController({
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  EnhancedMap,
3
3
  enhancedMapReject
4
- } from "./chunk-T5WDDPFI.js";
5
- import "./chunk-4UGSP3L3.js";
4
+ } from "./chunk-4DCLNY64.js";
5
+ import "./chunk-2TIVYE43.js";
6
6
  export {
7
7
  EnhancedMap,
8
8
  enhancedMapReject
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/exhaustiveMatch.ts
21
21
  var exhaustiveMatch_exports = {};
22
22
  __export(exhaustiveMatch_exports, {
23
- exhaustiveMatch: () => exhaustiveMatch
23
+ exhaustiveMatch: () => exhaustiveMatch,
24
+ exhaustiveMatchObjUnion: () => exhaustiveMatchObjUnion
24
25
  });
25
26
  module.exports = __toCommonJS(exhaustiveMatch_exports);
26
27
  function exhaustiveMatch(value) {
@@ -49,7 +50,17 @@ function exhaustiveMatch(value) {
49
50
  withObject
50
51
  };
51
52
  }
53
+ function exhaustiveMatchObjUnion(obj, key) {
54
+ function withLazy(pattern) {
55
+ const result = pattern[obj[key]];
56
+ if (typeof result === "function")
57
+ return result(obj);
58
+ throw new Error(`Exhaustive match failed: no match for ${obj[key]}`);
59
+ }
60
+ return { with: withLazy };
61
+ }
52
62
  // Annotate the CommonJS export names for ESM import in node:
53
63
  0 && (module.exports = {
54
- exhaustiveMatch
64
+ exhaustiveMatch,
65
+ exhaustiveMatchObjUnion
55
66
  });
@@ -2,5 +2,8 @@ declare function exhaustiveMatch<T extends string>(value: T): {
2
2
  with: <R>(pattern: { [K in T]: "_nxt" | "_never" | (() => R); }) => R;
3
3
  withObject: <R>(pattern: Record<T, R>) => R;
4
4
  };
5
+ declare function exhaustiveMatchObjUnion<T extends Record<string, unknown>, D extends keyof T, K extends T[D] & string>(obj: T, key: D): {
6
+ with: <R>(pattern: { [P in K]: "_never" | ((props: Extract<T, Record<D, P>>) => R); }) => R;
7
+ };
5
8
 
6
- export { exhaustiveMatch };
9
+ export { exhaustiveMatch, exhaustiveMatchObjUnion };
@@ -2,5 +2,8 @@ declare function exhaustiveMatch<T extends string>(value: T): {
2
2
  with: <R>(pattern: { [K in T]: "_nxt" | "_never" | (() => R); }) => R;
3
3
  withObject: <R>(pattern: Record<T, R>) => R;
4
4
  };
5
+ declare function exhaustiveMatchObjUnion<T extends Record<string, unknown>, D extends keyof T, K extends T[D] & string>(obj: T, key: D): {
6
+ with: <R>(pattern: { [P in K]: "_never" | ((props: Extract<T, Record<D, P>>) => R); }) => R;
7
+ };
5
8
 
6
- export { exhaustiveMatch };
9
+ export { exhaustiveMatch, exhaustiveMatchObjUnion };
@@ -25,6 +25,16 @@ function exhaustiveMatch(value) {
25
25
  withObject
26
26
  };
27
27
  }
28
+ function exhaustiveMatchObjUnion(obj, key) {
29
+ function withLazy(pattern) {
30
+ const result = pattern[obj[key]];
31
+ if (typeof result === "function")
32
+ return result(obj);
33
+ throw new Error(`Exhaustive match failed: no match for ${obj[key]}`);
34
+ }
35
+ return { with: withLazy };
36
+ }
28
37
  export {
29
- exhaustiveMatch
38
+ exhaustiveMatch,
39
+ exhaustiveMatchObjUnion
30
40
  };