@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
package/dist/testUtils.js CHANGED
@@ -1,20 +1,20 @@
1
1
  import {
2
2
  deepEqual
3
- } from "./chunk-M74KKYE4.js";
3
+ } from "./chunk-KCOXGSRA.js";
4
4
  import {
5
5
  clampMin
6
- } from "./chunk-NKCC3375.js";
6
+ } from "./chunk-NWXBMMHO.js";
7
7
  import {
8
8
  omit,
9
9
  pick
10
- } from "./chunk-SNAAKCTH.js";
10
+ } from "./chunk-RVVH3MDA.js";
11
11
  import {
12
12
  arrayWithPrevAndIndex,
13
13
  filterAndMap
14
- } from "./chunk-W7X6NSGR.js";
14
+ } from "./chunk-AZBBTE33.js";
15
15
  import {
16
16
  isObject
17
- } from "./chunk-FYMTZQ42.js";
17
+ } from "./chunk-4UGSP3L3.js";
18
18
 
19
19
  // src/testUtils.ts
20
20
  function createLoggerStore({
@@ -109,11 +109,17 @@ function createLoggerStore({
109
109
  }
110
110
  logs.push({ _lastSnapshotMark: true });
111
111
  const propDivider = "\u22C5";
112
- return `
112
+ const snapShot = `
113
113
  ${filterAndMap(rendersToUse, (render, i) => {
114
114
  if (render._lastSnapshotMark) {
115
- if (includeLastSnapshotEndMark && i !== rendersToUse.length - 1) {
116
- return "\u22C5\u22C5\u22C5";
115
+ if (includeLastSnapshotEndMark) {
116
+ if (rendersToUse.length === 1) {
117
+ return "\u22C5\u22C5\u22C5";
118
+ }
119
+ if (i !== rendersToUse.length - 1) {
120
+ return "\u22C5\u22C5\u22C5";
121
+ }
122
+ return false;
117
123
  } else {
118
124
  return false;
119
125
  }
@@ -184,6 +190,9 @@ ${propDividerML} `;
184
190
  return line;
185
191
  }).join("\n")}
186
192
  `;
193
+ return snapShot === `
194
+ \u22C5\u22C5\u22C5
195
+ ` ? "\u22C5\u22C5\u22C5empty\u22C5\u22C5\u22C5" : snapShot;
187
196
  }
188
197
  function addMark(label) {
189
198
  add({ _mark: label });
@@ -223,4 +232,3 @@ export {
223
232
  createLoggerStore,
224
233
  getResultFn
225
234
  };
226
- //# sourceMappingURL=testUtils.js.map
@@ -0,0 +1,55 @@
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/typingFnUtils.ts
21
+ var typingFnUtils_exports = {};
22
+ __export(typingFnUtils_exports, {
23
+ asNonPartial: () => asNonPartial,
24
+ asType: () => asType,
25
+ narrowStringToUnion: () => narrowStringToUnion,
26
+ typedObjectEntries: () => typedObjectEntries,
27
+ typedObjectKeys: () => typedObjectKeys
28
+ });
29
+ module.exports = __toCommonJS(typingFnUtils_exports);
30
+ function asNonPartial(obj) {
31
+ return obj;
32
+ }
33
+ function typedObjectEntries(obj) {
34
+ return Object.entries(obj);
35
+ }
36
+ function typedObjectKeys(obj) {
37
+ return Object.keys(obj);
38
+ }
39
+ function asType(value) {
40
+ return value;
41
+ }
42
+ function narrowStringToUnion(key, union) {
43
+ if (key && union.includes(key)) {
44
+ return key;
45
+ }
46
+ return void 0;
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ asNonPartial,
51
+ asType,
52
+ narrowStringToUnion,
53
+ typedObjectEntries,
54
+ typedObjectKeys
55
+ });
@@ -0,0 +1,15 @@
1
+ import { NonPartial } from './typingUtils.cjs';
2
+
3
+ declare function asNonPartial<T extends Record<string, unknown>>(obj: T): NonPartial<T>;
4
+ /** a wrapper to Object.entries with a better typing inference */
5
+ declare function typedObjectEntries<T extends Record<string, unknown>>(obj: T): NonNullable<{
6
+ [K in keyof T]: [K, T[K]];
7
+ }[keyof T]>[];
8
+ /** a wrapper to Object.keys with a better typing inference */
9
+ declare function typedObjectKeys<T extends Record<string, unknown>>(obj: T): (keyof T)[];
10
+ /** a safe way to cast types, use to substitute the `as Type` */
11
+ declare function asType<T = unknown>(value: T): T;
12
+ /** narrow a string to a union of strings */
13
+ declare function narrowStringToUnion<const T extends string>(key: string | undefined | null, union: T[]): T | undefined;
14
+
15
+ export { asNonPartial, asType, narrowStringToUnion, typedObjectEntries, typedObjectKeys };
@@ -24,4 +24,3 @@ export {
24
24
  typedObjectEntries,
25
25
  typedObjectKeys
26
26
  };
27
- //# sourceMappingURL=typingFnUtils.js.map
@@ -0,0 +1,43 @@
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/typingTestUtils.ts
21
+ var typingTestUtils_exports = {};
22
+ __export(typingTestUtils_exports, {
23
+ typingTest: () => typingTest
24
+ });
25
+ module.exports = __toCommonJS(typingTestUtils_exports);
26
+ function test(title, func) {
27
+ func();
28
+ }
29
+ function describe(title, func) {
30
+ func();
31
+ }
32
+ function expectType() {
33
+ return {};
34
+ }
35
+ var typingTest = {
36
+ test,
37
+ describe,
38
+ expectType
39
+ };
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ typingTest
43
+ });
@@ -0,0 +1,12 @@
1
+ type TestTypeIsEqual<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
2
+ type TestTypeNotEqual<X, Y> = true extends TestTypeIsEqual<X, Y> ? false : true;
3
+ declare function test(title: string, func: () => any): void;
4
+ declare function describe(title: string, func: () => any): void;
5
+ declare function expectType<T extends true>(): T;
6
+ declare const typingTest: {
7
+ test: typeof test;
8
+ describe: typeof describe;
9
+ expectType: typeof expectType;
10
+ };
11
+
12
+ export { type TestTypeIsEqual, type TestTypeNotEqual, typingTest };
@@ -16,4 +16,3 @@ var typingTest = {
16
16
  export {
17
17
  typingTest
18
18
  };
19
- //# sourceMappingURL=typingTestUtils.js.map
@@ -0,0 +1,18 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/typingUtils.ts
17
+ var typingUtils_exports = {};
18
+ module.exports = __toCommonJS(typingUtils_exports);
@@ -0,0 +1,11 @@
1
+ type PartialRecord<K extends keyof any, T> = {
2
+ [P in K]?: T;
3
+ };
4
+ type NonPartial<T> = {
5
+ [K in keyof Required<T>]: T[K];
6
+ };
7
+ type ObjKeysWithValuesOfType<Obj extends Record<PropertyKey, unknown>, ValueType> = {
8
+ [K in keyof Obj]: Obj[K] extends ValueType ? K : never;
9
+ }[keyof Obj];
10
+
11
+ export type { NonPartial, ObjKeysWithValuesOfType, PartialRecord };
@@ -1 +0,0 @@
1
- //# sourceMappingURL=typingUtils.js.map
@@ -0,0 +1,346 @@
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/yamlStringify.ts
21
+ var yamlStringify_exports = {};
22
+ __export(yamlStringify_exports, {
23
+ yamlStringify: () => yamlStringify
24
+ });
25
+ module.exports = __toCommonJS(yamlStringify_exports);
26
+
27
+ // src/assertions.ts
28
+ function isObject(value) {
29
+ return typeof value === "object" && value !== null && !Array.isArray(value);
30
+ }
31
+ function isPlainObject(value) {
32
+ if (!value || typeof value !== "object") return false;
33
+ const proto = Object.getPrototypeOf(value);
34
+ if (proto === null) {
35
+ return true;
36
+ }
37
+ const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
38
+ if (Ctor === Object) return true;
39
+ const objectCtorString = Object.prototype.constructor.toString();
40
+ return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
41
+ }
42
+
43
+ // src/conversions.ts
44
+ function bytesToHumanReadable(bytes) {
45
+ if (bytes < 1024) {
46
+ return `${bytes} B`;
47
+ }
48
+ const kb = bytes / 1024;
49
+ if (kb < 1024) {
50
+ return `${kb.toFixed(2)} KB`;
51
+ }
52
+ const mb = kb / 1024;
53
+ if (mb < 1024) {
54
+ return `${mb.toFixed(2)} MB`;
55
+ }
56
+ const gb = mb / 1024;
57
+ return `${gb.toFixed(2)} GB`;
58
+ }
59
+
60
+ // src/stringUtils.ts
61
+ function truncateString(str, length, ellipsis = "\u2026") {
62
+ if (str.length <= length) return str;
63
+ return str.slice(0, length - 1) + ellipsis;
64
+ }
65
+
66
+ // src/yamlStringify.ts
67
+ function yamlStringify(obj, {
68
+ maxLineLength = 100,
69
+ showUndefined,
70
+ maxDepth = 50,
71
+ addRootObjSpaces = "beforeAndAfter"
72
+ } = {}) {
73
+ if (isObject(obj) || Array.isArray(obj) || typeof obj === "function") {
74
+ return `${stringifyValue(obj, "", maxLineLength, !!showUndefined, maxDepth, 0, addRootObjSpaces)}
75
+ `;
76
+ }
77
+ return JSON.stringify(obj) || "undefined";
78
+ }
79
+ function stringifyValue(value, indent, maxLineLength, showUndefined, maxDepth, depth, addObjSpaces) {
80
+ let result = "";
81
+ const childIndent = `${indent} `;
82
+ if (isPlainObject(value)) {
83
+ if (Object.keys(value).length === 0) {
84
+ return "{}";
85
+ }
86
+ let prevValue;
87
+ let afterSpaceWasAdded = false;
88
+ for (let [key, objVal] of Object.entries(value)) {
89
+ if (objVal === void 0 && !showUndefined) {
90
+ continue;
91
+ }
92
+ if (depth > maxDepth) {
93
+ objVal = `{max depth reached}`;
94
+ }
95
+ const normalizedValue2 = normalizeValue(objVal);
96
+ if (normalizedValue2 !== null) {
97
+ objVal = normalizedValue2[1];
98
+ key = `${key}{${normalizedValue2[0]}}`;
99
+ }
100
+ const valueString = stringifyValue(
101
+ objVal,
102
+ childIndent,
103
+ maxLineLength,
104
+ showUndefined,
105
+ maxDepth,
106
+ depth + 1,
107
+ addObjSpaces
108
+ );
109
+ if (!afterSpaceWasAdded && indent === "" && isObject(objVal) && prevValue && (addObjSpaces === "before" || addObjSpaces === "beforeAndAfter")) {
110
+ result += "\n";
111
+ }
112
+ if (Array.isArray(objVal)) {
113
+ const arrayIsSingleLine = valueString.split("\n").length === 1;
114
+ if (arrayIsSingleLine && !valueString.trim().startsWith("-")) {
115
+ result += `${indent}${key}: `;
116
+ } else {
117
+ result += `${indent}${key}:
118
+ `;
119
+ }
120
+ } else if (isObject(objVal)) {
121
+ if (Object.keys(objVal).length === 0) {
122
+ result += `${indent}${key}: `;
123
+ } else {
124
+ result += `${indent}${key}:
125
+ `;
126
+ }
127
+ } else {
128
+ result += `${indent}${key}: `;
129
+ }
130
+ result += valueString;
131
+ result += "\n";
132
+ if (indent === "") {
133
+ if (isObject(objVal)) {
134
+ if (addObjSpaces === "after" || addObjSpaces === "beforeAndAfter") {
135
+ result += "\n";
136
+ afterSpaceWasAdded = true;
137
+ } else {
138
+ afterSpaceWasAdded = false;
139
+ }
140
+ }
141
+ }
142
+ prevValue = objVal;
143
+ }
144
+ return result.trimEnd();
145
+ }
146
+ if (Array.isArray(value)) {
147
+ let arrayWasAdded = false;
148
+ if (value.length === 0 || value.every(
149
+ (item) => typeof item === "string" || typeof item === "number" || typeof item === "boolean" || item === null || item === void 0
150
+ )) {
151
+ let line = "";
152
+ line += `[`;
153
+ line += value.map((item) => {
154
+ let valueToUse = item;
155
+ if (depth > maxDepth) {
156
+ valueToUse = `{max depth reached}`;
157
+ }
158
+ if (typeof valueToUse === "string" && valueToUse.includes("\n")) {
159
+ valueToUse = valueToUse.replace(/\n/g, "\\n");
160
+ }
161
+ return stringifyValue(
162
+ valueToUse,
163
+ "",
164
+ maxLineLength,
165
+ showUndefined,
166
+ maxDepth,
167
+ depth + 1,
168
+ addObjSpaces
169
+ );
170
+ }).join(", ");
171
+ line += "]";
172
+ if (line.length <= maxLineLength) {
173
+ result += line;
174
+ arrayWasAdded = true;
175
+ }
176
+ }
177
+ if (!arrayWasAdded) {
178
+ for (let item of value) {
179
+ if (depth > maxDepth) {
180
+ item = `{max depth reached}`;
181
+ }
182
+ result += `${indent}- `;
183
+ if (Array.isArray(item) || isObject(item)) {
184
+ let arrayString = stringifyValue(
185
+ item,
186
+ childIndent,
187
+ maxLineLength,
188
+ showUndefined,
189
+ maxDepth,
190
+ depth + 1,
191
+ addObjSpaces
192
+ );
193
+ arrayString = arrayString.trimStart();
194
+ result += arrayString;
195
+ } else {
196
+ result += stringifyValue(
197
+ item,
198
+ childIndent,
199
+ maxLineLength,
200
+ showUndefined,
201
+ maxDepth,
202
+ depth + 1,
203
+ addObjSpaces
204
+ );
205
+ }
206
+ result += "\n";
207
+ }
208
+ }
209
+ return result.trimEnd();
210
+ }
211
+ if (typeof value === "string") {
212
+ if (value.includes("\n")) {
213
+ const lines = value.split("\n");
214
+ for (const [i, line] of lines.entries()) {
215
+ if (i === 0) {
216
+ if (value.endsWith("\n")) {
217
+ result += `|`;
218
+ } else {
219
+ result += `|-`;
220
+ }
221
+ result += `
222
+ ${indent}${line}
223
+ `;
224
+ } else {
225
+ result += `${indent}${line}
226
+ `;
227
+ }
228
+ }
229
+ } else {
230
+ if (value.includes("'")) {
231
+ result += `"${value}"`;
232
+ } else {
233
+ result += `'${value}'`;
234
+ }
235
+ }
236
+ return result.trimEnd();
237
+ }
238
+ if (typeof value === "number" || typeof value === "boolean" || value === null || value === void 0) {
239
+ return String(value).trimEnd();
240
+ }
241
+ const normalizedValue = normalizeValue(value);
242
+ if (normalizedValue !== null) {
243
+ return stringifyValue(
244
+ {
245
+ [`${normalizedValue[0]}#`]: normalizedValue[1]
246
+ },
247
+ indent,
248
+ maxLineLength,
249
+ showUndefined,
250
+ maxDepth,
251
+ depth + 1,
252
+ addObjSpaces
253
+ );
254
+ }
255
+ return JSON.stringify(value);
256
+ }
257
+ function normalizeValue(value) {
258
+ if (value === null || isPlainObject(value) || Array.isArray(value)) {
259
+ return null;
260
+ }
261
+ if (value instanceof Map) {
262
+ const mapEntries = Array.from(value.entries());
263
+ let mapValue;
264
+ if (mapEntries.every(([key]) => typeof key === "string")) {
265
+ const mapObjValue = {};
266
+ for (const [key, val] of mapEntries) {
267
+ mapObjValue[key] = val;
268
+ }
269
+ mapValue = mapObjValue;
270
+ } else {
271
+ mapValue = mapEntries.map(([key, val]) => ({
272
+ key,
273
+ value: val
274
+ }));
275
+ }
276
+ return ["Map", mapValue];
277
+ }
278
+ if (value instanceof Set) {
279
+ const setValue = Array.from(value);
280
+ return ["Set", setValue];
281
+ }
282
+ if (value instanceof Date) {
283
+ return ["Date", value.toISOString()];
284
+ }
285
+ if (value instanceof RegExp) {
286
+ return ["RegExp", value.toString()];
287
+ }
288
+ if (value instanceof Error) {
289
+ return [
290
+ "Error",
291
+ {
292
+ message: value.message,
293
+ name: value.name,
294
+ stack: value.stack
295
+ }
296
+ ];
297
+ }
298
+ if (value instanceof File) {
299
+ return [
300
+ "File",
301
+ {
302
+ name: value.name,
303
+ type: value.type,
304
+ lastModified: new Date(value.lastModified).toISOString(),
305
+ size: bytesToHumanReadable(value.size)
306
+ }
307
+ ];
308
+ }
309
+ if (typeof value === "object") {
310
+ if ("toJSON" in value && typeof value.toJSON === "function") {
311
+ return [value.constructor.name, value.toJSON()];
312
+ }
313
+ if ("toString" in value && typeof value.toString === "function") {
314
+ const stringValue = value.toString();
315
+ if (stringValue.toString() !== "[object Object]") {
316
+ return [value.constructor.name, stringValue];
317
+ }
318
+ }
319
+ const objectValue = { ...value };
320
+ const displayValue = {};
321
+ let addedKeys = 0;
322
+ for (const [key, item] of Object.entries(objectValue)) {
323
+ if (addedKeys > 4) {
324
+ displayValue["...and more properties"] = Object.keys(objectValue).length - 4;
325
+ break;
326
+ }
327
+ if (typeof item === "string" || typeof item === "number" || typeof item === "boolean" || item === null || item === void 0) {
328
+ displayValue[key] = item;
329
+ addedKeys++;
330
+ }
331
+ }
332
+ return [String(value.constructor.name), displayValue];
333
+ }
334
+ if (typeof value === "function") {
335
+ const functionString = value.toString();
336
+ return [
337
+ `Function`,
338
+ functionString.includes("\n") ? truncateString(functionString.split("\n").join(""), 40) : functionString
339
+ ];
340
+ }
341
+ return null;
342
+ }
343
+ // Annotate the CommonJS export names for ESM import in node:
344
+ 0 && (module.exports = {
345
+ yamlStringify
346
+ });
@@ -0,0 +1,8 @@
1
+ declare function yamlStringify(obj: unknown, { maxLineLength, showUndefined, maxDepth, addRootObjSpaces, }?: {
2
+ maxLineLength?: number;
3
+ showUndefined?: boolean;
4
+ maxDepth?: number;
5
+ addRootObjSpaces?: 'before' | 'after' | 'beforeAndAfter' | false;
6
+ }): string;
7
+
8
+ export { yamlStringify };
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  truncateString
3
- } from "./chunk-GLZ5MZC5.js";
3
+ } from "./chunk-V2L472LS.js";
4
4
  import {
5
5
  bytesToHumanReadable
6
- } from "./chunk-MMKMF4GG.js";
6
+ } from "./chunk-IATIXMCE.js";
7
7
  import {
8
8
  isObject,
9
9
  isPlainObject
10
- } from "./chunk-FYMTZQ42.js";
10
+ } from "./chunk-4UGSP3L3.js";
11
11
 
12
12
  // src/yamlStringify.ts
13
13
  function yamlStringify(obj, {
@@ -289,4 +289,3 @@ function normalizeValue(value) {
289
289
  export {
290
290
  yamlStringify
291
291
  };
292
- //# sourceMappingURL=yamlStringify.js.map