@ls-stack/utils 1.13.1 → 2.0.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 (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-FYMTZQ42.js → chunk-4UGSP3L3.js} +0 -1
  11. package/dist/{chunk-HLFWWIDK.js → chunk-5DZT3Z5Z.js} +0 -1
  12. package/dist/{chunk-W7X6NSGR.js → chunk-AZBBTE33.js} +0 -1
  13. package/dist/{chunk-MMKMF4GG.js → chunk-IATIXMCE.js} +0 -1
  14. package/dist/chunk-JOBPQAI3.js +147 -0
  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 +265 -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 +179 -0
  69. package/dist/rsResult.d.cts +88 -0
  70. package/dist/rsResult.d.ts +33 -63
  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 +17 -9
  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,88 @@
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/shallowEqual.ts
21
+ var shallowEqual_exports = {};
22
+ __export(shallowEqual_exports, {
23
+ shallowEqual: () => shallowEqual
24
+ });
25
+ module.exports = __toCommonJS(shallowEqual_exports);
26
+ var has = Object.prototype.hasOwnProperty;
27
+ function find(iter, tar, key) {
28
+ for (key of iter.keys()) {
29
+ if (key === tar) return key;
30
+ }
31
+ }
32
+ function shallowEqual(foo, bar) {
33
+ var ctor, len, tmp;
34
+ if (foo === bar) return true;
35
+ if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
36
+ if (ctor === Date) return shallowEqual(foo.getTime(), bar.getTime());
37
+ if (ctor === RegExp) return foo.toString() === bar.toString();
38
+ if (ctor === Array) {
39
+ if ((len = foo.length) === bar.length) {
40
+ while (len-- && foo[len] === bar[len]) ;
41
+ }
42
+ return len === -1;
43
+ }
44
+ if (ctor === Set) {
45
+ if (foo.size !== bar.size) {
46
+ return false;
47
+ }
48
+ for (len of foo) {
49
+ tmp = len;
50
+ if (tmp && typeof tmp === "object") {
51
+ tmp = find(bar, tmp);
52
+ if (!tmp) return false;
53
+ }
54
+ if (!bar.has(tmp)) return false;
55
+ }
56
+ return true;
57
+ }
58
+ if (ctor === Map) {
59
+ if (foo.size !== bar.size) {
60
+ return false;
61
+ }
62
+ for (len of foo) {
63
+ tmp = len[0];
64
+ if (tmp && typeof tmp === "object") {
65
+ tmp = find(bar, tmp);
66
+ if (!tmp) return false;
67
+ }
68
+ if (len[1] !== bar.get(tmp)) {
69
+ return false;
70
+ }
71
+ }
72
+ return true;
73
+ }
74
+ if (!ctor || typeof foo === "object") {
75
+ len = 0;
76
+ for (ctor in foo) {
77
+ if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
78
+ if (!(ctor in bar) || !(foo[ctor] === bar[ctor])) return false;
79
+ }
80
+ return Object.keys(bar).length === len;
81
+ }
82
+ }
83
+ return foo !== foo && bar !== bar;
84
+ }
85
+ // Annotate the CommonJS export names for ESM import in node:
86
+ 0 && (module.exports = {
87
+ shallowEqual
88
+ });
@@ -0,0 +1,4 @@
1
+ /** shallow equal version of https://github.com/lukeed/dequal */
2
+ declare function shallowEqual(foo: any, bar: any): boolean;
3
+
4
+ export { shallowEqual };
@@ -61,4 +61,3 @@ function shallowEqual(foo, bar) {
61
61
  export {
62
62
  shallowEqual
63
63
  };
64
- //# sourceMappingURL=shallowEqual.js.map
package/dist/sleep.cjs ADDED
@@ -0,0 +1,32 @@
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/sleep.ts
21
+ var sleep_exports = {};
22
+ __export(sleep_exports, {
23
+ sleep: () => sleep
24
+ });
25
+ module.exports = __toCommonJS(sleep_exports);
26
+ function sleep(ms) {
27
+ return new Promise((resolve) => setTimeout(resolve, ms));
28
+ }
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ sleep
32
+ });
@@ -0,0 +1,3 @@
1
+ declare function sleep(ms: number): Promise<unknown>;
2
+
3
+ export { sleep };
package/dist/sleep.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  sleep
3
- } from "./chunk-HLFWWIDK.js";
3
+ } from "./chunk-5DZT3Z5Z.js";
4
4
  export {
5
5
  sleep
6
6
  };
