@ls-stack/utils 3.13.0 → 3.15.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 (46) hide show
  1. package/lib/arrayUtils.cjs +5 -2
  2. package/lib/arrayUtils.js +3 -2
  3. package/lib/assertions.cjs +42 -34
  4. package/lib/assertions.d.cts +175 -11
  5. package/lib/assertions.d.ts +175 -11
  6. package/lib/assertions.js +2 -1
  7. package/lib/cache.cjs +7 -4
  8. package/lib/cache.js +2 -1
  9. package/lib/{chunk-UTFE4P3P.js → chunk-DMW5Q4T2.js} +1 -1
  10. package/lib/{chunk-OHHF4CJZ.js → chunk-GKOTKAIV.js} +1 -1
  11. package/lib/{chunk-U44EKR2F.js → chunk-NH2LCAQS.js} +1 -1
  12. package/lib/chunk-SSKW673U.js +36 -0
  13. package/lib/chunk-WS4WEVHU.js +57 -0
  14. package/lib/concurrentCalls.cjs +20 -14
  15. package/lib/concurrentCalls.d.cts +2 -0
  16. package/lib/concurrentCalls.d.ts +2 -0
  17. package/lib/concurrentCalls.js +5 -2
  18. package/lib/createThrottleController.cjs +5 -2
  19. package/lib/createThrottleController.js +3 -2
  20. package/lib/enhancedMap.cjs +5 -2
  21. package/lib/enhancedMap.js +3 -2
  22. package/lib/getCompositeKey.cjs +5 -2
  23. package/lib/getCompositeKey.js +3 -2
  24. package/lib/getValueStableKey.cjs +5 -2
  25. package/lib/getValueStableKey.js +3 -2
  26. package/lib/interpolate.cjs +2 -2
  27. package/lib/interpolate.js +2 -1
  28. package/lib/parallelAsyncCalls.cjs +10 -7
  29. package/lib/parallelAsyncCalls.js +2 -1
  30. package/lib/serializeXML.js +3 -2
  31. package/lib/testUtils.cjs +5 -2
  32. package/lib/testUtils.js +3 -2
  33. package/lib/tsResult.cjs +9 -4
  34. package/lib/tsResult.js +2 -1
  35. package/lib/typeGuards.cjs +65 -0
  36. package/lib/typeGuards.d.cts +109 -0
  37. package/lib/typeGuards.d.ts +109 -0
  38. package/lib/typeGuards.js +16 -0
  39. package/lib/typingFnUtils.cjs +10 -3
  40. package/lib/typingFnUtils.d.cts +25 -2
  41. package/lib/typingFnUtils.d.ts +25 -2
  42. package/lib/typingFnUtils.js +7 -2
  43. package/lib/yamlStringify.cjs +17 -9
  44. package/lib/yamlStringify.js +7 -2
  45. package/package.json +5 -1
  46. package/lib/chunk-3XCS7FVO.js +0 -66
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Type guard to check if a value is a plain object (not null, not an array).
3
+ *
4
+ * Returns true if the value is an object that is not null and not an array.
5
+ * This is useful for distinguishing between objects and other types.
6
+ *
7
+ * @param value - The value to check
8
+ * @returns True if the value is a plain object, false otherwise
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * if (isObject(value)) {
13
+ * // TypeScript knows value is Record<string, unknown>
14
+ * console.log(value.someProperty);
15
+ * }
16
+ *
17
+ * isObject({}); // true
18
+ * isObject({ a: 1 }); // true
19
+ * isObject(null); // false
20
+ * isObject([]); // false
21
+ * isObject('string'); // false
22
+ * ```
23
+ */
24
+ declare function isObject(value: unknown): value is Record<string, unknown>;
25
+ /**
26
+ * Type guard to check if a value is a function.
27
+ *
28
+ * Returns true if the value is a function of any kind (regular function,
29
+ * arrow function, method, constructor, etc.).
30
+ *
31
+ * @param value - The value to check
32
+ * @returns True if the value is a function, false otherwise
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * if (isFunction(value)) {
37
+ * // TypeScript knows value is (...args: any[]) => any
38
+ * const result = value();
39
+ * }
40
+ *
41
+ * isFunction(() => {}); // true
42
+ * isFunction(function() {}); // true
43
+ * isFunction(Math.max); // true
44
+ * isFunction('string'); // false
45
+ * isFunction({}); // false
46
+ * ```
47
+ */
48
+ declare function isFunction(value: unknown): value is (...args: any[]) => any;
49
+ /**
50
+ * Type guard to check if a value is a Promise or thenable object.
51
+ *
52
+ * Returns true if the value is an object with a `then` method that is a function.
53
+ * This covers both native Promises and thenable objects that implement the
54
+ * Promise interface.
55
+ *
56
+ * @param value - The value to check
57
+ * @returns True if the value is a Promise or thenable, false otherwise
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * if (isPromise(value)) {
62
+ * // TypeScript knows value is Promise<unknown>
63
+ * const result = await value;
64
+ * }
65
+ *
66
+ * isPromise(Promise.resolve()); // true
67
+ * isPromise(new Promise(() => {})); // true
68
+ * isPromise({ then: () => {} }); // true
69
+ * isPromise({ then: 'not a function' }); // false
70
+ * isPromise('string'); // false
71
+ * ```
72
+ */
73
+ declare function isPromise(value: unknown): value is Promise<unknown>;
74
+ /**
75
+ * Type guard to check if a value is a plain object (created by Object literal or Object constructor).
76
+ *
77
+ * Returns true if the value is a plain object - an object created by the Object
78
+ * constructor or object literal syntax. This excludes instances of classes,
79
+ * built-in objects like Date, RegExp, etc.
80
+ *
81
+ * @param value - The value to check
82
+ * @returns True if the value is a plain object, false otherwise
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * if (isPlainObject(value)) {
87
+ * // TypeScript knows value is Record<string, unknown>
88
+ * console.log(Object.keys(value));
89
+ * }
90
+ *
91
+ * isPlainObject({}); // true
92
+ * isPlainObject({ a: 1 }); // true
93
+ * isPlainObject(Object.create(null)); // true
94
+ * isPlainObject(new Date()); // false
95
+ * isPlainObject(/regex/); // false
96
+ * isPlainObject(new MyClass()); // false
97
+ * isPlainObject([]); // false
98
+ * ```
99
+ */
100
+ declare function isPlainObject(value: any): value is Record<string, unknown>;
101
+ type NonEmptyArray<T> = [T, ...T[]];
102
+ declare function isNonEmptyArray<T>(value: T[] | readonly T[]): value is NonEmptyArray<T>;
103
+ declare function arrayHasAtLeastXItems<T>(array: T[], minLength: 1): array is [T, ...T[]];
104
+ declare function arrayHasAtLeastXItems<T>(array: T[], minLength: 2): array is [T, T, ...T[]];
105
+ declare function arrayHasAtLeastXItems<T>(array: T[], minLength: 3): array is [T, T, T, ...T[]];
106
+ declare function arrayHasAtLeastXItems<T>(array: T[], minLength: 4): array is [T, T, T, T, ...T[]];
107
+ declare function arrayHasAtLeastXItems<T>(array: T[], minLength: 5): array is [T, T, T, T, T, ...T[]];
108
+
109
+ export { type NonEmptyArray, arrayHasAtLeastXItems, isFunction, isNonEmptyArray, isObject, isPlainObject, isPromise };
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Type guard to check if a value is a plain object (not null, not an array).
3
+ *
4
+ * Returns true if the value is an object that is not null and not an array.
5
+ * This is useful for distinguishing between objects and other types.
6
+ *
7
+ * @param value - The value to check
8
+ * @returns True if the value is a plain object, false otherwise
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * if (isObject(value)) {
13
+ * // TypeScript knows value is Record<string, unknown>
14
+ * console.log(value.someProperty);
15
+ * }
16
+ *
17
+ * isObject({}); // true
18
+ * isObject({ a: 1 }); // true
19
+ * isObject(null); // false
20
+ * isObject([]); // false
21
+ * isObject('string'); // false
22
+ * ```
23
+ */
24
+ declare function isObject(value: unknown): value is Record<string, unknown>;
25
+ /**
26
+ * Type guard to check if a value is a function.
27
+ *
28
+ * Returns true if the value is a function of any kind (regular function,
29
+ * arrow function, method, constructor, etc.).
30
+ *
31
+ * @param value - The value to check
32
+ * @returns True if the value is a function, false otherwise
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * if (isFunction(value)) {
37
+ * // TypeScript knows value is (...args: any[]) => any
38
+ * const result = value();
39
+ * }
40
+ *
41
+ * isFunction(() => {}); // true
42
+ * isFunction(function() {}); // true
43
+ * isFunction(Math.max); // true
44
+ * isFunction('string'); // false
45
+ * isFunction({}); // false
46
+ * ```
47
+ */
48
+ declare function isFunction(value: unknown): value is (...args: any[]) => any;
49
+ /**
50
+ * Type guard to check if a value is a Promise or thenable object.
51
+ *
52
+ * Returns true if the value is an object with a `then` method that is a function.
53
+ * This covers both native Promises and thenable objects that implement the
54
+ * Promise interface.
55
+ *
56
+ * @param value - The value to check
57
+ * @returns True if the value is a Promise or thenable, false otherwise
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * if (isPromise(value)) {
62
+ * // TypeScript knows value is Promise<unknown>
63
+ * const result = await value;
64
+ * }
65
+ *
66
+ * isPromise(Promise.resolve()); // true
67
+ * isPromise(new Promise(() => {})); // true
68
+ * isPromise({ then: () => {} }); // true
69
+ * isPromise({ then: 'not a function' }); // false
70
+ * isPromise('string'); // false
71
+ * ```
72
+ */
73
+ declare function isPromise(value: unknown): value is Promise<unknown>;
74
+ /**
75
+ * Type guard to check if a value is a plain object (created by Object literal or Object constructor).
76
+ *
77
+ * Returns true if the value is a plain object - an object created by the Object
78
+ * constructor or object literal syntax. This excludes instances of classes,
79
+ * built-in objects like Date, RegExp, etc.
80
+ *
81
+ * @param value - The value to check
82
+ * @returns True if the value is a plain object, false otherwise
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * if (isPlainObject(value)) {
87
+ * // TypeScript knows value is Record<string, unknown>
88
+ * console.log(Object.keys(value));
89
+ * }
90
+ *
91
+ * isPlainObject({}); // true
92
+ * isPlainObject({ a: 1 }); // true
93
+ * isPlainObject(Object.create(null)); // true
94
+ * isPlainObject(new Date()); // false
95
+ * isPlainObject(/regex/); // false
96
+ * isPlainObject(new MyClass()); // false
97
+ * isPlainObject([]); // false
98
+ * ```
99
+ */
100
+ declare function isPlainObject(value: any): value is Record<string, unknown>;
101
+ type NonEmptyArray<T> = [T, ...T[]];
102
+ declare function isNonEmptyArray<T>(value: T[] | readonly T[]): value is NonEmptyArray<T>;
103
+ declare function arrayHasAtLeastXItems<T>(array: T[], minLength: 1): array is [T, ...T[]];
104
+ declare function arrayHasAtLeastXItems<T>(array: T[], minLength: 2): array is [T, T, ...T[]];
105
+ declare function arrayHasAtLeastXItems<T>(array: T[], minLength: 3): array is [T, T, T, ...T[]];
106
+ declare function arrayHasAtLeastXItems<T>(array: T[], minLength: 4): array is [T, T, T, T, ...T[]];
107
+ declare function arrayHasAtLeastXItems<T>(array: T[], minLength: 5): array is [T, T, T, T, T, ...T[]];
108
+
109
+ export { type NonEmptyArray, arrayHasAtLeastXItems, isFunction, isNonEmptyArray, isObject, isPlainObject, isPromise };
@@ -0,0 +1,16 @@
1
+ import {
2
+ arrayHasAtLeastXItems,
3
+ isFunction,
4
+ isNonEmptyArray,
5
+ isObject,
6
+ isPlainObject,
7
+ isPromise
8
+ } from "./chunk-SSKW673U.js";
9
+ export {
10
+ arrayHasAtLeastXItems,
11
+ isFunction,
12
+ isNonEmptyArray,
13
+ isObject,
14
+ isPlainObject,
15
+ isPromise
16
+ };
@@ -25,8 +25,10 @@ __export(typingFnUtils_exports, {
25
25
  isObjKey: () => isObjKey,
26
26
  isSubTypeOf: () => isSubTypeOf,
27
27
  narrowStringToUnion: () => narrowStringToUnion,
28
+ typeOnRightExtendsLeftType: () => typeOnRightExtendsLeftType,
28
29
  typedObjectEntries: () => typedObjectEntries,
29
- typedObjectKeys: () => typedObjectKeys
30
+ typedObjectKeys: () => typedObjectKeys,
31
+ unionsAreTheSame: () => unionsAreTheSame
30
32
  });
