@ls-stack/utils 1.13.2 → 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.
- package/dist/arrayUtils.cjs +91 -0
- package/dist/arrayUtils.d.cts +51 -0
- package/dist/arrayUtils.js +1 -2
- package/dist/assertions.cjs +99 -0
- package/dist/assertions.d.cts +17 -0
- package/dist/assertions.js +1 -2
- package/dist/castValues.cjs +41 -0
- package/dist/castValues.d.cts +4 -0
- package/dist/castValues.js +0 -1
- package/dist/{chunk-FYMTZQ42.js → chunk-4UGSP3L3.js} +0 -1
- package/dist/{chunk-HLFWWIDK.js → chunk-5DZT3Z5Z.js} +0 -1
- package/dist/{chunk-W7X6NSGR.js → chunk-AZBBTE33.js} +0 -1
- package/dist/{chunk-MMKMF4GG.js → chunk-IATIXMCE.js} +0 -1
- package/dist/chunk-JOBPQAI3.js +147 -0
- package/dist/{chunk-M74KKYE4.js → chunk-KCOXGSRA.js} +0 -1
- package/dist/{chunk-NKCC3375.js → chunk-NWXBMMHO.js} +0 -1
- package/dist/{chunk-SNAAKCTH.js → chunk-RVVH3MDA.js} +0 -1
- package/dist/{chunk-4QK76IRX.js → chunk-T5WDDPFI.js} +1 -6
- package/dist/{chunk-GLZ5MZC5.js → chunk-V2L472LS.js} +0 -30
- package/dist/consoleFmt.cjs +84 -0
- package/dist/consoleFmt.d.cts +48 -0
- package/dist/consoleFmt.js +0 -1
- package/dist/conversions.cjs +44 -0
- package/dist/conversions.d.cts +3 -0
- package/dist/conversions.js +1 -2
- package/dist/createThrottleController.cjs +183 -0
- package/dist/createThrottleController.d.cts +16 -0
- package/dist/createThrottleController.js +2 -3
- package/dist/debounce.cjs +125 -0
- package/dist/debounce.d.cts +45 -0
- package/dist/debounce.js +0 -1
- package/dist/dedent.cjs +57 -0
- package/dist/dedent.d.cts +4 -0
- package/dist/dedent.js +0 -1
- package/dist/deepEqual.cjs +88 -0
- package/dist/deepEqual.d.cts +4 -0
- package/dist/deepEqual.js +1 -2
- package/dist/enhancedMap.cjs +128 -0
- package/dist/enhancedMap.d.cts +20 -0
- package/dist/enhancedMap.d.ts +0 -2
- package/dist/enhancedMap.js +2 -3
- package/dist/exhaustiveMatch.cjs +55 -0
- package/dist/exhaustiveMatch.d.cts +6 -0
- package/dist/exhaustiveMatch.js +0 -1
- package/dist/interpolate.cjs +88 -0
- package/dist/interpolate.d.cts +11 -0
- package/dist/interpolate.js +2 -3
- package/dist/levenshtein.cjs +180 -0
- package/dist/levenshtein.d.cts +5 -0
- package/dist/levenshtein.js +0 -1
- package/dist/main.cjs +4 -0
- package/dist/main.d.cts +2 -0
- package/dist/main.d.ts +1 -1
- package/dist/main.js +0 -1
- package/dist/mathUtils.cjs +50 -0
- package/dist/mathUtils.d.cts +6 -0
- package/dist/mathUtils.js +1 -2
- package/dist/objUtils.cjs +67 -0
- package/dist/objUtils.d.cts +7 -0
- package/dist/objUtils.js +1 -2
- package/dist/parallelAsyncCalls.cjs +265 -0
- package/dist/{parallelAsyncResultCalls.d.ts → parallelAsyncCalls.d.cts} +7 -7
- package/dist/parallelAsyncCalls.d.ts +76 -0
- package/dist/{parallelAsyncResultCalls.js → parallelAsyncCalls.js} +7 -9
- package/dist/promiseUtils.cjs +38 -0
- package/dist/promiseUtils.d.cts +8 -0
- package/dist/promiseUtils.js +0 -1
- package/dist/rsResult.cjs +179 -0
- package/dist/rsResult.d.cts +88 -0
- package/dist/rsResult.d.ts +33 -63
- package/dist/rsResult.js +6 -10
- package/dist/runShellCmd.cjs +127 -0
- package/dist/runShellCmd.d.cts +23 -0
- package/dist/runShellCmd.d.ts +2 -1
- package/dist/runShellCmd.js +9 -4
- package/dist/shallowEqual.cjs +88 -0
- package/dist/shallowEqual.d.cts +4 -0
- package/dist/shallowEqual.js +0 -1
- package/dist/sleep.cjs +32 -0
- package/dist/sleep.d.cts +3 -0
- package/dist/sleep.js +1 -2
- package/dist/stringUtils.cjs +66 -0
- package/dist/stringUtils.d.cts +16 -0
- package/dist/stringUtils.d.ts +1 -3
- package/dist/stringUtils.js +1 -4
- package/dist/testUtils.cjs +357 -0
- package/dist/testUtils.d.cts +38 -0
- package/dist/testUtils.js +5 -6
- package/dist/typingFnUtils.cjs +55 -0
- package/dist/typingFnUtils.d.cts +15 -0
- package/dist/typingFnUtils.js +0 -1
- package/dist/typingTestUtils.cjs +43 -0
- package/dist/typingTestUtils.d.cts +12 -0
- package/dist/typingTestUtils.js +0 -1
- package/dist/typingUtils.cjs +18 -0
- package/dist/typingUtils.d.cts +11 -0
- package/dist/typingUtils.js +0 -1
- package/dist/yamlStringify.cjs +346 -0
- package/dist/yamlStringify.d.cts +8 -0
- package/dist/yamlStringify.js +3 -4
- package/package.json +64 -34
- package/dist/arrayUtils.js.map +0 -1
- package/dist/assertions.js.map +0 -1
- package/dist/castValues.js.map +0 -1
- package/dist/chunk-4QK76IRX.js.map +0 -1
- package/dist/chunk-FYMTZQ42.js.map +0 -1
- package/dist/chunk-GLZ5MZC5.js.map +0 -1
- package/dist/chunk-HLFWWIDK.js.map +0 -1
- package/dist/chunk-I7ZDKDUM.js +0 -217
- package/dist/chunk-I7ZDKDUM.js.map +0 -1
- package/dist/chunk-M74KKYE4.js.map +0 -1
- package/dist/chunk-MMKMF4GG.js.map +0 -1
- package/dist/chunk-NKCC3375.js.map +0 -1
- package/dist/chunk-SNAAKCTH.js.map +0 -1
- package/dist/chunk-W7X6NSGR.js.map +0 -1
- package/dist/consoleFmt.js.map +0 -1
- package/dist/conversions.js.map +0 -1
- package/dist/createThrottleController.js.map +0 -1
- package/dist/debounce.js.map +0 -1
- package/dist/dedent.js.map +0 -1
- package/dist/deepEqual.js.map +0 -1
- package/dist/enhancedMap.js.map +0 -1
- package/dist/exhaustiveMatch.js.map +0 -1
- package/dist/interpolate.js.map +0 -1
- package/dist/levenshtein.js.map +0 -1
- package/dist/main.js.map +0 -1
- package/dist/mathUtils.js.map +0 -1
- package/dist/objUtils.js.map +0 -1
- package/dist/parallelAsyncResultCalls.js.map +0 -1
- package/dist/promiseUtils.js.map +0 -1
- package/dist/rsResult.js.map +0 -1
- package/dist/runShellCmd.js.map +0 -1
- package/dist/shallowEqual.js.map +0 -1
- package/dist/sleep.js.map +0 -1
- package/dist/stringUtils.js.map +0 -1
- package/dist/testUtils.js.map +0 -1
- package/dist/typingFnUtils.js.map +0 -1
- package/dist/typingTestUtils.js.map +0 -1
- package/dist/typingUtils.js.map +0 -1
- package/dist/yamlStringify.js.map +0 -1
|
@@ -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 };
|
package/dist/typingFnUtils.js
CHANGED
|
@@ -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 };
|
package/dist/typingTestUtils.js
CHANGED
|
@@ -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 };
|
package/dist/typingUtils.js
CHANGED
|
@@ -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 };
|
package/dist/yamlStringify.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
truncateString
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-V2L472LS.js";
|
|
4
4
|
import {
|
|
5
5
|
bytesToHumanReadable
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-IATIXMCE.js";
|
|
7
7
|
import {
|
|
8
8
|
isObject,
|
|
9
9
|
isPlainObject
|
|
10
|
-
} from "./chunk-
|
|
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
|