7
- //# sourceMappingURL=sleep.js.map
@@ -0,0 +1,66 @@
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/stringUtils.ts
21
+ var stringUtils_exports = {};
22
+ __export(stringUtils_exports, {
23
+ convertToSnakeCase: () => convertToSnakeCase,
24
+ formatNum: () => formatNum,
25
+ isSnakeCase: () => isSnakeCase,
26
+ joinStrings: () => joinStrings,
27
+ truncateString: () => truncateString
28
+ });
29
+ module.exports = __toCommonJS(stringUtils_exports);
30
+ function joinStrings(...args) {
31
+ const strings = [];
32
+ for (let i = 0; i < args.length; i++) {
33
+ const arg = args[i];
34
+ if (!arg) continue;
35
+ if (Array.isArray(arg)) {
36
+ strings.push(joinStrings(...arg));
37
+ continue;
38
+ }
39
+ strings.push(arg);
40
+ }
41
+ return strings.join("");
42
+ }
43
+ function formatNum(num) {
44
+ return num.toLocaleString("en-US", {
45
+ minimumFractionDigits: 2,
46
+ maximumFractionDigits: 2
47
+ });
48
+ }
49
+ function isSnakeCase(str) {
50
+ return /^[a-z0-9_]+$/.test(str);
51
+ }
52
+ function convertToSnakeCase(str) {
53
+ return str.replace(/([A-Z])/g, "_$1").replace(/[^a-z0-9_]/g, "").toLowerCase();
54
+ }
55
+ function truncateString(str, length, ellipsis = "\u2026") {
56
+ if (str.length <= length) return str;
57
+ return str.slice(0, length - 1) + ellipsis;
58
+ }
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ convertToSnakeCase,
62
+ formatNum,
63
+ isSnakeCase,
64
+ joinStrings,
65
+ truncateString
66
+ });
@@ -0,0 +1,16 @@
1
+ type Arg = string | false | undefined | null;
2
+ /**
3
+ * A util to create more legible conditional concatenated strings
4
+ *
5
+ * @example
6
+ * joinStrings('a', 'b', 'c') // 'abc'
7
+ * joinStrings('a', false, 'c') // 'ac'
8
+ * joinStrings('a', addBString ? 'b' : null, 'c') // 'ac' if addBString is false, 'abc' if addBString is true
9
+ */
10
+ declare function joinStrings(...args: (Arg | Arg[])[]): string;
11
+ declare function formatNum(num: number): string;
12
+ declare function isSnakeCase(str: string): boolean;
13
+ declare function convertToSnakeCase(str: string): string;
14
+ declare function truncateString(str: string, length: number, ellipsis?: string): string;
15
+
16
+ export { convertToSnakeCase, formatNum, isSnakeCase, joinStrings, truncateString };
@@ -8,11 +8,9 @@ type Arg = string | false | undefined | null;
8
8
  * joinStrings('a', addBString ? 'b' : null, 'c') // 'ac' if addBString is false, 'abc' if addBString is true
9
9
  */
10
10
  declare function joinStrings(...args: (Arg | Arg[])[]): string;
11
- declare function dedent(strings: string): string;
12
- declare function dedent(strings: TemplateStringsArray, ...values: string[]): string;
13
11
  declare function formatNum(num: number): string;
14
12
  declare function isSnakeCase(str: string): boolean;
15
13
  declare function convertToSnakeCase(str: string): string;
16
14
  declare function truncateString(str: string, length: number, ellipsis?: string): string;
17
15
 