31
33
  module.exports = __toCommonJS(typingFnUtils_exports);
32
34
  function asNonPartial(obj) {
@@ -47,12 +49,15 @@ function narrowStringToUnion(key, union) {
47
49
  }
48
50
  return void 0;
49
51
  }
50
- function isSubTypeOf() {
52
+ function typeOnRightExtendsLeftType() {
51
53
  return void 0;
52
54
  }
55
+ var isSubTypeOf = typeOnRightExtendsLeftType;
53
56
  function isObjKey(key, obj) {
54
57
  return typeof key === "string" && key in obj;
55
58
  }
59
+ function unionsAreTheSame(_diff) {
60
+ }
56
61
  // Annotate the CommonJS export names for ESM import in node:
57
62
  0 && (module.exports = {
58
63
  asNonPartial,
@@ -60,6 +65,8 @@ function isObjKey(key, obj) {
60
65
  isObjKey,
61
66
  isSubTypeOf,
62
67
  narrowStringToUnion,
68
+ typeOnRightExtendsLeftType,
63
69
  typedObjectEntries,
64
- typedObjectKeys
70
+ typedObjectKeys,
71
+ unionsAreTheSame
65
72
  });
@@ -18,10 +18,33 @@ declare function narrowStringToUnion<const T extends string>(key: string | undef
18
18
  * @template SubType - The type that should extend BaseType
19
19
  * @returns {unknown} Returns undefined, only used for type checking
20
20
  */
21
- declare function isSubTypeOf<BaseType, SubType extends BaseType>(): unknown;
21
+ declare function typeOnRightExtendsLeftType<BaseType, SubType extends BaseType>(): unknown;
22
+ /** @deprecated use typeOnRightExtendsLeftType instead */
23
+ declare const isSubTypeOf: typeof typeOnRightExtendsLeftType;
22
24
  /**
23
25
  * Type helper to narrow a string to a key of an object.
24
26
  */
25
27
  declare function isObjKey<T extends Record<string, unknown>>(key: unknown, obj: T): key is keyof T;
28
+ type UnionDiff<T, U> = [
29
+ T
30
+ ] extends [U] ? [
31
+ U
32
+ ] extends [T] ? null : {
33
+ onRightHasExtra: Exclude<U, T>;
34
+ } : [U] extends [T] ? {
35
+ onRightHasMissing: Exclude<T, U>;
36
+ } : {
37
+ onRightHasExtra: Exclude<U, T>;
38
+ onRightHasMissing: Exclude<T, U>;
39
+ };
40
+ /**
41
+ * Type helper to compare two union types and determine their relationship.
42
+ *
43
+ * @template T - The first union type (left side)
44
+ * @template U - The second union type (right side)
45
+ * @param _diff - null if unions are identical, or an object describing the difference
46
+ * @returns void - This function is only used for type checking
47
+ */
48
+ declare function unionsAreTheSame<T, U>(_diff: UnionDiff<T, U>): void;
26
49
 
27
- export { asNonPartial, asType, isObjKey, isSubTypeOf, narrowStringToUnion, typedObjectEntries, typedObjectKeys };
50
+ export { asNonPartial, asType, isObjKey, isSubTypeOf, narrowStringToUnion, typeOnRightExtendsLeftType, typedObjectEntries, typedObjectKeys, unionsAreTheSame };
@@ -18,10 +18,33 @@ declare function narrowStringToUnion<const T extends string>(key: string | undef
18
18
  * @template SubType - The type that should extend BaseType
19
19
  * @returns {unknown} Returns undefined, only used for type checking
20
20
  */
21
- declare function isSubTypeOf<BaseType, SubType extends BaseType>(): unknown;
21
+ declare function typeOnRightExtendsLeftType<BaseType, SubType extends BaseType>(): unknown;
22
+ /** @deprecated use typeOnRightExtendsLeftType instead */
23
+ declare const isSubTypeOf: typeof typeOnRightExtendsLeftType;
22
24
  /**
23
25
  * Type helper to narrow a string to a key of an object.
24
26
  */
25
27
  declare function isObjKey<T extends Record<string, unknown>>(key: unknown, obj: T): key is keyof T;
28
+ type UnionDiff<T, U> = [
29
+ T
30
+ ] extends [U] ? [
31
+ U
32
+ ] extends [T] ? null : {
33
+ onRightHasExtra: Exclude<U, T>;
34
+ } : [U] extends [T] ? {
35
+ onRightHasMissing: Exclude<T, U>;
36
+ } : {
37
+ onRightHasExtra: Exclude<U, T>;
38
+ onRightHasMissing: Exclude<T, U>;
39
+ };
40
+ /**
41
+ * Type helper to compare two union types and determine their relationship.
42
+ *
43
+ * @template T - The first union type (left side)
44
+ * @template U - The second union type (right side)
45
+ * @param _diff - null if unions are identical, or an object describing the difference
46
+ * @returns void - This function is only used for type checking
47
+ */
48
+ declare function unionsAreTheSame<T, U>(_diff: UnionDiff<T, U>): void;
26
49
 
27
- export { asNonPartial, asType, isObjKey, isSubTypeOf, narrowStringToUnion, typedObjectEntries, typedObjectKeys };
50
+ export { asNonPartial, asType, isObjKey, isSubTypeOf, narrowStringToUnion, typeOnRightExtendsLeftType, typedObjectEntries, typedObjectKeys, unionsAreTheSame };
@@ -17,18 +17,23 @@ function narrowStringToUnion(key, union) {
17
17
  }
18
18
  return void 0;
19
19
  }
20
- function isSubTypeOf() {
20
+ function typeOnRightExtendsLeftType() {
21
21
  return void 0;
22
22
  }
23
+ var isSubTypeOf = typeOnRightExtendsLeftType;
23
24
  function isObjKey(key, obj) {
24
25
  return typeof key === "string" && key in obj;
25
26
  }
27
+ function unionsAreTheSame(_diff) {
28
+ }
26
29
  export {
27
30
  asNonPartial,
28
31
  asType,
29
32
  isObjKey,
30
33
  isSubTypeOf,
31
34
  narrowStringToUnion,
35
+ typeOnRightExtendsLeftType,
32
36
  typedObjectEntries,
33
- typedObjectKeys
37
+ typedObjectKeys,
38
+ unionsAreTheSame
34
39
  };
@@ -24,7 +24,7 @@ __export(yamlStringify_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(yamlStringify_exports);
26
26
 
27
- // src/assertions.ts
27
+ // src/typeGuards.ts
28
28
  function isObject(value) {
29
29
  return typeof value === "object" && value !== null && !Array.isArray(value);
30
30
  }
@@ -40,6 +40,10 @@ function isPlainObject(value) {
40
40
  return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
41
41
  }
42
42
 
43
+ // src/assertions.ts
44
+ var isObject2 = isObject;
45
+ var isPlainObject2 = isPlainObject;
46
+
43
47
  // src/conversions.ts
44
48
  function bytesToHumanReadable(bytes) {
45
49
  if (bytes < 1024) {
@@ -70,7 +74,7 @@ function yamlStringify(obj, {
70
74
  maxDepth = 50,
71
75
  addRootObjSpaces = "beforeAndAfter"
72
76
  } = {}) {
73
- if (isObject(obj) || Array.isArray(obj) || typeof obj === "function") {
77
+ if (isObject2(obj) || Array.isArray(obj) || typeof obj === "function") {
74
78
  return `${stringifyValue(obj, "", maxLineLength, !!showUndefined, maxDepth, 0, addRootObjSpaces)}
75
79
  `;
76
80
  }
@@ -79,7 +83,7 @@ function yamlStringify(obj, {
79
83
  function stringifyValue(value, indent, maxLineLength, showUndefined, maxDepth, depth, addObjSpaces) {
80
84
  let result = "";
81
85
  const childIndent = `${indent} `;
82
- if (isPlainObject(value)) {
86
+ if (isPlainObject2(value)) {
83
87
  if (Object.keys(value).length === 0) {
84
88
  return "{}";
85
89
  }
@@ -106,7 +110,7 @@ function stringifyValue(value, indent, maxLineLength, showUndefined, maxDepth, d
106
110
  depth + 1,
107
111
  addObjSpaces
108
112
  );
109
- if (!afterSpaceWasAdded && indent === "" && isObject(objVal) && prevValue && (addObjSpaces === "before" || addObjSpaces === "beforeAndAfter")) {
113
+ if (!afterSpaceWasAdded && indent === "" && isObject2(objVal) && prevValue && (addObjSpaces === "before" || addObjSpaces === "beforeAndAfter")) {
110
114
  result += "\n";
111
115
  }
112
116
  if (Array.isArray(objVal)) {
@@ -117,7 +121,7 @@ function stringifyValue(value, indent, maxLineLength, showUndefined, maxDepth, d
117
121
  result += `${indent}${key}:
118
122
  `;
119
123
  }
120
- } else if (isObject(objVal)) {
124
+ } else if (isObject2(objVal)) {
121
125
  if (Object.keys(objVal).length === 0) {
122
126
  result += `${indent}${key}: `;
123
127
  } else {
@@ -130,7 +134,7 @@ function stringifyValue(value, indent, maxLineLength, showUndefined, maxDepth, d
130
134
  result += valueString;
131
135
  result += "\n";
132
136
  if (indent === "") {
133
- if (isObject(objVal)) {
137
+ if (isObject2(objVal)) {
134
138
  if (addObjSpaces === "after" || addObjSpaces === "beforeAndAfter") {
135
139
  result += "\n";
136
140
  afterSpaceWasAdded = true;
@@ -180,7 +184,7 @@ function stringifyValue(value, indent, maxLineLength, showUndefined, maxDepth, d
180
184
  item = `{max depth reached}`;
181
185
  }
182
186
  result += `${indent}- `;
183
- if (Array.isArray(item) || isObject(item)) {
187
+ if (Array.isArray(item) || isObject2(item)) {
184
188
  let arrayString = stringifyValue(
185
189
  item,
186
190
  childIndent,
@@ -227,8 +231,12 @@ ${indent}${line}
227
231
  }
228
232
  }
229
233
  } else {
230
- if (value.includes("'")) {
234
+ if (value.includes("'") && !value.includes('"')) {
231
235
  result += `"${value}"`;
236
+ } else if (value.includes('"') && !value.includes("'")) {
237
+ result += `'${value}'`;
238
+ } else if (value.includes("'") && value.includes('"')) {
239
+ result += `"${value.replace(/"/g, '\\"')}"`;
232
240
  } else {
233
241
  result += `'${value}'`;
234
242
  }
@@ -255,7 +263,7 @@ ${indent}${line}
255
263
  return JSON.stringify(value);
256
264
  }
257
265
  function normalizeValue(value) {
258
- if (value === null || isPlainObject(value) || Array.isArray(value)) {
266
+ if (value === null || isPlainObject2(value) || Array.isArray(value)) {
259
267
  return null;
260
268
  }
261
269
  if (value instanceof Map) {
@@ -4,7 +4,8 @@ import {
4
4
  import {
5
5
  isObject,
6
6
  isPlainObject
7
- } from "./chunk-3XCS7FVO.js";
7
+ } from "./chunk-WS4WEVHU.js";
8
+ import "./chunk-SSKW673U.js";
8
9
  import {
9
10
  bytesToHumanReadable
10
11
  } from "./chunk-IATIXMCE.js";
@@ -173,8 +174,12 @@ ${indent}${line}
173
174
  }
174
175
  }
175
176
  } else {
176
- if (value.includes("'")) {
177
+ if (value.includes("'") && !value.includes('"')) {
177
178
  result += `"${value}"`;
179
+ } else if (value.includes('"') && !value.includes("'")) {
180
+ result += `'${value}'`;
181
+ } else if (value.includes("'") && value.includes('"')) {
182
+ result += `"${value.replace(/"/g, '\\"')}"`;
178
183
  } else {
179
184
  result += `'${value}'`;
180
185
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ls-stack/utils",
3
3
  "description": "Typescript utils",
4
- "version": "3.13.0",
4
+ "version": "3.15.0",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "lib"
@@ -150,6 +150,10 @@
150
150
  "import": "./lib/tsResult.js",
151
151
  "require": "./lib/tsResult.cjs"
152
152
  },
153
+ "./typeGuards": {
154
+ "import": "./lib/typeGuards.js",
155
+ "require": "./lib/typeGuards.cjs"
156
+ },
153
157
  "./typingFnUtils": {
154
158
  "import": "./lib/typingFnUtils.js",
155
159
  "require": "./lib/typingFnUtils.cjs"
@@ -1,66 +0,0 @@
1
- // src/assertions.ts
2
- var undefErrMsg = "not undefined assertion failed";
3
- var nullishErrMsg = "not nullish assertion failed";
4
- function notUndefined(value, errorMsg = undefErrMsg) {
5
- if (value === void 0) {
6
- throw new Error(errorMsg);
7
- }
8
- return value;
9
- }
10
- function notNullish(value, errorMsg = nullishErrMsg) {
11
- if (value === void 0 || value === null) {
12
- throw new Error(errorMsg);
13
- }
14
- return value;
15
- }
16
- function assertIsNotNullish(value, errorMsg = nullishErrMsg) {
17
- if (value === void 0 || value === null) {
18
- throw new Error(errorMsg);
19
- }
20
- }
21
- function assertIsNotUndefined(value, errorMsg = undefErrMsg) {
22
- if (value === void 0) {
23
- throw new Error(errorMsg);
24
- }
25
- }
26
- function invariant(condition, errorMsg = "Invariant violation") {
27
- if (!condition) {
28
- throw new Error(`Invariant violation: ${errorMsg}`);
29
- }
30
- }
31
- function exhaustiveCheck(narrowedType) {
32
- return new Error("This should never happen");
33
- }
34
- function isObject(value) {
35
- return typeof value === "object" && value !== null && !Array.isArray(value);
36
- }
37
- function isFunction(value) {
38
- return typeof value === "function";
39
- }
40
- function isPromise(value) {
41
- return isObject(value) && "then" in value && isFunction(value.then);
42
- }
43
- function isPlainObject(value) {
44
- if (!value || typeof value !== "object") return false;
45
- const proto = Object.getPrototypeOf(value);
46
- if (proto === null) {
47
- return true;
48
- }
49
- const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
50
- if (Ctor === Object) return true;
51
- const objectCtorString = Object.prototype.constructor.toString();
52
- return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
53
- }
54
-
55
- export {
56
- notUndefined,
57
- notNullish,
58
- assertIsNotNullish,
59
- assertIsNotUndefined,
60
- invariant,
61
- exhaustiveCheck,
62
- isObject,
63
- isFunction,
64
- isPromise,
65
- isPlainObject
66
- };