@ls-stack/utils 1.13.2 → 2.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.
Files changed (140) hide show
  1. package/dist/arrayUtils.cjs +91 -0
  2. package/dist/arrayUtils.d.cts +51 -0
  3. package/dist/arrayUtils.js +1 -2
  4. package/dist/assertions.cjs +99 -0
  5. package/dist/assertions.d.cts +17 -0
  6. package/dist/assertions.js +1 -2
  7. package/dist/castValues.cjs +41 -0
  8. package/dist/castValues.d.cts +4 -0
  9. package/dist/castValues.js +0 -1
  10. package/dist/chunk-3PXKYWJF.js +148 -0
  11. package/dist/{chunk-FYMTZQ42.js → chunk-4UGSP3L3.js} +0 -1
  12. package/dist/{chunk-HLFWWIDK.js → chunk-5DZT3Z5Z.js} +0 -1
  13. package/dist/{chunk-W7X6NSGR.js → chunk-AZBBTE33.js} +0 -1
  14. package/dist/{chunk-MMKMF4GG.js → chunk-IATIXMCE.js} +0 -1
  15. package/dist/{chunk-M74KKYE4.js → chunk-KCOXGSRA.js} +0 -1
  16. package/dist/{chunk-NKCC3375.js → chunk-NWXBMMHO.js} +0 -1
  17. package/dist/{chunk-SNAAKCTH.js → chunk-RVVH3MDA.js} +0 -1
  18. package/dist/{chunk-4QK76IRX.js → chunk-T5WDDPFI.js} +1 -6
  19. package/dist/{chunk-GLZ5MZC5.js → chunk-V2L472LS.js} +0 -30
  20. package/dist/consoleFmt.cjs +84 -0
  21. package/dist/consoleFmt.d.cts +48 -0
  22. package/dist/consoleFmt.js +0 -1
  23. package/dist/conversions.cjs +44 -0
  24. package/dist/conversions.d.cts +3 -0
  25. package/dist/conversions.js +1 -2
  26. package/dist/createThrottleController.cjs +183 -0
  27. package/dist/createThrottleController.d.cts +16 -0
  28. package/dist/createThrottleController.js +2 -3
  29. package/dist/debounce.cjs +125 -0
  30. package/dist/debounce.d.cts +45 -0
  31. package/dist/debounce.js +0 -1
  32. package/dist/dedent.cjs +57 -0
  33. package/dist/dedent.d.cts +4 -0
  34. package/dist/dedent.js +0 -1
  35. package/dist/deepEqual.cjs +88 -0
  36. package/dist/deepEqual.d.cts +4 -0
  37. package/dist/deepEqual.js +1 -2
  38. package/dist/enhancedMap.cjs +128 -0
  39. package/dist/enhancedMap.d.cts +20 -0
  40. package/dist/enhancedMap.d.ts +0 -2
  41. package/dist/enhancedMap.js +2 -3
  42. package/dist/exhaustiveMatch.cjs +55 -0
  43. package/dist/exhaustiveMatch.d.cts +6 -0
  44. package/dist/exhaustiveMatch.js +0 -1
  45. package/dist/interpolate.cjs +88 -0
  46. package/dist/interpolate.d.cts +11 -0
  47. package/dist/interpolate.js +2 -3
  48. package/dist/levenshtein.cjs +180 -0
  49. package/dist/levenshtein.d.cts +5 -0
  50. package/dist/levenshtein.js +0 -1
  51. package/dist/main.cjs +4 -0
  52. package/dist/main.d.cts +2 -0
  53. package/dist/main.d.ts +1 -1
  54. package/dist/main.js +0 -1
  55. package/dist/mathUtils.cjs +50 -0
  56. package/dist/mathUtils.d.cts +6 -0
  57. package/dist/mathUtils.js +1 -2
  58. package/dist/objUtils.cjs +67 -0
  59. package/dist/objUtils.d.cts +7 -0
  60. package/dist/objUtils.js +1 -2
  61. package/dist/parallelAsyncCalls.cjs +266 -0
  62. package/dist/{parallelAsyncResultCalls.d.ts → parallelAsyncCalls.d.cts} +7 -7
  63. package/dist/parallelAsyncCalls.d.ts +76 -0
  64. package/dist/{parallelAsyncResultCalls.js → parallelAsyncCalls.js} +7 -9
  65. package/dist/promiseUtils.cjs +38 -0
  66. package/dist/promiseUtils.d.cts +8 -0
  67. package/dist/promiseUtils.js +0 -1
  68. package/dist/rsResult.cjs +180 -0
  69. package/dist/rsResult.d.cts +83 -0
  70. package/dist/rsResult.d.ts +34 -69
  71. package/dist/rsResult.js +6 -10
  72. package/dist/runShellCmd.cjs +127 -0
  73. package/dist/runShellCmd.d.cts +23 -0
  74. package/dist/runShellCmd.d.ts +2 -1
  75. package/dist/runShellCmd.js +9 -4
  76. package/dist/shallowEqual.cjs +88 -0
  77. package/dist/shallowEqual.d.cts +4 -0
  78. package/dist/shallowEqual.js +0 -1
  79. package/dist/sleep.cjs +32 -0
  80. package/dist/sleep.d.cts +3 -0
  81. package/dist/sleep.js +1 -2
  82. package/dist/stringUtils.cjs +66 -0
  83. package/dist/stringUtils.d.cts +16 -0
  84. package/dist/stringUtils.d.ts +1 -3
  85. package/dist/stringUtils.js +1 -4
  86. package/dist/testUtils.cjs +357 -0
  87. package/dist/testUtils.d.cts +38 -0
  88. package/dist/testUtils.js +5 -6
  89. package/dist/typingFnUtils.cjs +55 -0
  90. package/dist/typingFnUtils.d.cts +15 -0
  91. package/dist/typingFnUtils.js +0 -1
  92. package/dist/typingTestUtils.cjs +43 -0
  93. package/dist/typingTestUtils.d.cts +12 -0
  94. package/dist/typingTestUtils.js +0 -1
  95. package/dist/typingUtils.cjs +18 -0
  96. package/dist/typingUtils.d.cts +11 -0
  97. package/dist/typingUtils.js +0 -1
  98. package/dist/yamlStringify.cjs +346 -0
  99. package/dist/yamlStringify.d.cts +8 -0
  100. package/dist/yamlStringify.js +3 -4
  101. package/package.json +64 -34
  102. package/dist/arrayUtils.js.map +0 -1
  103. package/dist/assertions.js.map +0 -1
  104. package/dist/castValues.js.map +0 -1
  105. package/dist/chunk-4QK76IRX.js.map +0 -1
  106. package/dist/chunk-FYMTZQ42.js.map +0 -1
  107. package/dist/chunk-GLZ5MZC5.js.map +0 -1
  108. package/dist/chunk-HLFWWIDK.js.map +0 -1
  109. package/dist/chunk-I7ZDKDUM.js +0 -217
  110. package/dist/chunk-I7ZDKDUM.js.map +0 -1
  111. package/dist/chunk-M74KKYE4.js.map +0 -1
  112. package/dist/chunk-MMKMF4GG.js.map +0 -1
  113. package/dist/chunk-NKCC3375.js.map +0 -1
  114. package/dist/chunk-SNAAKCTH.js.map +0 -1
  115. package/dist/chunk-W7X6NSGR.js.map +0 -1
  116. package/dist/consoleFmt.js.map +0 -1
  117. package/dist/conversions.js.map +0 -1
  118. package/dist/createThrottleController.js.map +0 -1
  119. package/dist/debounce.js.map +0 -1
  120. package/dist/dedent.js.map +0 -1
  121. package/dist/deepEqual.js.map +0 -1
  122. package/dist/enhancedMap.js.map +0 -1
  123. package/dist/exhaustiveMatch.js.map +0 -1
  124. package/dist/interpolate.js.map +0 -1
  125. package/dist/levenshtein.js.map +0 -1
  126. package/dist/main.js.map +0 -1
  127. package/dist/mathUtils.js.map +0 -1
  128. package/dist/objUtils.js.map +0 -1
  129. package/dist/parallelAsyncResultCalls.js.map +0 -1
  130. package/dist/promiseUtils.js.map +0 -1
  131. package/dist/rsResult.js.map +0 -1
  132. package/dist/runShellCmd.js.map +0 -1
  133. package/dist/shallowEqual.js.map +0 -1
  134. package/dist/sleep.js.map +0 -1
  135. package/dist/stringUtils.js.map +0 -1
  136. package/dist/testUtils.js.map +0 -1
  137. package/dist/typingFnUtils.js.map +0 -1
  138. package/dist/typingTestUtils.js.map +0 -1
  139. package/dist/typingUtils.js.map +0 -1
  140. package/dist/yamlStringify.js.map +0 -1
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/arrayUtils.ts
21
+ var arrayUtils_exports = {};
22
+ __export(arrayUtils_exports, {
23
+ arrayWithPrev: () => arrayWithPrev,
24
+ arrayWithPrevAndIndex: () => arrayWithPrevAndIndex,
25
+ filterAndMap: () => filterAndMap,
26
+ isInArray: () => isInArray,
27
+ sortBy: () => sortBy
28
+ });
29
+ module.exports = __toCommonJS(arrayUtils_exports);
30
+ function filterAndMap(array, mapFilter) {
31
+ const result = [];
32
+ let i = -1;
33
+ for (const item of array) {
34
+ i += 1;
35
+ const filterResult = mapFilter(item, i);
36
+ if (filterResult !== false) {
37
+ result.push(filterResult);
38
+ }
39
+ }
40
+ return result;
41
+ }
42
+ function sortBy(arr, sortByValue, props = "asc") {
43
+ const order = Array.isArray(props) || typeof props === "string" ? props : props.order ?? "asc";
44
+ return [...arr].sort((a, b) => {
45
+ const _aPriority = sortByValue(a);
46
+ const _bPriority = sortByValue(b);
47
+ const aPriority = Array.isArray(_aPriority) ? _aPriority : [_aPriority];
48
+ const bPriority = Array.isArray(_bPriority) ? _bPriority : [_bPriority];
49
+ for (let i = 0; i < aPriority.length; i++) {
50
+ const levelOrder = typeof order === "string" ? order : order[i] ?? "asc";
51
+ const aP = aPriority[i] ?? 0;
52
+ const bP = bPriority[i] ?? 0;
53
+ if (aP === bP) {
54
+ continue;
55
+ }
56
+ if (bP === Infinity || aP === -Infinity || aP < bP) {
57
+ return levelOrder === "asc" ? -1 : 1;
58
+ }
59
+ if (aP === Infinity || bP === -Infinity || aP > bP) {
60
+ return levelOrder === "asc" ? 1 : -1;
61
+ }
62
+ }
63
+ return 0;
64
+ });
65
+ }
66
+ function arrayWithPrev(array) {
67
+ return array.map((item, i) => [item, array[i - 1] ?? null]);
68
+ }
69
+ function arrayWithPrevAndIndex(array) {
70
+ return array.map((item, i) => ({
71
+ item,
72
+ prev: array[i - 1] ?? null,
73
+ index: i
74
+ }));
75
+ }
76
+ function isInArray(value, oneOf) {
77
+ for (let i = 0; i < oneOf.length; i++) {
78
+ if (oneOf[i] === value) {
79
+ return true;
80
+ }
81
+ }
82
+ return false;
83
+ }
84
+ // Annotate the CommonJS export names for ESM import in node:
85
+ 0 && (module.exports = {
86
+ arrayWithPrev,
87
+ arrayWithPrevAndIndex,
88
+ filterAndMap,
89
+ isInArray,
90
+ sortBy
91
+ });
@@ -0,0 +1,51 @@
1
+ /**
2
+ * allow to filter and map with better typing ergonomics
3
+ *
4
+ * In the `mapFilter` function return `false` to reject the item, or any other
5
+ * value to map it.
6
+ *
7
+ * @example
8
+ * // Filter reject and turn value into `value mapped`
9
+ * const items = ['value', 'value', 'reject', 'reject'];
10
+ *
11
+ * const mappedItems = filterAndMap(items, (item) =>
12
+ * item === 'reject'
13
+ * ? false
14
+ * : `${item} mapped`,
15
+ * );
16
+ *
17
+ * mappedItems; // ['value mapped', 'value mapped']
18
+ */
19
+ declare function filterAndMap<T, R>(array: IterableIterator<T> | readonly T[], mapFilter: (item: T, index: number) => false | R): R[];
20
+ type FilterAndMapReturn<T> = false | T;
21
+ type SortOrder = 'desc' | 'asc';
22
+ /**
23
+ * Sort an array based on a value
24
+ *
25
+ * Sort by `ascending` order by default
26
+ *
27
+ * Use `Infinity` as as wildcard to absolute max and min values
28
+ *
29
+ * @example
30
+ * const items = [1, 3, 2, 4];
31
+ *
32
+ * const sortedItems = sortBy(items, (item) => item);
33
+ * // [1, 2, 3, 4]
34
+ *
35
+ * const items2 = [{ a: 1, b: 2 }, { a: 2, b: 1 }, { a: 1, b: 1}]
36
+ *
37
+ * // return a array to sort by multiple values
38
+ * const sortedItems = sortBy(items, (item) => [item.a, item.b]);
39
+ **/
40
+ declare function sortBy<T>(arr: T[], sortByValue: (item: T) => (number | string)[] | number | string, props?: {
41
+ order?: SortOrder | SortOrder[];
42
+ } | SortOrder | SortOrder[]): T[];
43
+ declare function arrayWithPrev<T>(array: T[]): [current: T, prev: T | null][];
44
+ declare function arrayWithPrevAndIndex<T>(array: T[]): {
45
+ item: T;
46
+ prev: T | null;
47
+ index: number;
48
+ }[];
49
+ declare function isInArray<T, const U extends T>(value: T, oneOf: readonly U[]): value is U;
50
+
51
+ export { type FilterAndMapReturn, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, isInArray, sortBy };
@@ -4,7 +4,7 @@ import {
4
4
  filterAndMap,
5
5
  isInArray,
6
6
  sortBy
7
- } from "./chunk-W7X6NSGR.js";
7
+ } from "./chunk-AZBBTE33.js";
8
8
  export {
9
9
  arrayWithPrev,
10
10
  arrayWithPrevAndIndex,
@@ -12,4 +12,3 @@ export {
12
12
  isInArray,
13
13
  sortBy
14
14
  };
15
- //# sourceMappingURL=arrayUtils.js.map
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/assertions.ts
21
+ var assertions_exports = {};
22
+ __export(assertions_exports, {
23
+ assertIsNotNullish: () => assertIsNotNullish,
24
+ assertIsNotUndefined: () => assertIsNotUndefined,
25
+ exhaustiveCheck: () => exhaustiveCheck,
26
+ invariant: () => invariant,
27
+ isFunction: () => isFunction,
28
+ isObject: () => isObject,
29
+ isPlainObject: () => isPlainObject,
30
+ isPromise: () => isPromise,
31
+ notNullish: () => notNullish,
32
+ notUndefined: () => notUndefined
33
+ });
34
+ module.exports = __toCommonJS(assertions_exports);
35
+ var undefErrMsg = "not undefined assertion failed";
36
+ var nullishErrMsg = "not nullish assertion failed";
37
+ function notUndefined(value) {
38
+ if (value === void 0) {
39
+ throw new Error(undefErrMsg);
40
+ }
41
+ return value;
42
+ }
43
+ function notNullish(value) {
44
+ if (value === void 0 || value === null) {
45
+ throw new Error(nullishErrMsg);
46
+ }
47
+ return value;
48
+ }
49
+ function assertIsNotNullish(value, errorMsg = nullishErrMsg) {
50
+ if (value === void 0 || value === null) {
51
+ throw new Error(errorMsg);
52
+ }
53
+ }
54
+ function assertIsNotUndefined(value, errorMsg = undefErrMsg) {
55
+ if (value === void 0) {
56
+ throw new Error(errorMsg);
57
+ }
58
+ }
59
+ function invariant(condition, errorMsg = "Invariant violation") {
60
+ if (!condition) {
61
+ throw new Error(`Invariant violation: ${errorMsg}`);
62
+ }
63
+ }
64
+ function exhaustiveCheck(narrowedType) {
65
+ return new Error("This should never happen");
66
+ }
67
+ function isObject(value) {
68
+ return typeof value === "object" && value !== null && !Array.isArray(value);
69
+ }
70
+ function isFunction(value) {
71
+ return typeof value === "function";
72
+ }
73
+ function isPromise(value) {
74
+ return isObject(value) && "then" in value;
75
+ }
76
+ function isPlainObject(value) {
77
+ if (!value || typeof value !== "object") return false;
78
+ const proto = Object.getPrototypeOf(value);
79
+ if (proto === null) {
80
+ return true;
81
+ }
82
+ const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
83
+ if (Ctor === Object) return true;
84
+ const objectCtorString = Object.prototype.constructor.toString();
85
+ return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
86
+ }
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ assertIsNotNullish,
90
+ assertIsNotUndefined,
91
+ exhaustiveCheck,
92
+ invariant,
93
+ isFunction,
94
+ isObject,
95
+ isPlainObject,
96
+ isPromise,
97
+ notNullish,
98
+ notUndefined
99
+ });
@@ -0,0 +1,17 @@
1
+ type NotUndefined<T> = T extends undefined ? never : T;
2
+ type StrictNonUndefined<T, N = unknown> = undefined extends T ? NotUndefined<T> : N;
3
+ declare function notUndefined<T>(value: T): StrictNonUndefined<T>;
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>;
6
+ declare function assertIsNotNullish<T>(value: T, errorMsg?: string): asserts value is StrictNonNullable<T, never>;
7
+ declare function assertIsNotUndefined<T>(value: T, errorMsg?: string): asserts value is StrictNonUndefined<T, never>;
8
+ /** Use this function to assert that a certain condition is always true. */
9
+ declare function invariant(condition: any, errorMsg?: string): asserts condition;
10
+ /** ensures all type possibilities are being handled */
11
+ declare function exhaustiveCheck<Except = never>(narrowedType: NoInfer<Except>): Error;
12
+ declare function isObject(value: unknown): value is Record<string, unknown>;
13
+ declare function isFunction(value: unknown): value is (...args: any[]) => any;
14
+ declare function isPromise(value: unknown): value is Promise<unknown>;
15
+ declare function isPlainObject(value: any): value is Record<string, unknown>;
16
+
17
+ export { assertIsNotNullish, assertIsNotUndefined, exhaustiveCheck, invariant, isFunction, isObject, isPlainObject, isPromise, notNullish, notUndefined };
@@ -9,7 +9,7 @@ import {
9
9
  isPromise,
10
10
  notNullish,
11
11
  notUndefined
12
- } from "./chunk-FYMTZQ42.js";
12
+ } from "./chunk-4UGSP3L3.js";
13
13
  export {
14
14
  assertIsNotNullish,
15
15
  assertIsNotUndefined,
@@ -22,4 +22,3 @@ export {
22
22
  notNullish,
23
23
  notUndefined
24
24
  };
25
- //# sourceMappingURL=assertions.js.map
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/castValues.ts
21
+ var castValues_exports = {};
22
+ __export(castValues_exports, {
23
+ castToNumber: () => castToNumber,
24
+ castToString: () => castToString
25
+ });
26
+ module.exports = __toCommonJS(castValues_exports);
27
+ function castToString(value) {
28
+ return value !== null && value !== void 0 ? String(value) : null;
29
+ }
30
+ function castToNumber(value) {
31
+ return isNumeric(value) ? Number(value) : null;
32
+ }
33
+ function isNumeric(num) {
34
+ const str = String(num);
35
+ return !isNaN(str) && !isNaN(parseFloat(str));
36
+ }
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ castToNumber,
40
+ castToString
41
+ });
@@ -0,0 +1,4 @@
1
+ declare function castToString(value: unknown): string | null;
2
+ declare function castToNumber(value: unknown): number | null;
3
+
4
+ export { castToNumber, castToString };
@@ -13,4 +13,3 @@ export {
13
13
  castToNumber,
14
14
  castToString
15
15
  };
