@elyukai/utils 0.2.1 → 0.2.2
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/CHANGELOG.md +8 -0
- package/dist/array/fixed.d.ts +13 -0
- package/dist/array/fixed.js +5 -0
- package/dist/dictionary.d.ts +4 -0
- package/dist/dictionary.js +16 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [0.2.2](https://github.com/elyukai/ts-utils/compare/v0.2.1...v0.2.2) (2026-02-11)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add FixedArray helper ([4a1b61a](https://github.com/elyukai/ts-utils/commit/4a1b61a51ad53c35767adf716d4a64ef10f4dc10))
|
|
11
|
+
* add static groupBy method to dictionary ([2ee4802](https://github.com/elyukai/ts-utils/commit/2ee4802db8f1b821819f4ced5f79079153a6c11e))
|
|
12
|
+
|
|
5
13
|
## [0.2.1](https://github.com/elyukai/ts-utils/compare/v0.2.0...v0.2.1) (2026-02-07)
|
|
6
14
|
|
|
7
15
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A helper type that builds a tuple type of a desired length.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* A recursive type that constructs an array of type `T` with a length of `N`.
|
|
7
|
+
*/
|
|
8
|
+
type FixedArrayAux<T, N extends number, A extends T[]> = A["length"] extends N ? A : FixedArrayAux<T, N, [...A, T]>;
|
|
9
|
+
/**
|
|
10
|
+
* A type representing an array of a fixed size `N` containing elements of type `T`.
|
|
11
|
+
*/
|
|
12
|
+
export type FixedArray<T, N extends number> = FixedArrayAux<T, N, []>;
|
|
13
|
+
export {};
|
package/dist/dictionary.d.ts
CHANGED
|
@@ -21,6 +21,10 @@ export declare class Dictionary<T extends AnyNonNullish | null, K extends string
|
|
|
21
21
|
* Constructs a dictionary from an array of key-value pairs.
|
|
22
22
|
*/
|
|
23
23
|
static fromEntries<T extends AnyNonNullish | null, K extends string = string>(entries: [K, T][]): Dictionary<T, K>;
|
|
24
|
+
/**
|
|
25
|
+
* Groups the given items by the key returned by the given function and returns a dictionary mapping each key to an array of items with that key.
|
|
26
|
+
*/
|
|
27
|
+
static groupBy<T, K extends string>(items: T[], keyFn: (item: T) => K): Dictionary<T[], K>;
|
|
24
28
|
/**
|
|
25
29
|
* Returns the value associated with the given key, or `undefined` if the key does not exist.
|
|
26
30
|
*/
|
package/dist/dictionary.js
CHANGED
|
@@ -25,6 +25,22 @@ export class Dictionary {
|
|
|
25
25
|
static fromEntries(entries) {
|
|
26
26
|
return new Dictionary(Object.fromEntries(entries));
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Groups the given items by the key returned by the given function and returns a dictionary mapping each key to an array of items with that key.
|
|
30
|
+
*/
|
|
31
|
+
static groupBy(items, keyFn) {
|
|
32
|
+
const record = {};
|
|
33
|
+
for (const item of items) {
|
|
34
|
+
const key = keyFn(item);
|
|
35
|
+
if (record[key] === undefined) {
|
|
36
|
+
record[key] = [item];
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
record[key].push(item);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return new Dictionary(record);
|
|
43
|
+
}
|
|
28
44
|
/**
|
|
29
45
|
* Returns the value associated with the given key, or `undefined` if the key does not exist.
|
|
30
46
|
*/
|