es-toolkit 1.49.0-dev.1970 → 1.49.0-dev.1974
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/array/partition.d.mts +5 -4
- package/dist/array/partition.d.ts +5 -4
- package/dist/types/DeepPartial.d.mts +21 -0
- package/dist/types/DeepPartial.d.ts +21 -0
- package/dist/types/DeepReadonly.d.mts +22 -0
- package/dist/types/DeepReadonly.d.ts +22 -0
- package/dist/types/NonEmptyArray.d.mts +14 -0
- package/dist/types/NonEmptyArray.d.ts +14 -0
- package/dist/types/Simplify.d.mts +18 -0
- package/dist/types/Simplify.d.ts +18 -0
- package/dist/types/ValueOf.d.mts +14 -0
- package/dist/types/ValueOf.d.ts +14 -0
- package/dist/types/Writable.d.mts +15 -0
- package/dist/types/Writable.d.ts +15 -0
- package/dist/types/index.d.mts +7 -0
- package/dist/types/index.d.ts +7 -0
- package/package.json +17 -1
- package/types.d.ts +1 -0
|
@@ -33,11 +33,12 @@ declare function partition<T, U extends T>(arr: readonly T[], isInTruthy: (value
|
|
|
33
33
|
* @template T - The type of elements in the array.
|
|
34
34
|
* @param arr - The array to partition.
|
|
35
35
|
* @param isInTruthy - A predicate function that determines
|
|
36
|
-
* whether an element should be placed in the truthy array.
|
|
36
|
+
* whether an element should be placed in the truthy array. An element is placed in the truthy
|
|
37
|
+
* array when the function returns a truthy value. The function is called with each
|
|
37
38
|
* element of the array and its index.
|
|
38
39
|
* @returns A tuple containing two arrays: the first array contains elements for
|
|
39
|
-
* which the predicate returned
|
|
40
|
-
* predicate returned
|
|
40
|
+
* which the predicate returned a truthy value, and the second array contains elements for which the
|
|
41
|
+
* predicate returned a falsy value.
|
|
41
42
|
*
|
|
42
43
|
* @example
|
|
43
44
|
* const array = [1, 2, 3, 4, 5];
|
|
@@ -45,6 +46,6 @@ declare function partition<T, U extends T>(arr: readonly T[], isInTruthy: (value
|
|
|
45
46
|
* const [even, odd] = partition(array, isEven);
|
|
46
47
|
* // even will be [2, 4], and odd will be [1, 3, 5]
|
|
47
48
|
*/
|
|
48
|
-
declare function partition<T>(arr: readonly T[], isInTruthy: (value: T, index: number, array: readonly T[]) =>
|
|
49
|
+
declare function partition<T>(arr: readonly T[], isInTruthy: (value: T, index: number, array: readonly T[]) => unknown): [truthy: T[], falsy: T[]];
|
|
49
50
|
//#endregion
|
|
50
51
|
export { partition };
|
|
@@ -33,11 +33,12 @@ declare function partition<T, U extends T>(arr: readonly T[], isInTruthy: (value
|
|
|
33
33
|
* @template T - The type of elements in the array.
|
|
34
34
|
* @param arr - The array to partition.
|
|
35
35
|
* @param isInTruthy - A predicate function that determines
|
|
36
|
-
* whether an element should be placed in the truthy array.
|
|
36
|
+
* whether an element should be placed in the truthy array. An element is placed in the truthy
|
|
37
|
+
* array when the function returns a truthy value. The function is called with each
|
|
37
38
|
* element of the array and its index.
|
|
38
39
|
* @returns A tuple containing two arrays: the first array contains elements for
|
|
39
|
-
* which the predicate returned
|
|
40
|
-
* predicate returned
|
|
40
|
+
* which the predicate returned a truthy value, and the second array contains elements for which the
|
|
41
|
+
* predicate returned a falsy value.
|
|
41
42
|
*
|
|
42
43
|
* @example
|
|
43
44
|
* const array = [1, 2, 3, 4, 5];
|
|
@@ -45,6 +46,6 @@ declare function partition<T, U extends T>(arr: readonly T[], isInTruthy: (value
|
|
|
45
46
|
* const [even, odd] = partition(array, isEven);
|
|
46
47
|
* // even will be [2, 4], and odd will be [1, 3, 5]
|
|
47
48
|
*/
|
|
48
|
-
declare function partition<T>(arr: readonly T[], isInTruthy: (value: T, index: number, array: readonly T[]) =>
|
|
49
|
+
declare function partition<T>(arr: readonly T[], isInTruthy: (value: T, index: number, array: readonly T[]) => unknown): [truthy: T[], falsy: T[]];
|
|
49
50
|
//#endregion
|
|
50
51
|
export { partition };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/types/DeepPartial.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Makes all properties of `T` optional recursively, unlike the built-in
|
|
4
|
+
* `Partial` which only affects the first level.
|
|
5
|
+
*
|
|
6
|
+
* Recurses into plain objects, arrays/tuples (elements do not become sparse),
|
|
7
|
+
* and `Map`/`Set` contents. Functions, `Date`, and `RegExp` pass through
|
|
8
|
+
* unchanged.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type to make deeply optional.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* type Config = { server: { host: string; port: number }; debug: boolean };
|
|
14
|
+
* type ConfigPatch = DeepPartial<Config>;
|
|
15
|
+
* // => { server?: { host?: string; port?: number }; debug?: boolean }
|
|
16
|
+
*
|
|
17
|
+
* const patch: ConfigPatch = { server: { port: 8080 } }; // ok, host omitted
|
|
18
|
+
*/
|
|
19
|
+
type DeepPartial<T> = T extends ((...args: any[]) => unknown) | Date | RegExp ? T : T extends Map<infer K, infer V> ? Map<DeepPartial<K>, DeepPartial<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepPartial<K>, DeepPartial<V>> : T extends Set<infer U> ? Set<DeepPartial<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepPartial<U>> : T extends readonly unknown[] ? { [K in keyof T]: DeepPartial<T[K]> } : T extends object ? { [K in keyof T]?: DeepPartial<T[K]> } : T;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { DeepPartial };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/types/DeepPartial.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Makes all properties of `T` optional recursively, unlike the built-in
|
|
4
|
+
* `Partial` which only affects the first level.
|
|
5
|
+
*
|
|
6
|
+
* Recurses into plain objects, arrays/tuples (elements do not become sparse),
|
|
7
|
+
* and `Map`/`Set` contents. Functions, `Date`, and `RegExp` pass through
|
|
8
|
+
* unchanged.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type to make deeply optional.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* type Config = { server: { host: string; port: number }; debug: boolean };
|
|
14
|
+
* type ConfigPatch = DeepPartial<Config>;
|
|
15
|
+
* // => { server?: { host?: string; port?: number }; debug?: boolean }
|
|
16
|
+
*
|
|
17
|
+
* const patch: ConfigPatch = { server: { port: 8080 } }; // ok, host omitted
|
|
18
|
+
*/
|
|
19
|
+
type DeepPartial<T> = T extends ((...args: any[]) => unknown) | Date | RegExp ? T : T extends Map<infer K, infer V> ? Map<DeepPartial<K>, DeepPartial<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepPartial<K>, DeepPartial<V>> : T extends Set<infer U> ? Set<DeepPartial<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepPartial<U>> : T extends readonly unknown[] ? { [K in keyof T]: DeepPartial<T[K]> } : T extends object ? { [K in keyof T]?: DeepPartial<T[K]> } : T;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { DeepPartial };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/types/DeepReadonly.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Makes all properties of `T` readonly recursively, unlike the built-in
|
|
4
|
+
* `Readonly` which only affects the first level.
|
|
5
|
+
*
|
|
6
|
+
* Arrays and tuples become readonly, and `Map`/`Set` become
|
|
7
|
+
* `ReadonlyMap`/`ReadonlySet`. Functions, `Date`, and `RegExp` pass through
|
|
8
|
+
* unchanged.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type to make deeply readonly.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* type State = { user: { name: string; tags: string[] } };
|
|
14
|
+
* type FrozenState = DeepReadonly<State>;
|
|
15
|
+
* // => { readonly user: { readonly name: string; readonly tags: readonly string[] } }
|
|
16
|
+
*
|
|
17
|
+
* declare const state: FrozenState;
|
|
18
|
+
* state.user.name = 'x'; // error: name is readonly
|
|
19
|
+
*/
|
|
20
|
+
type DeepReadonly<T> = T extends ((...args: any[]) => unknown) | Date | RegExp ? T : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]> } : T;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { DeepReadonly };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/types/DeepReadonly.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Makes all properties of `T` readonly recursively, unlike the built-in
|
|
4
|
+
* `Readonly` which only affects the first level.
|
|
5
|
+
*
|
|
6
|
+
* Arrays and tuples become readonly, and `Map`/`Set` become
|
|
7
|
+
* `ReadonlyMap`/`ReadonlySet`. Functions, `Date`, and `RegExp` pass through
|
|
8
|
+
* unchanged.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type to make deeply readonly.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* type State = { user: { name: string; tags: string[] } };
|
|
14
|
+
* type FrozenState = DeepReadonly<State>;
|
|
15
|
+
* // => { readonly user: { readonly name: string; readonly tags: readonly string[] } }
|
|
16
|
+
*
|
|
17
|
+
* declare const state: FrozenState;
|
|
18
|
+
* state.user.name = 'x'; // error: name is readonly
|
|
19
|
+
*/
|
|
20
|
+
type DeepReadonly<T> = T extends ((...args: any[]) => unknown) | Date | RegExp ? T : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]> } : T;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { DeepReadonly };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/types/NonEmptyArray.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* An array guaranteed to have at least one element.
|
|
4
|
+
* The first element resolves to `T` instead of `T | undefined`.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type of the elements.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const a: NonEmptyArray<number> = [1, 2, 3]; // ok
|
|
10
|
+
* const b: NonEmptyArray<number> = []; // error: empty array not allowed
|
|
11
|
+
*/
|
|
12
|
+
type NonEmptyArray<T> = [T, ...T[]];
|
|
13
|
+
//#endregion
|
|
14
|
+
export { NonEmptyArray };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/types/NonEmptyArray.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* An array guaranteed to have at least one element.
|
|
4
|
+
* The first element resolves to `T` instead of `T | undefined`.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type of the elements.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const a: NonEmptyArray<number> = [1, 2, 3]; // ok
|
|
10
|
+
* const b: NonEmptyArray<number> = []; // error: empty array not allowed
|
|
11
|
+
*/
|
|
12
|
+
type NonEmptyArray<T> = [T, ...T[]];
|
|
13
|
+
//#endregion
|
|
14
|
+
export { NonEmptyArray };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/types/Simplify.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Flattens an intersection or mapped type into a single, readable object type.
|
|
4
|
+
*
|
|
5
|
+
* The result is equivalent for plain object types, but editors show the
|
|
6
|
+
* resolved shape (`{ a: 1; b: 2 }`) instead of `A & B`.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type to flatten.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* type A = { name: string };
|
|
12
|
+
* type B = { age: number };
|
|
13
|
+
* type User = Simplify<A & B>;
|
|
14
|
+
* // hover => { name: string; age: number } (instead of A & B)
|
|
15
|
+
*/
|
|
16
|
+
type Simplify<T> = { [K in keyof T]: T[K] } & {};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { Simplify };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/types/Simplify.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Flattens an intersection or mapped type into a single, readable object type.
|
|
4
|
+
*
|
|
5
|
+
* The result is equivalent for plain object types, but editors show the
|
|
6
|
+
* resolved shape (`{ a: 1; b: 2 }`) instead of `A & B`.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type to flatten.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* type A = { name: string };
|
|
12
|
+
* type B = { age: number };
|
|
13
|
+
* type User = Simplify<A & B>;
|
|
14
|
+
* // hover => { name: string; age: number } (instead of A & B)
|
|
15
|
+
*/
|
|
16
|
+
type Simplify<T> = { [K in keyof T]: T[K] } & {};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { Simplify };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/types/ValueOf.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a union of all value types in `T`. The value-side counterpart to `keyof`.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The object type to read values from.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const STATUS = { IDLE: 'idle', ERROR: 'error' } as const;
|
|
9
|
+
* type Status = ValueOf<typeof STATUS>;
|
|
10
|
+
* // => 'idle' | 'error'
|
|
11
|
+
*/
|
|
12
|
+
type ValueOf<T> = T[keyof T];
|
|
13
|
+
//#endregion
|
|
14
|
+
export { ValueOf };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/types/ValueOf.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a union of all value types in `T`. The value-side counterpart to `keyof`.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The object type to read values from.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const STATUS = { IDLE: 'idle', ERROR: 'error' } as const;
|
|
9
|
+
* type Status = ValueOf<typeof STATUS>;
|
|
10
|
+
* // => 'idle' | 'error'
|
|
11
|
+
*/
|
|
12
|
+
type ValueOf<T> = T[keyof T];
|
|
13
|
+
//#endregion
|
|
14
|
+
export { ValueOf };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/types/Writable.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Removes the `readonly` modifier from all properties of `T`.
|
|
4
|
+
* The inverse of the built-in `Readonly`.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The object type to make writable.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* type Config = { readonly host: string; readonly port: number };
|
|
10
|
+
* type MutableConfig = Writable<Config>;
|
|
11
|
+
* // => { host: string; port: number }
|
|
12
|
+
*/
|
|
13
|
+
type Writable<T> = { -readonly [K in keyof T]: T[K] };
|
|
14
|
+
//#endregion
|
|
15
|
+
export { Writable };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/types/Writable.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Removes the `readonly` modifier from all properties of `T`.
|
|
4
|
+
* The inverse of the built-in `Readonly`.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The object type to make writable.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* type Config = { readonly host: string; readonly port: number };
|
|
10
|
+
* type MutableConfig = Writable<Config>;
|
|
11
|
+
* // => { host: string; port: number }
|
|
12
|
+
*/
|
|
13
|
+
type Writable<T> = { -readonly [K in keyof T]: T[K] };
|
|
14
|
+
//#endregion
|
|
15
|
+
export { Writable };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DeepPartial } from "./DeepPartial.mjs";
|
|
2
|
+
import { DeepReadonly } from "./DeepReadonly.mjs";
|
|
3
|
+
import { NonEmptyArray } from "./NonEmptyArray.mjs";
|
|
4
|
+
import { Simplify } from "./Simplify.mjs";
|
|
5
|
+
import { ValueOf } from "./ValueOf.mjs";
|
|
6
|
+
import { Writable } from "./Writable.mjs";
|
|
7
|
+
export { type DeepPartial, type DeepReadonly, type NonEmptyArray, type Simplify, type ValueOf, type Writable };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DeepPartial } from "./DeepPartial.js";
|
|
2
|
+
import { DeepReadonly } from "./DeepReadonly.js";
|
|
3
|
+
import { NonEmptyArray } from "./NonEmptyArray.js";
|
|
4
|
+
import { Simplify } from "./Simplify.js";
|
|
5
|
+
import { ValueOf } from "./ValueOf.js";
|
|
6
|
+
import { Writable } from "./Writable.js";
|
|
7
|
+
export { type DeepPartial, type DeepReadonly, type NonEmptyArray, type Simplify, type ValueOf, type Writable };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
|
-
"version": "1.49.0-dev.
|
|
3
|
+
"version": "1.49.0-dev.1974+9232c573",
|
|
4
4
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
5
5
|
"homepage": "https://es-toolkit.dev",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
@@ -164,6 +164,14 @@
|
|
|
164
164
|
"default": "./dist/string/index.js"
|
|
165
165
|
}
|
|
166
166
|
},
|
|
167
|
+
"./types": {
|
|
168
|
+
"import": {
|
|
169
|
+
"types": "./dist/types/index.d.mts"
|
|
170
|
+
},
|
|
171
|
+
"require": {
|
|
172
|
+
"types": "./dist/types/index.d.ts"
|
|
173
|
+
}
|
|
174
|
+
},
|
|
167
175
|
"./util": {
|
|
168
176
|
"import": {
|
|
169
177
|
"types": "./dist/util/index.d.mts",
|
|
@@ -405,6 +413,14 @@
|
|
|
405
413
|
"default": "./dist/string/index.js"
|
|
406
414
|
}
|
|
407
415
|
},
|
|
416
|
+
"./types": {
|
|
417
|
+
"import": {
|
|
418
|
+
"types": "./dist/types/index.d.mts"
|
|
419
|
+
},
|
|
420
|
+
"require": {
|
|
421
|
+
"types": "./dist/types/index.d.ts"
|
|
422
|
+
}
|
|
423
|
+
},
|
|
408
424
|
"./util": {
|
|
409
425
|
"import": {
|
|
410
426
|
"types": "./dist/util/index.d.mts",
|
package/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/types';
|