16
- //# sourceMappingURL=castValues.js.map
@@ -0,0 +1,148 @@
1
+ import {
2
+ isObject
3
+ } from "./chunk-4UGSP3L3.js";
4
+
5
+ // src/rsResult.ts
6
+ function okUnwrapOr() {
7
+ return this.value;
8
+ }
9
+ function okMap(mapFn) {
10
+ return this.ok ? ok(mapFn(this.value)) : this;
11
+ }
12
+ function errMap(mapFn) {
13
+ return this.ok ? this : err(mapFn(this.error));
14
+ }
15
+ function mapOkAndErr({
16
+ ok: mapFn,
17
+ err: mapErrFn
18
+ }) {
19
+ return this.ok ? ok(mapFn(this.value)) : err(mapErrFn(this.error));
20
+ }
21
+ function returnResult() {
22
+ return this;
23
+ }
24
+ function ok(value = void 0) {
25
+ return {
26
+ ok: true,
27
+ error: false,
28
+ value,
29
+ unwrapOrNull: okUnwrapOr,
30
+ unwrapOr: okUnwrapOr,
31
+ unwrap: okUnwrapOr,
32
+ mapOk: okMap,
33
+ mapErr: returnResult,
34
+ mapOkAndErr
35
+ };
36
+ }
37
+ function err(error) {
38
+ return {
39
+ ok: false,
40
+ error,
41
+ unwrapOrNull: () => null,
42
+ unwrapOr: (defaultValue) => defaultValue,
43
+ errorResult() {
44
+ return err(error);
45
+ },
46
+ unwrap: () => {
47
+ if (error instanceof Error) {
48
+ throw error;
49
+ }
50
+ throw normalizeError(error);
51
+ },
52
+ mapOk: returnResult,
53
+ mapErr: errMap,
54
+ mapOkAndErr
55
+ };
56
+ }
57
+ function unknownToError(error) {
58
+ return err(normalizeError(error));
59
+ }
60
+ async function asyncUnwrap(result) {
61
+ const unwrapped = await result;
62
+ if (unwrapped.ok) {
63
+ return unwrapped.value;
64
+ }
65
+ if (unwrapped.error instanceof Error) {
66
+ throw unwrapped.error;
67
+ }
68
+ throw normalizeError(unwrapped.error);
69
+ }
70
+ function asyncMap(resultPromise) {
71
+ return {
72
+ err: async (mapFn) => {
73
+ const result = await resultPromise;
74
+ return result.ok ? ok(result.value) : err(mapFn(result.error));
75
+ },
76
+ ok: async (mapFn) => {
77
+ const result = await resultPromise;
78
+ return result.ok ? ok(mapFn(result.value)) : err(result.error);
79
+ },
80
+ okAndErr: async ({
81
+ ok: mapFn,
82
+ err: mapErrFn
83
+ }) => {
84
+ const result = await resultPromise;
85
+ return result.ok ? ok(mapFn(result.value)) : err(mapErrFn(result.error));
86
+ }
87
+ };
88
+ }
89
+ var Result = {
90
+ ok,
91
+ err,
92
+ unknownToError,
93
+ asyncUnwrap,
94
+ asyncMap
95
+ };
96
+ function resultify(fn, errorNormalizer) {
97
+ try {
98
+ return ok(fn());
99
+ } catch (error) {
100
+ return err(
101
+ errorNormalizer ? errorNormalizer(error) : normalizeError(error)
102
+ );
103
+ }
104
+ }
105
+ async function asyncResultify(fn, errorNormalizer) {
106
+ try {
107
+ return ok(await fn());
108
+ } catch (error) {
109
+ return err(
110
+ errorNormalizer ? errorNormalizer(error) : normalizeError(error)
111
+ );
112
+ }
113
+ }
114
+ function normalizeError(error) {
115
+ if (error instanceof Error) return error;
116
+ if (typeof error === "string") {
117
+ return new Error(error);
118
+ }
119
+ if (isObject(error)) {
120
+ return new Error(
121
+ "message" in error && error.message && typeof error.message === "string" ? error.message : safeJsonStringify(error) ?? "unknown",
122
+ { cause: error }
123
+ );
124
+ }
125
+ return new Error(safeJsonStringify(error) ?? "unknown", { cause: error });
126
+ }
127
+ function safeJsonStringify(value) {
128
+ try {
129
+ return JSON.stringify(value);
130
+ } catch (_) {
131
+ return null;
132
+ }
133
+ }
134
+ function createTypedResult() {
135
+ return {
136
+ ok,
137
+ err
138
+ };
139
+ }
140
+
141
+ export {
142
+ Result,
143
+ resultify,
144
+ asyncResultify,
145
+ normalizeError,
146
+ safeJsonStringify,
147
+ createTypedResult
148
+ };
@@ -64,4 +64,3 @@ export {
64
64
  isPromise,
65
65
  isPlainObject
66
66
  };
