@ls-stack/utils 2.14.0 → 3.1.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/assertions.cjs +5 -5
- package/dist/assertions.d.cts +2 -2
- package/dist/assertions.d.ts +2 -2
- package/dist/assertions.js +1 -1
- package/dist/cache.cjs +13 -10
- package/dist/cache.d.cts +6 -6
- package/dist/cache.d.ts +6 -6
- package/dist/cache.js +11 -11
- package/dist/castValues.cjs +12 -4
- package/dist/castValues.js +1 -1
- package/dist/{chunk-4UGSP3L3.js → chunk-2TIVYE43.js} +5 -5
- package/dist/{chunk-T5WDDPFI.js → chunk-4DCLNY64.js} +1 -1
- package/dist/{chunk-KBFP7INB.js → chunk-55DQGPY3.js} +67 -38
- package/dist/{chunk-RK6PT7JY.js → chunk-5MNYPLZI.js} +1 -1
- package/dist/chunk-II4R3VVX.js +25 -0
- package/dist/createThrottleController.js +4 -4
- package/dist/enhancedMap.js +2 -2
- package/dist/exhaustiveMatch.cjs +13 -2
- package/dist/exhaustiveMatch.d.cts +4 -1
- package/dist/exhaustiveMatch.d.ts +4 -1
- package/dist/exhaustiveMatch.js +11 -1
- package/dist/getValueStableKey.cjs +83 -0
- package/dist/getValueStableKey.d.cts +10 -0
- package/dist/getValueStableKey.d.ts +10 -0
- package/dist/getValueStableKey.js +55 -0
- package/dist/interpolate.js +1 -1
- package/dist/main.d.ts +2 -2
- package/dist/parallelAsyncCalls.cjs +51 -18
- package/dist/parallelAsyncCalls.d.cts +1 -2
- package/dist/parallelAsyncCalls.d.ts +1 -2
- package/dist/parallelAsyncCalls.js +5 -5
- package/dist/testUtils.js +1 -1
- package/dist/time.cjs +12 -4
- package/dist/time.js +2 -2
- package/dist/{rsResult.cjs → tsResult.cjs} +74 -43
- package/dist/{rsResult.d.cts → tsResult.d.cts} +34 -23
- package/dist/{rsResult.d.ts → tsResult.d.ts} +34 -23
- package/dist/tsResult.js +16 -0
- package/dist/typingTestUtils.cjs +4 -1
- package/dist/typingTestUtils.d.cts +26 -0
- package/dist/typingTestUtils.d.ts +26 -0
- package/dist/typingTestUtils.js +4 -1
- package/dist/typingUtils.d.cts +4 -1
- package/dist/typingUtils.d.ts +4 -1
- package/dist/yamlStringify.js +1 -1
- package/package.json +15 -15
- package/dist/chunk-GBFS2I67.js +0 -17
- package/dist/getObjStableKey.cjs +0 -83
- package/dist/getObjStableKey.d.cts +0 -3
- package/dist/getObjStableKey.d.ts +0 -3
- package/dist/getObjStableKey.js +0 -44
- package/dist/rsResult.js +0 -20
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { safeJsonStringify as safeJsonStringify$1 } from './safeJson.cjs';
|
|
2
|
-
|
|
3
1
|
type Ok<T> = {
|
|
4
2
|
ok: true;
|
|
5
3
|
error: false;
|
|
6
4
|
value: T;
|
|
7
|
-
};
|
|
5
|
+
} & AnyResultMethods;
|
|
6
|
+
type AnyResultMethods = Record<ResultMethodsKeys, never>;
|
|
8
7
|
type ResultValidErrors = Error | Record<string, unknown> | unknown[] | true;
|
|
9
8
|
type Err<E extends ResultValidErrors> = {
|
|
10
9
|
ok: false;
|
|
11
10
|
error: E;
|
|
12
11
|
errorResult: () => Result<any, E>;
|
|
13
|
-
};
|
|
12
|
+
} & AnyResultMethods;
|
|
14
13
|
type ResultMethods<T, E extends ResultValidErrors> = {
|
|
15
14
|
/** Returns the value if the result is Ok, otherwise returns null */
|
|
16
15
|
unwrapOrNull: () => T | null;
|
|
@@ -23,13 +22,14 @@ type ResultMethods<T, E extends ResultValidErrors> = {
|
|
|
23
22
|
ok: (value: T) => NewValue;
|
|
24
23
|
err: (error: E) => NewError;
|
|
25
24
|
}) => Result<NewValue, NewError>;
|
|
25
|
+
ifOk: (fn: (value: T) => void) => Result<T, E>;
|
|
26
|
+
ifErr: (fn: (error: E) => void) => Result<T, E>;
|
|
26
27
|
};
|
|
27
|
-
type
|
|
28
|
-
declare function ok():
|
|
29
|
-
declare function ok<T>(value: T):
|
|
30
|
-
|
|
31
|
-
declare function
|
|
32
|
-
declare function unknownToResultError(error: unknown): ErrResult<Error, any>;
|
|
28
|
+
type ResultMethodsKeys = keyof ResultMethods<any, any>;
|
|
29
|
+
declare function ok(): Ok<void>;
|
|
30
|
+
declare function ok<T>(value: T): Ok<T>;
|
|
31
|
+
declare function err<E extends ResultValidErrors>(error: E): Err<E>;
|
|
32
|
+
declare function unknownToResultError(error: unknown): Err<Error>;
|
|
33
33
|
/** Unwraps a promise result */
|
|
34
34
|
declare function asyncUnwrap<T>(result: Promise<Result<T, ResultValidErrors>>): Promise<T>;
|
|
35
35
|
declare function asyncMap<T, E extends ResultValidErrors>(resultPromise: Promise<Result<T, E>>): {
|
|
@@ -62,18 +62,18 @@ declare function asyncMap<T, E extends ResultValidErrors>(resultPromise: Promise
|
|
|
62
62
|
* // result.error is an Error
|
|
63
63
|
* }
|
|
64
64
|
*/
|
|
65
|
-
type Result<T, E extends ResultValidErrors = Error> =
|
|
65
|
+
type Result<T, E extends ResultValidErrors = Error> = (Omit<Ok<T>, ResultMethodsKeys> | Omit<Err<E>, ResultMethodsKeys>) & ResultMethods<T, E>;
|
|
66
66
|
declare const Result: {
|
|
67
67
|
ok: typeof ok;
|
|
68
68
|
err: typeof err;
|
|
69
69
|
unknownToError: typeof unknownToResultError;
|
|
70
70
|
asyncUnwrap: typeof asyncUnwrap;
|
|
71
71
|
asyncMap: typeof asyncMap;
|
|
72
|
+
getOkErr: typeof getOkErr;
|
|
72
73
|
};
|
|
73
|
-
|
|
74
|
-
declare function resultify<T, E extends ResultValidErrors = Error>(fn: () => T
|
|
75
|
-
|
|
76
|
-
declare function asyncResultify<T, E extends Error = Error>(fn: () => Promise<T>, errorNormalizer?: (err: unknown) => E): Promise<Result<Awaited<T>, E>>;
|
|
74
|
+
declare function resultify<T, E extends ResultValidErrors = Error>(fn: () => T extends Promise<any> ? never : T, errorNormalizer?: (err: unknown) => E): Result<T, E>;
|
|
75
|
+
declare function resultify<T, E extends ResultValidErrors = Error>(fn: () => Promise<T>, errorNormalizer?: (err: unknown) => E): Promise<Result<Awaited<T>, E>>;
|
|
76
|
+
declare function resultify<T, E extends ResultValidErrors = Error>(fn: Promise<T>, errorNormalizer?: (err: unknown) => E): Promise<Result<T, E>>;
|
|
77
77
|
/**
|
|
78
78
|
* Converts an unknown error value into an Error object.
|
|
79
79
|
*
|
|
@@ -96,14 +96,25 @@ declare function asyncResultify<T, E extends Error = Error>(fn: () => Promise<T>
|
|
|
96
96
|
* The original error value is preserved as the `cause` property of the returned Error.
|
|
97
97
|
*/
|
|
98
98
|
declare function unknownToError(error: unknown): Error;
|
|
99
|
-
/** @deprecated use unknownToError instead, this will be removed in the next major version */
|
|
100
|
-
declare function normalizeError(error: unknown): Error;
|
|
101
|
-
/** @deprecated use safeJsonStringify from `@ls-stack/utils/safeJson` instead, this will be removed in the next major version */
|
|
102
|
-
declare const safeJsonStringify: typeof safeJsonStringify$1;
|
|
103
99
|
type TypedResult<T, E extends ResultValidErrors = Error> = {
|
|
104
|
-
ok: (value: T) =>
|
|
105
|
-
err: (error: E) =>
|
|
100
|
+
ok: (value: T) => Ok<T>;
|
|
101
|
+
err: (error: E) => Err<E>;
|
|
102
|
+
/**
|
|
103
|
+
* Use in combination with `typeof` to get the return type of the result
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* const typedResult = createTypedResult<{ a: 'test' }>();
|
|
107
|
+
*
|
|
108
|
+
* function foo(): typeof typedResult.type {
|
|
109
|
+
* return typedResult.ok({ a: 'test' });
|
|
110
|
+
* }
|
|
111
|
+
*/
|
|
112
|
+
_type: Result<T, E>;
|
|
106
113
|
};
|
|
107
|
-
|
|
114
|
+
type GetTypedResult<R extends Result<any, any>> = TypedResult<R extends Result<infer T, any> ? T : never, R extends Result<any, infer E> ? E : never>;
|
|
115
|
+
declare function getOkErr<F extends (...args: any[]) => Promise<Result<any, any>>>(): TypedResult<Awaited<ReturnType<F>> extends Result<infer T, any> ? T : never, Awaited<ReturnType<F>> extends Result<any, infer E> ? E : never>;
|
|
116
|
+
declare function getOkErr<F extends (...args: any[]) => Result<any, any>>(): TypedResult<ReturnType<F> extends Result<infer T, any> ? T : never, ReturnType<F> extends Result<any, infer E> ? E : never>;
|
|
117
|
+
declare function getOkErr<R extends Result<any, any>>(): TypedResult<R extends Result<infer T, any> ? T : never, R extends Result<any, infer E> ? E : never>;
|
|
118
|
+
declare function getOkErr<T, E extends ResultValidErrors = Error>(): TypedResult<T, E>;
|
|
108
119
|
|
|
109
|
-
export { Result, type
|
|
120
|
+
export { type GetTypedResult, Result, type ResultValidErrors, type TypedResult, err, ok, resultify, unknownToError };
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { safeJsonStringify as safeJsonStringify$1 } from './safeJson.js';
|
|
2
|
-
|
|
3
1
|
type Ok<T> = {
|
|
4
2
|
ok: true;
|
|
5
3
|
error: false;
|
|
6
4
|
value: T;
|
|
7
|
-
};
|
|
5
|
+
} & AnyResultMethods;
|
|
6
|
+
type AnyResultMethods = Record<ResultMethodsKeys, never>;
|
|
8
7
|
type ResultValidErrors = Error | Record<string, unknown> | unknown[] | true;
|
|
9
8
|
type Err<E extends ResultValidErrors> = {
|
|
10
9
|
ok: false;
|
|
11
10
|
error: E;
|
|
12
11
|
errorResult: () => Result<any, E>;
|
|
13
|
-
};
|
|
12
|
+
} & AnyResultMethods;
|
|
14
13
|
type ResultMethods<T, E extends ResultValidErrors> = {
|
|
15
14
|
/** Returns the value if the result is Ok, otherwise returns null */
|
|
16
15
|
unwrapOrNull: () => T | null;
|
|
@@ -23,13 +22,14 @@ type ResultMethods<T, E extends ResultValidErrors> = {
|
|
|
23
22
|
ok: (value: T) => NewValue;
|
|
24
23
|
err: (error: E) => NewError;
|
|
25
24
|
}) => Result<NewValue, NewError>;
|
|
25
|
+
ifOk: (fn: (value: T) => void) => Result<T, E>;
|
|
26
|
+
ifErr: (fn: (error: E) => void) => Result<T, E>;
|
|
26
27
|
};
|
|
27
|
-
type
|
|
28
|
-
declare function ok():
|
|
29
|
-
declare function ok<T>(value: T):
|
|
30
|
-
|
|
31
|
-
declare function
|
|
32
|
-
declare function unknownToResultError(error: unknown): ErrResult<Error, any>;
|
|
28
|
+
type ResultMethodsKeys = keyof ResultMethods<any, any>;
|
|
29
|
+
declare function ok(): Ok<void>;
|
|
30
|
+
declare function ok<T>(value: T): Ok<T>;
|
|
31
|
+
declare function err<E extends ResultValidErrors>(error: E): Err<E>;
|
|
32
|
+
declare function unknownToResultError(error: unknown): Err<Error>;
|
|
33
33
|
/** Unwraps a promise result */
|
|
34
34
|
declare function asyncUnwrap<T>(result: Promise<Result<T, ResultValidErrors>>): Promise<T>;
|
|
35
35
|
declare function asyncMap<T, E extends ResultValidErrors>(resultPromise: Promise<Result<T, E>>): {
|
|
@@ -62,18 +62,18 @@ declare function asyncMap<T, E extends ResultValidErrors>(resultPromise: Promise
|
|
|
62
62
|
* // result.error is an Error
|
|
63
63
|
* }
|
|
64
64
|
*/
|
|
65
|
-
type Result<T, E extends ResultValidErrors = Error> =
|
|
65
|
+
type Result<T, E extends ResultValidErrors = Error> = (Omit<Ok<T>, ResultMethodsKeys> | Omit<Err<E>, ResultMethodsKeys>) & ResultMethods<T, E>;
|
|
66
66
|
declare const Result: {
|
|
67
67
|
ok: typeof ok;
|
|
68
68
|
err: typeof err;
|
|
69
69
|
unknownToError: typeof unknownToResultError;
|
|
70
70
|
asyncUnwrap: typeof asyncUnwrap;
|
|
71
71
|
asyncMap: typeof asyncMap;
|
|
72
|
+
getOkErr: typeof getOkErr;
|
|
72
73
|
};
|
|
73
|
-
|
|
74
|
-
declare function resultify<T, E extends ResultValidErrors = Error>(fn: () => T
|
|
75
|
-
|
|
76
|
-
declare function asyncResultify<T, E extends Error = Error>(fn: () => Promise<T>, errorNormalizer?: (err: unknown) => E): Promise<Result<Awaited<T>, E>>;
|
|
74
|
+
declare function resultify<T, E extends ResultValidErrors = Error>(fn: () => T extends Promise<any> ? never : T, errorNormalizer?: (err: unknown) => E): Result<T, E>;
|
|
75
|
+
declare function resultify<T, E extends ResultValidErrors = Error>(fn: () => Promise<T>, errorNormalizer?: (err: unknown) => E): Promise<Result<Awaited<T>, E>>;
|
|
76
|
+
declare function resultify<T, E extends ResultValidErrors = Error>(fn: Promise<T>, errorNormalizer?: (err: unknown) => E): Promise<Result<T, E>>;
|
|
77
77
|
/**
|
|
78
78
|
* Converts an unknown error value into an Error object.
|
|
79
79
|
*
|
|
@@ -96,14 +96,25 @@ declare function asyncResultify<T, E extends Error = Error>(fn: () => Promise<T>
|
|
|
96
96
|
* The original error value is preserved as the `cause` property of the returned Error.
|
|
97
97
|
*/
|
|
98
98
|
declare function unknownToError(error: unknown): Error;
|
|
99
|
-
/** @deprecated use unknownToError instead, this will be removed in the next major version */
|
|
100
|
-
declare function normalizeError(error: unknown): Error;
|
|
101
|
-
/** @deprecated use safeJsonStringify from `@ls-stack/utils/safeJson` instead, this will be removed in the next major version */
|
|
102
|
-
declare const safeJsonStringify: typeof safeJsonStringify$1;
|
|
103
99
|
type TypedResult<T, E extends ResultValidErrors = Error> = {
|
|
104
|
-
ok: (value: T) =>
|
|
105
|
-
err: (error: E) =>
|
|
100
|
+
ok: (value: T) => Ok<T>;
|
|
101
|
+
err: (error: E) => Err<E>;
|
|
102
|
+
/**
|
|
103
|
+
* Use in combination with `typeof` to get the return type of the result
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* const typedResult = createTypedResult<{ a: 'test' }>();
|
|
107
|
+
*
|
|
108
|
+
* function foo(): typeof typedResult.type {
|
|
109
|
+
* return typedResult.ok({ a: 'test' });
|
|
110
|
+
* }
|
|
111
|
+
*/
|
|
112
|
+
_type: Result<T, E>;
|
|
106
113
|
};
|
|
107
|
-
|
|
114
|
+
type GetTypedResult<R extends Result<any, any>> = TypedResult<R extends Result<infer T, any> ? T : never, R extends Result<any, infer E> ? E : never>;
|
|
115
|
+
declare function getOkErr<F extends (...args: any[]) => Promise<Result<any, any>>>(): TypedResult<Awaited<ReturnType<F>> extends Result<infer T, any> ? T : never, Awaited<ReturnType<F>> extends Result<any, infer E> ? E : never>;
|
|
116
|
+
declare function getOkErr<F extends (...args: any[]) => Result<any, any>>(): TypedResult<ReturnType<F> extends Result<infer T, any> ? T : never, ReturnType<F> extends Result<any, infer E> ? E : never>;
|
|
117
|
+
declare function getOkErr<R extends Result<any, any>>(): TypedResult<R extends Result<infer T, any> ? T : never, R extends Result<any, infer E> ? E : never>;
|
|
118
|
+
declare function getOkErr<T, E extends ResultValidErrors = Error>(): TypedResult<T, E>;
|
|
108
119
|
|
|
109
|
-
export { Result, type
|
|
120
|
+
export { type GetTypedResult, Result, type ResultValidErrors, type TypedResult, err, ok, resultify, unknownToError };
|
package/dist/tsResult.js
ADDED
package/dist/typingTestUtils.cjs
CHANGED
|
@@ -32,10 +32,13 @@ function describe(title, func) {
|
|
|
32
32
|
function expectType() {
|
|
33
33
|
return {};
|
|
34
34
|
}
|
|
35
|
+
function expectTypesAre(result) {
|
|
36
|
+
}
|
|
35
37
|
var typingTest = {
|
|
36
38
|
test,
|
|
37
39
|
describe,
|
|
38
|
-
expectType
|
|
40
|
+
expectType,
|
|
41
|
+
expectTypesAre
|
|
39
42
|
};
|
|
40
43
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
44
|
0 && (module.exports = {
|
|
@@ -2,11 +2,37 @@ type TestTypeIsEqual<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T e
|
|
|
2
2
|
type TestTypeNotEqual<X, Y> = true extends TestTypeIsEqual<X, Y> ? false : true;
|
|
3
3
|
declare function test(title: string, func: () => any): void;
|
|
4
4
|
declare function describe(title: string, func: () => any): void;
|
|
5
|
+
/**
|
|
6
|
+
* Helper function for type testing that ensures a type extends `true`.
|
|
7
|
+
* Used in combination with `TestTypeIsEqual` to verify type equality at compile time.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* expectType<TestTypeIsEqual<string, string>>(); // OK
|
|
11
|
+
* expectType<TestTypeIsEqual<string, number>>(); // Type error
|
|
12
|
+
*
|
|
13
|
+
* @template T Type that must extend `true`
|
|
14
|
+
* @returns An empty object cast to type T
|
|
15
|
+
*/
|
|
5
16
|
declare function expectType<T extends true>(): T;
|
|
17
|
+
/**
|
|
18
|
+
* Helper function for type testing that compares two types and expects a specific result.
|
|
19
|
+
* This function allows for more explicit type equality assertions with a descriptive result.
|
|
20
|
+
*
|
|
21
|
+
* @template X First type to compare
|
|
22
|
+
* @template Y Second type to compare
|
|
23
|
+
* @param result Expected comparison result: 'equal' if types are equal, 'notEqual' if they differ
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* expectTypesAre<string, string>('equal'); // OK
|
|
27
|
+
* expectTypesAre<string, number>('notEqual'); // OK
|
|
28
|
+
* expectTypesAre<string, string>('notEqual'); // Type error
|
|
29
|
+
*/
|
|
30
|
+
declare function expectTypesAre<X, Y>(result: TestTypeIsEqual<X, Y> extends true ? 'equal' : 'notEqual'): void;
|
|
6
31
|
declare const typingTest: {
|
|
7
32
|
test: typeof test;
|
|
8
33
|
describe: typeof describe;
|
|
9
34
|
expectType: typeof expectType;
|
|
35
|
+
expectTypesAre: typeof expectTypesAre;
|
|
10
36
|
};
|
|
11
37
|
|
|
12
38
|
export { type TestTypeIsEqual, type TestTypeNotEqual, typingTest };
|
|
@@ -2,11 +2,37 @@ type TestTypeIsEqual<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T e
|
|
|
2
2
|
type TestTypeNotEqual<X, Y> = true extends TestTypeIsEqual<X, Y> ? false : true;
|
|
3
3
|
declare function test(title: string, func: () => any): void;
|
|
4
4
|
declare function describe(title: string, func: () => any): void;
|
|
5
|
+
/**
|
|
6
|
+
* Helper function for type testing that ensures a type extends `true`.
|
|
7
|
+
* Used in combination with `TestTypeIsEqual` to verify type equality at compile time.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* expectType<TestTypeIsEqual<string, string>>(); // OK
|
|
11
|
+
* expectType<TestTypeIsEqual<string, number>>(); // Type error
|
|
12
|
+
*
|
|
13
|
+
* @template T Type that must extend `true`
|
|
14
|
+
* @returns An empty object cast to type T
|
|
15
|
+
*/
|
|
5
16
|
declare function expectType<T extends true>(): T;
|
|
17
|
+
/**
|
|
18
|
+
* Helper function for type testing that compares two types and expects a specific result.
|
|
19
|
+
* This function allows for more explicit type equality assertions with a descriptive result.
|
|
20
|
+
*
|
|
21
|
+
* @template X First type to compare
|
|
22
|
+
* @template Y Second type to compare
|
|
23
|
+
* @param result Expected comparison result: 'equal' if types are equal, 'notEqual' if they differ
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* expectTypesAre<string, string>('equal'); // OK
|
|
27
|
+
* expectTypesAre<string, number>('notEqual'); // OK
|
|
28
|
+
* expectTypesAre<string, string>('notEqual'); // Type error
|
|
29
|
+
*/
|
|
30
|
+
declare function expectTypesAre<X, Y>(result: TestTypeIsEqual<X, Y> extends true ? 'equal' : 'notEqual'): void;
|
|
6
31
|
declare const typingTest: {
|
|
7
32
|
test: typeof test;
|
|
8
33
|
describe: typeof describe;
|
|
9
34
|
expectType: typeof expectType;
|
|
35
|
+
expectTypesAre: typeof expectTypesAre;
|
|
10
36
|
};
|
|
11
37
|
|
|
12
38
|
export { type TestTypeIsEqual, type TestTypeNotEqual, typingTest };
|
package/dist/typingTestUtils.js
CHANGED
package/dist/typingUtils.d.cts
CHANGED
|
@@ -7,5 +7,8 @@ type NonPartial<T> = {
|
|
|
7
7
|
type ObjKeysWithValuesOfType<Obj extends Record<PropertyKey, unknown>, ValueType> = {
|
|
8
8
|
[K in keyof Obj]: Obj[K] extends ValueType ? K : never;
|
|
9
9
|
}[keyof Obj];
|
|
10
|
+
type IsAny<T> = unknown extends T ? [
|
|
11
|
+
keyof T
|
|
12
|
+
] extends [never] ? false : true : false;
|
|
10
13
|
|
|
11
|
-
export type { NonPartial, ObjKeysWithValuesOfType, PartialRecord };
|
|
14
|
+
export type { IsAny, NonPartial, ObjKeysWithValuesOfType, PartialRecord };
|
package/dist/typingUtils.d.ts
CHANGED
|
@@ -7,5 +7,8 @@ type NonPartial<T> = {
|
|
|
7
7
|
type ObjKeysWithValuesOfType<Obj extends Record<PropertyKey, unknown>, ValueType> = {
|
|
8
8
|
[K in keyof Obj]: Obj[K] extends ValueType ? K : never;
|
|
9
9
|
}[keyof Obj];
|
|
10
|
+
type IsAny<T> = unknown extends T ? [
|
|
11
|
+
keyof T
|
|
12
|
+
] extends [never] ? false : true : false;
|
|
10
13
|
|
|
11
|
-
export type { NonPartial, ObjKeysWithValuesOfType, PartialRecord };
|
|
14
|
+
export type { IsAny, NonPartial, ObjKeysWithValuesOfType, PartialRecord };
|
package/dist/yamlStringify.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ls-stack/utils",
|
|
3
3
|
"description": "Typescript utils",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.1.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -79,10 +79,10 @@
|
|
|
79
79
|
"types": "./dist/exhaustiveMatch.d.ts",
|
|
80
80
|
"require": "./dist/exhaustiveMatch.cjs"
|
|
81
81
|
},
|
|
82
|
-
"./
|
|
83
|
-
"import": "./dist/
|
|
84
|
-
"types": "./dist/
|
|
85
|
-
"require": "./dist/
|
|
82
|
+
"./getValueStableKey": {
|
|
83
|
+
"import": "./dist/getValueStableKey.js",
|
|
84
|
+
"types": "./dist/getValueStableKey.d.ts",
|
|
85
|
+
"require": "./dist/getValueStableKey.cjs"
|
|
86
86
|
},
|
|
87
87
|
"./internalUtils": {
|
|
88
88
|
"import": "./dist/internalUtils.js",
|
|
@@ -129,11 +129,6 @@
|
|
|
129
129
|
"types": "./dist/retryOnError.d.ts",
|
|
130
130
|
"require": "./dist/retryOnError.cjs"
|
|
131
131
|
},
|
|
132
|
-
"./rsResult": {
|
|
133
|
-
"import": "./dist/rsResult.js",
|
|
134
|
-
"types": "./dist/rsResult.d.ts",
|
|
135
|
-
"require": "./dist/rsResult.cjs"
|
|
136
|
-
},
|
|
137
132
|
"./runShellCmd": {
|
|
138
133
|
"import": "./dist/runShellCmd.js",
|
|
139
134
|
"types": "./dist/runShellCmd.d.ts",
|
|
@@ -169,6 +164,11 @@
|
|
|
169
164
|
"types": "./dist/time.d.ts",
|
|
170
165
|
"require": "./dist/time.cjs"
|
|
171
166
|
},
|
|
167
|
+
"./tsResult": {
|
|
168
|
+
"import": "./dist/tsResult.js",
|
|
169
|
+
"types": "./dist/tsResult.d.ts",
|
|
170
|
+
"require": "./dist/tsResult.cjs"
|
|
171
|
+
},
|
|
172
172
|
"./typingFnUtils": {
|
|
173
173
|
"import": "./dist/typingFnUtils.js",
|
|
174
174
|
"types": "./dist/typingFnUtils.d.ts",
|
|
@@ -253,8 +253,8 @@
|
|
|
253
253
|
"exhaustiveMatch": [
|
|
254
254
|
"./dist/exhaustiveMatch.d.ts"
|
|
255
255
|
],
|
|
256
|
-
"
|
|
257
|
-
"./dist/
|
|
256
|
+
"getValueStableKey": [
|
|
257
|
+
"./dist/getValueStableKey.d.ts"
|
|
258
258
|
],
|
|
259
259
|
"internalUtils": [
|
|
260
260
|
"./dist/internalUtils.d.ts"
|
|
@@ -283,9 +283,6 @@
|
|
|
283
283
|
"retryOnError": [
|
|
284
284
|
"./dist/retryOnError.d.ts"
|
|
285
285
|
],
|
|
286
|
-
"rsResult": [
|
|
287
|
-
"./dist/rsResult.d.ts"
|
|
288
|
-
],
|
|
289
286
|
"runShellCmd": [
|
|
290
287
|
"./dist/runShellCmd.d.ts"
|
|
291
288
|
],
|
|
@@ -307,6 +304,9 @@
|
|
|
307
304
|
"time": [
|
|
308
305
|
"./dist/time.d.ts"
|
|
309
306
|
],
|
|
307
|
+
"tsResult": [
|
|
308
|
+
"./dist/tsResult.d.ts"
|
|
309
|
+
],
|
|
310
310
|
"typingFnUtils": [
|
|
311
311
|
"./dist/typingFnUtils.d.ts"
|
|
312
312
|
],
|
package/dist/chunk-GBFS2I67.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// src/castValues.ts
|
|
2
|
-
function castToString(value) {
|
|
3
|
-
const valueType = typeof value;
|
|
4
|
-
return valueType === "string" || valueType === "number" || valueType === "boolean" || valueType === "bigint" ? String(value) : null;
|
|
5
|
-
}
|
|
6
|
-
function castToNumber(value) {
|
|
7
|
-
return isNumeric(value) ? Number(value) : null;
|
|
8
|
-
}
|
|
9
|
-
function isNumeric(num) {
|
|
10
|
-
const str = String(num);
|
|
11
|
-
return !isNaN(str) && !isNaN(parseFloat(str));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export {
|
|
15
|
-
castToString,
|
|
16
|
-
castToNumber
|
|
17
|
-
};
|
package/dist/getObjStableKey.cjs
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
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/getObjStableKey.ts
|
|
21
|
-
var getObjStableKey_exports = {};
|
|
22
|
-
__export(getObjStableKey_exports, {
|
|
23
|
-
getObjStableKey: () => getObjStableKey
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(getObjStableKey_exports);
|
|
26
|
-
|
|
27
|
-
// src/arrayUtils.ts
|
|
28
|
-
function filterAndMap(array, mapFilter) {
|
|
29
|
-
const result = [];
|
|
30
|
-
let i = -1;
|
|
31
|
-
for (const item of array) {
|
|
32
|
-
i += 1;
|
|
33
|
-
const filterResult = mapFilter(item, i);
|
|
34
|
-
if (filterResult !== false) {
|
|
35
|
-
result.push(filterResult);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// src/assertions.ts
|
|
42
|
-
function isObject(value) {
|
|
43
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// src/getObjStableKey.ts
|
|
47
|
-
function getObjStableKey(input, maxDepth = 3) {
|
|
48
|
-
if (typeof input === "string") return String(input);
|
|
49
|
-
if (!input || typeof input !== "object") return `#$${input}$#`;
|
|
50
|
-
return JSON.stringify(sortValues(input, maxDepth, 0));
|
|
51
|
-
}
|
|
52
|
-
function sortValues(input, maxDepth, depth) {
|
|
53
|
-
if (depth >= maxDepth) return input;
|
|
54
|
-
if (Array.isArray(input)) {
|
|
55
|
-
return input.map((v) => sortValues(v, maxDepth, depth + 1));
|
|
56
|
-
}
|
|
57
|
-
if (isObject(input)) {
|
|
58
|
-
return orderedProps(input, (v) => sortValues(v, maxDepth, depth + 1));
|
|
59
|
-
}
|
|
60
|
-
return input;
|
|
61
|
-
}
|
|
62
|
-
var emptyObject = {};
|
|
63
|
-
function orderedProps(obj, mapValue) {
|
|
64
|
-
const keys = Object.keys(obj);
|
|
65
|
-
if (keys.length === 0) return emptyObject;
|
|
66
|
-
if (keys.length === 1) {
|
|
67
|
-
const value = obj[keys[0]];
|
|
68
|
-
if (value === void 0) return emptyObject;
|
|
69
|
-
return { [keys[0]]: mapValue(value) };
|
|
70
|
-
}
|
|
71
|
-
const mappedValues = filterAndMap(keys.sort(), (k) => {
|
|
72
|
-
const value = obj[k];
|
|
73
|
-
if (value === void 0) return false;
|
|
74
|
-
return { [k]: mapValue(value) };
|
|
75
|
-
});
|
|
76
|
-
if (mappedValues.length === 0) return emptyObject;
|
|
77
|
-
if (mappedValues.length === 1) return mappedValues[0];
|
|
78
|
-
return mappedValues;
|
|
79
|
-
}
|
|
80
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
-
0 && (module.exports = {
|
|
82
|
-
getObjStableKey
|
|
83
|
-
});
|
package/dist/getObjStableKey.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
filterAndMap
|
|
3
|
-
} from "./chunk-QMFZE2VO.js";
|
|
4
|
-
import {
|
|
5
|
-
isObject
|
|
6
|
-
} from "./chunk-4UGSP3L3.js";
|
|
7
|
-
|
|
8
|
-
// src/getObjStableKey.ts
|
|
9
|
-
function getObjStableKey(input, maxDepth = 3) {
|
|
10
|
-
if (typeof input === "string") return String(input);
|
|
11
|
-
if (!input || typeof input !== "object") return `#$${input}$#`;
|
|
12
|
-
return JSON.stringify(sortValues(input, maxDepth, 0));
|
|
13
|
-
}
|
|
14
|
-
function sortValues(input, maxDepth, depth) {
|
|
15
|
-
if (depth >= maxDepth) return input;
|
|
16
|
-
if (Array.isArray(input)) {
|
|
17
|
-
return input.map((v) => sortValues(v, maxDepth, depth + 1));
|
|
18
|
-
}
|
|
19
|
-
if (isObject(input)) {
|
|
20
|
-
return orderedProps(input, (v) => sortValues(v, maxDepth, depth + 1));
|
|
21
|
-
}
|
|
22
|
-
return input;
|
|
23
|
-
}
|
|
24
|
-
var emptyObject = {};
|
|
25
|
-
function orderedProps(obj, mapValue) {
|
|
26
|
-
const keys = Object.keys(obj);
|
|
27
|
-
if (keys.length === 0) return emptyObject;
|
|
28
|
-
if (keys.length === 1) {
|
|
29
|
-
const value = obj[keys[0]];
|
|
30
|
-
if (value === void 0) return emptyObject;
|
|
31
|
-
return { [keys[0]]: mapValue(value) };
|
|
32
|
-
}
|
|
33
|
-
const mappedValues = filterAndMap(keys.sort(), (k) => {
|
|
34
|
-
const value = obj[k];
|
|
35
|
-
if (value === void 0) return false;
|
|
36
|
-
return { [k]: mapValue(value) };
|
|
37
|
-
});
|
|
38
|
-
if (mappedValues.length === 0) return emptyObject;
|
|
39
|
-
if (mappedValues.length === 1) return mappedValues[0];
|
|
40
|
-
return mappedValues;
|
|
41
|
-
}
|
|
42
|
-
export {
|
|
43
|
-
getObjStableKey
|
|
44
|
-
};
|
package/dist/rsResult.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Result,
|
|
3
|
-
asyncResultify,
|
|
4
|
-
createTypedResult,
|
|
5
|
-
normalizeError,
|
|
6
|
-
resultify,
|
|
7
|
-
safeJsonStringify,
|
|
8
|
-
unknownToError
|
|
9
|
-
} from "./chunk-KBFP7INB.js";
|
|
10
|
-
import "./chunk-VAAMRG4K.js";
|
|
11
|
-
import "./chunk-4UGSP3L3.js";
|
|
12
|
-
export {
|
|
13
|
-
Result,
|
|
14
|
-
asyncResultify,
|
|
15
|
-
createTypedResult,
|
|
16
|
-
normalizeError,
|
|
17
|
-
resultify,
|
|
18
|
-
safeJsonStringify,
|
|
19
|
-
unknownToError
|
|
20
|
-
};
|