18
- export { convertToSnakeCase, dedent, formatNum, isSnakeCase, joinStrings, truncateString };
16
+ export { convertToSnakeCase, formatNum, isSnakeCase, joinStrings, truncateString };
@@ -1,17 +1,14 @@
1
1
  import {
2
2
  convertToSnakeCase,
3
- dedent,
4
3
  formatNum,
5
4
  isSnakeCase,
6
5
  joinStrings,
7
6
  truncateString
8
- } from "./chunk-GLZ5MZC5.js";
7
+ } from "./chunk-V2L472LS.js";
9
8
  export {
10
9
  convertToSnakeCase,
11
- dedent,
12
10
  formatNum,
13
11
  isSnakeCase,
14
12
  joinStrings,
15
13
  truncateString
16
14
  };
17
- //# sourceMappingURL=stringUtils.js.map
@@ -0,0 +1,357 @@
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/testUtils.ts
21
+ var testUtils_exports = {};
22
+ __export(testUtils_exports, {
23
+ createLoggerStore: () => createLoggerStore,
24
+ getResultFn: () => getResultFn
25
+ });
26
+ module.exports = __toCommonJS(testUtils_exports);
27
+
28
+ // src/arrayUtils.ts
29
+ function filterAndMap(array, mapFilter) {
30
+ const result = [];
31
+ let i = -1;
32
+ for (const item of array) {
33
+ i += 1;
34
+ const filterResult = mapFilter(item, i);
35
+ if (filterResult !== false) {
36
+ result.push(filterResult);
37
+ }
38
+ }
39
+ return result;
40
+ }
41
+ function arrayWithPrevAndIndex(array) {
42
+ return array.map((item, i) => ({
43
+ item,
44
+ prev: array[i - 1] ?? null,
45
+ index: i
46
+ }));
47
+ }
48
+
49
+ // src/assertions.ts
50
+ function isObject(value) {
51
+ return typeof value === "object" && value !== null && !Array.isArray(value);
52
+ }
53
+
54
+ // src/deepEqual.ts
55
+ var has = Object.prototype.hasOwnProperty;
56
+ function find(iter, tar, key) {
57
+ for (key of iter.keys()) {
58
+ if (deepEqual(key, tar)) return key;
59
+ }
60
+ }
61
+ function deepEqual(foo, bar) {
62
+ let ctor, len, tmp;
63
+ if (foo === bar) return true;
64
+ if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
65
+ if (ctor === Date) return deepEqual(foo.getTime(), bar.getTime());
66
+ if (ctor === RegExp) return foo.toString() === bar.toString();
67
+ if (ctor === Array) {
68
+ if ((len = foo.length) === bar.length) {
69
+ while (len-- && deepEqual(foo[len], bar[len])) ;
70
+ }
71
+ return len === -1;
72
+ }
73
+ if (ctor === Set) {
74
+ if (foo.size !== bar.size) {
75
+ return false;
76
+ }
77
+ for (len of foo) {
78
+ tmp = len;
79
+ if (tmp && typeof tmp === "object") {
80
+ tmp = find(bar, tmp);
81
+ if (!tmp) return false;
82
+ }
83
+ if (!bar.has(tmp)) return false;
84
+ }
85
+ return true;
86
+ }
87
+ if (ctor === Map) {
88
+ if (foo.size !== bar.size) {
89
+ return false;
90
+ }
91
+ for (len of foo) {
92
+ tmp = len[0];
93
+ if (tmp && typeof tmp === "object") {
94
+ tmp = find(bar, tmp);
95
+ if (!tmp) return false;
96
+ }
97
+ if (!deepEqual(len[1], bar.get(tmp))) {
98
+ return false;
99
+ }
100
+ }
101
+ return true;
102
+ }
103
+ if (!ctor || typeof foo === "object") {
104
+ len = 0;
105
+ for (ctor in foo) {
106
+ if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
107
+ if (!(ctor in bar) || !deepEqual(foo[ctor], bar[ctor])) return false;
108
+ }
109
+ return Object.keys(bar).length === len;
110
+ }
111
+ }
112
+ return foo !== foo && bar !== bar;
113
+ }
114
+
115
+ // src/mathUtils.ts
116
+ function clampMin(value, min) {
117
+ return value < min ? min : value;
118
+ }
119
+
120
+ // src/objUtils.ts
121
+ function pick(obj, keys, rename) {
122
+ const result = {};
123
+ if (!obj) {
124
+ return result;
125
+ }
126
+ for (const key of keys) {
127
+ result[rename?.[key] || key] = obj[key];
128
+ }
129
+ return result;
130
+ }
131
+ function omit(obj, keys) {
132
+ const result = {};
133
+ for (const key of Object.keys(obj)) {
134
+ if (!keys.includes(key)) {
135
+ result[key] = obj[key];
136
+ }
137
+ }
138
+ return result;
139
+ }
140
+
141
+ // src/testUtils.ts
142
+ function createLoggerStore({
143
+ filterKeys: defaultFilterKeys,
144
+ rejectKeys: defaultRejectKeys,
145
+ splitLongLines: defaultSplitLongLines = true,
146
+ maxLineLengthBeforeSplit: defaultMaxLineLengthBeforeSplit = 80,
147
+ fromLastSnapshot: defaultFromLastSnapshot = false,
148
+ arrays: defaultArrays = { firstNItems: 1 },
149
+ changesOnly: defaultChangesOnly = false,
150
+ useEmojiForBooleans: defaultUseEmojiForBooleans = true
151
+ } = {}) {
152
+ let logs = [];
153
+ let logsTime = [];
154
+ let startTime = Date.now();
155
+ let onNextLog = () => {
156
+ };
157
+ function reset(keepLastRender = false) {
158
+ logs = keepLastRender ? [logs.at(-1)] : [];
159
+ logsTime = [];
160
+ startTime = Date.now();
161
+ }
162
+ function add(render) {
163
+ if (!isObject(render)) {
164
+ for (const [i, r] of render.entries()) {
165
+ logs.push({
166
+ i: i + 1,
167
+ ...r
168
+ });
169
+ logsTime.push(Date.now() - startTime);
170
+ }
171
+ } else {
172
+ logs.push(render);
173
+ logsTime.push(Date.now() - startTime);
174
+ }
175
+ onNextLog();
176
+ if (logs.length > 100) {
177
+ throw new Error("Too many logs");
178
+ }
179
+ }
180
+ function logsCount() {
181
+ return logs.filter((item) => !item._lastSnapshotMark).length;
182
+ }
183
+ async function waitNextLog(timeout = 50) {
184
+ return new Promise((resolve) => {
185
+ const timeoutId = setTimeout(() => {
186
+ throw new Error("Timeout");
187
+ }, timeout);
188
+ onNextLog = () => {
189
+ clearTimeout(timeoutId);
190
+ resolve();
191
+ };
192
+ });
193
+ }
194
+ function getSnapshot({
195
+ arrays = defaultArrays,
196
+ changesOnly = defaultChangesOnly,
197
+ filterKeys = defaultFilterKeys,
198
+ rejectKeys = defaultRejectKeys,
199
+ includeLastSnapshotEndMark = true,
200
+ splitLongLines = defaultSplitLongLines,
201
+ maxLineLengthBeforeSplit = defaultMaxLineLengthBeforeSplit,
202
+ fromLastSnapshot = defaultFromLastSnapshot,
203
+ useEmojiForBooleans = defaultUseEmojiForBooleans
204
+ } = {}) {
205
+ let rendersToUse = logs;
206
+ if (changesOnly || filterKeys || rejectKeys) {
207
+ rendersToUse = [];
208
+ for (let { item, prev } of arrayWithPrevAndIndex(logs)) {
209
+ if (item._lastSnapshotMark || item._mark) {
210
+ rendersToUse.push(item);
211
+ continue;
212
+ }
213
+ if (filterKeys) {
214
+ prev = prev && pick(prev, filterKeys);
215
+ item = pick(item, filterKeys);
216
+ }
217
+ if (rejectKeys) {
218
+ prev = prev && omit(prev, rejectKeys);
219
+ item = omit(item, rejectKeys);
220
+ }
221
+ if (!deepEqual(prev, item)) {
222
+ rendersToUse.push(item);
223
+ }
224
+ }
225
+ }
226
+ if (fromLastSnapshot) {
227
+ const lastSnapshotMark = rendersToUse.findLastIndex(
228
+ (item) => item._lastSnapshotMark === true
229
+ );
230
+ rendersToUse = rendersToUse.slice(clampMin(lastSnapshotMark, 0));
231
+ }
232
+ logs.push({ _lastSnapshotMark: true });
233
+ const propDivider = "\u22C5";
234
+ const snapShot = `
235
+ ${filterAndMap(rendersToUse, (render, i) => {
236
+ if (render._lastSnapshotMark) {
237
+ if (includeLastSnapshotEndMark) {
238
+ if (rendersToUse.length === 1) {
239
+ return "\u22C5\u22C5\u22C5";
240
+ }
241
+ if (i !== rendersToUse.length - 1) {
242
+ return "\u22C5\u22C5\u22C5";
243
+ }
244
+ return false;
245
+ } else {
246
+ return false;
247
+ }
248
+ }
249
+ if (render._mark) {
250
+ const prevIsLastSnapshotMark = rendersToUse[i - 1]?._lastSnapshotMark;
251
+ let mark = `${prevIsLastSnapshotMark ? "" : "\n"}>>> ${String(render._mark)}`;
252
+ const nextRender = rendersToUse[i + 1];
253
+ if (nextRender && !nextRender._mark && !nextRender._lastSnapshotMark) {
254
+ mark = `${mark}
255
+ `;
256
+ }
257
+ return mark;
258
+ }
259
+ let line = "";
260
+ for (const [key, _value] of Object.entries(render)) {
261
+ let value = _value;
262
+ if (Array.isArray(value)) {
263
+ if (arrays === "length") {
264
+ value = `Array(${value.length})`;
265
+ } else if (arrays === "firstAndLast" && value.length > 2) {
266
+ const intermediateSize = clampMin(value.length - 2, 0);
267
+ value = [value[0], `\u2026(${intermediateSize} between)`, value.at(-1)];
268
+ } else if (typeof arrays === "object" && value.length > 2) {
269
+ value = [
270
+ ...value.slice(0, arrays.firstNItems),
271
+ `\u2026(${value.length - arrays.firstNItems} more)`
272
+ ];
273
+ }
274
+ }
275
+ if (typeof value === "boolean" && useEmojiForBooleans) {
276
+ value = value ? "\u2705" : "\u274C";
277
+ }
278
+ if (value === "") {
279
+ value = `''`;
280
+ }
281
+ if (typeof value === "object" && value !== null) {
282
+ value = JSON.stringify(value).replace(/:true/g, ":\u2705").replace(/:false/g, ":\u274C").replace(/:""/g, ":''").replace(/"/g, "").replace(/,/g, ", ");
283
+ }
284
+ line += `${key}: ${value} ${propDivider} `;
285
+ }
286
+ line = line.slice(0, (propDivider.length + 2) * -1);
287
+ if (splitLongLines && line.length > maxLineLengthBeforeSplit) {
288
+ const parts = line.split(` ${propDivider} `);
289
+ if (parts.length === 1) {
290
+ return line;
291
+ }
292
+ line = "";
293
+ const propDividerML = "\u22C5";
294
+ for (const { item, index } of arrayWithPrevAndIndex(parts)) {
295
+ if (index === 0) {
296
+ line += `\u250C\u2500
297
+ ${propDividerML} `;
298
+ } else if (index === parts.length - 1) {
299
+ line += `${propDividerML} `;
300
+ } else {
301
+ line += `${propDividerML} `;
302
+ }
303
+ line += `${item}
304
+ `;
305
+ if (index === parts.length - 1) {
306
+ line += "\u2514\u2500";
307
+ }
308
+ }
309
+ } else {
310
+ line = `-> ${line}`;
311
+ }
312
+ return line;
313
+ }).join("\n")}
314
+ `;
315
+ return snapShot === `
316
+ \u22C5\u22C5\u22C5
317
+ ` ? "\u22C5\u22C5\u22C5empty\u22C5\u22C5\u22C5" : snapShot;
318
+ }
319
+ function addMark(label) {
320
+ add({ _mark: label });
321
+ }
322
+ return {
323
+ add,
324
+ reset,
325
+ getSnapshot,
326
+ waitNextLog,
327
+ get changesSnapshot() {
328
+ return getSnapshot({ changesOnly: true });
329
+ },
330
+ get snapshot() {
331
+ return getSnapshot();
332
+ },
333
+ get snapshotFromLast() {
334
+ return getSnapshot({ fromLastSnapshot: true });
335
+ },
336
+ logsCount,
337
+ get rendersTime() {
338
+ return logsTime;
339
+ },
340
+ addMark
341
+ };
342
+ }
343
+ function getResultFn(fnGetter, wrapper) {
344
+ return (...args) => {
345
+ const fn = fnGetter();
346
+ if (wrapper) {
347
+ return wrapper(fn(...args));
348
+ } else {
349
+ return fn(...args);
350
+ }
351
+ };
352
+ }
353
+ // Annotate the CommonJS export names for ESM import in node:
354
+ 0 && (module.exports = {
355
+ createLoggerStore,
356
+ getResultFn
357
+ });
@@ -0,0 +1,38 @@
1
+ declare function createLoggerStore({ filterKeys: defaultFilterKeys, rejectKeys: defaultRejectKeys, splitLongLines: defaultSplitLongLines, maxLineLengthBeforeSplit: defaultMaxLineLengthBeforeSplit, fromLastSnapshot: defaultFromLastSnapshot, arrays: defaultArrays, changesOnly: defaultChangesOnly, useEmojiForBooleans: defaultUseEmojiForBooleans, }?: {
2
+ filterKeys?: string[];
3
+ rejectKeys?: string[];
4
+ splitLongLines?: true;
5
+ maxLineLengthBeforeSplit?: number;
6
+ fromLastSnapshot?: boolean;
7
+ arrays?: 'all' | 'firstAndLast' | 'length' | {
8
+ firstNItems: number;
9
+ };
10
+ changesOnly?: boolean;
11
+ useEmojiForBooleans?: boolean;
12
+ }): {
13
+ add: (render: Record<string, unknown> | readonly Record<string, unknown>[]) => void;
14
+ reset: (keepLastRender?: boolean) => void;
15
+ getSnapshot: ({ arrays, changesOnly, filterKeys, rejectKeys, includeLastSnapshotEndMark, splitLongLines, maxLineLengthBeforeSplit, fromLastSnapshot, useEmojiForBooleans, }?: {
16
+ arrays?: "all" | "firstAndLast" | "length" | {
17
+ firstNItems: number;
18
+ };
19
+ changesOnly?: boolean;
20
+ filterKeys?: string[];
21
+ rejectKeys?: string[];
22
+ includeLastSnapshotEndMark?: boolean;
23
+ splitLongLines?: boolean;
24
+ maxLineLengthBeforeSplit?: number;
25
+ fromLastSnapshot?: boolean;
26
+ useEmojiForBooleans?: boolean;
27
+ }) => string;
28
+ waitNextLog: (timeout?: number) => Promise<void>;
29
+ readonly changesSnapshot: string;
30
+ readonly snapshot: string;
31
+ readonly snapshotFromLast: string;
32
+ logsCount: () => number;
33
+ readonly rendersTime: number[];
34
+ addMark: (label: string) => void;
35
+ };
36
+ declare function getResultFn<T extends (...args: any[]) => any>(fnGetter: () => T, wrapper?: (...args: any[]) => any): T;
37
+
38
+ export { createLoggerStore, getResultFn };