67
- //# sourceMappingURL=chunk-FYMTZQ42.js.map
@@ -6,4 +6,3 @@ function sleep(ms) {
6
6
  export {
7
7
  sleep
8
8
  };
9
- //# sourceMappingURL=chunk-HLFWWIDK.js.map
@@ -61,4 +61,3 @@ export {
61
61
  arrayWithPrevAndIndex,
62
62
  isInArray
63
63
  };
64
- //# sourceMappingURL=chunk-W7X6NSGR.js.map
@@ -18,4 +18,3 @@ function bytesToHumanReadable(bytes) {
18
18
  export {
19
19
  bytesToHumanReadable
20
20
  };
21
- //# sourceMappingURL=chunk-MMKMF4GG.js.map
@@ -62,4 +62,3 @@ function deepEqual(foo, bar) {
62
62
  export {
63
63
  deepEqual
64
64
  };
65
- //# sourceMappingURL=chunk-M74KKYE4.js.map
@@ -21,4 +21,3 @@ export {
21
21
  clampRange,
22
22
  clamp
23
23
  };
24
- //# sourceMappingURL=chunk-NKCC3375.js.map
@@ -37,4 +37,3 @@ export {
37
37
  mapObjectToObject,
38
38
  omit
39
39
  };
40
- //# sourceMappingURL=chunk-SNAAKCTH.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  isFunction
3
- } from "./chunk-FYMTZQ42.js";
3
+ } from "./chunk-4UGSP3L3.js";
4
4
 
5
5
  // src/enhancedMap.ts
6
6
  var enhancedMapReject = Symbol();
@@ -73,10 +73,6 @@ var EnhancedMap = class _EnhancedMap extends Map {
73
73
  toKeys() {
74
74
  return [...this.keys()];
75
75
  }
76
- /** @deprecated, will be removed in v5 use `from` method instead */
77
- static fromIterMap(array, mapFunction) {
78
- return this.from(array, mapFunction);
79
- }
80
76
  static from(array, mapFunction) {
81
77
  const map = new _EnhancedMap();
82
78
  if (!array) return map;
@@ -102,4 +98,3 @@ export {
102
98
  enhancedMapReject,
103
99
  EnhancedMap
104
100
  };
105
- //# sourceMappingURL=chunk-4QK76IRX.js.map
@@ -12,34 +12,6 @@ function joinStrings(...args) {
12
12
  }
13
13
  return strings.join("");
14
14
  }
15
- function dedent(strings, ...values) {
16
- const raw = typeof strings === "string" ? [strings] : strings.raw;
17
- let result = "";
18
- for (let i = 0; i < raw.length; i++) {
19
- result += raw[i].replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`");
20
- if (i < values.length) {
21
- result += values[i];
22
- }
23
- }
24
- const lines = result.split("\n");
25
- let mindent = null;
26
- lines.forEach((l) => {
27
- const m = l.match(/^(\s+)\S+/);
28
- if (m) {
29
- const indent = m[1].length;
30
- if (!mindent) {
31
- mindent = indent;
32
- } else {
33
- mindent = Math.min(mindent, indent);
34
- }
35
- }
36
- });
37
- if (mindent !== null) {
38
- const m = mindent;
39
- result = lines.map((l) => l.startsWith(" ") ? l.slice(m) : l).join("\n");
40
- }
41
- return result.trim().replace(/\\n/g, "\n");
42
- }
43
15
  function formatNum(num) {
44
16
  return num.toLocaleString("en-US", {
45
17
  minimumFractionDigits: 2,
@@ -59,10 +31,8 @@ function truncateString(str, length, ellipsis = "\u2026") {
59
31
 
60
32
  export {
61
33
  joinStrings,
62
- dedent,
63
34
  formatNum,
64
35
  isSnakeCase,
65
36
  convertToSnakeCase,
66
37
  truncateString
67
38
  };
68
- //# sourceMappingURL=chunk-GLZ5MZC5.js.map
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/consoleFmt.ts
21
+ var consoleFmt_exports = {};
22
+ __export(consoleFmt_exports, {
23
+ consoleFmt: () => consoleFmt
24
+ });
25
+ module.exports = __toCommonJS(consoleFmt_exports);
26
+ var colorToCodeASCII = {
27
+ red: "\x1B[31m",
28
+ green: "\x1B[32m",
29
+ yellow: "\x1B[33m",
30
+ blue: "\x1B[34m",
31
+ magenta: "\x1B[35m",
32
+ cyan: "\x1B[36m",
33
+ white: "\x1B[37m",
34
+ black: "\x1B[30m",
35
+ gray: "\x1B[90m",
36
+ brightRed: "\x1B[91m",
37
+ brightGreen: "\x1B[92m",
38
+ brightYellow: "\x1B[93m",
39
+ brightBlue: "\x1B[94m",
40
+ brightMagenta: "\x1B[95m",
41
+ brightCyan: "\x1B[96m",
42
+ brightWhite: "\x1B[97m"
43
+ };
44
+ function consoleColors(color, text) {
45
+ return `${colorToCodeASCII[color]}${text}\x1B[0m`;
46
+ }
47
+ function bold(text) {
48
+ return `\x1B[1m${text}\x1B[0m`;
49
+ }
50
+ function underline(text) {
51
+ return `\x1B[4m${text}\x1B[0m`;
52
+ }
53
+ var bgColorToCodeASCII = {
54
+ red: "\x1B[41m",
55
+ green: "\x1B[42m",
56
+ yellow: "\x1B[43m",
57
+ blue: "\x1B[44m",
58
+ magenta: "\x1B[45m",
59
+ cyan: "\x1B[46m",
60
+ white: "\x1B[47m",
61
+ black: "\x1B[40m",
62
+ gray: "\x1B[100m",
63
+ brightRed: "\x1B[101m",
64
+ brightGreen: "\x1B[102m",
65
+ brightYellow: "\x1B[103m",
66
+ brightBlue: "\x1B[104m",
67
+ brightMagenta: "\x1B[105m",
68
+ brightCyan: "\x1B[106m",
69
+ brightWhite: "\x1B[107m"
70
+ };
71
+ function bgColor(color, text) {
72
+ const resetBgColor = "\x1B[49m";
73
+ return `${bgColorToCodeASCII[color]}${text}${resetBgColor}\x1B[0m`;
74
+ }
75
+ var consoleFmt = {
76
+ color: consoleColors,
77
+ bold,
78
+ underline,
79
+ bgColor
80
+ };
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ consoleFmt
84
+ });