* Maps the collection items to a dictionary, indexed by the key you specify. * If there are more items with the same key, only the first one will be present.
(
key: K1,
valueKey?: K2,
)
| 838 | * If there are more items with the same key, only the first one will be present. |
| 839 | */ |
| 840 | indexBy<K1 extends keyof T, K2 extends keyof T = never>( |
| 841 | key: K1, |
| 842 | valueKey?: K2, |
| 843 | ): Record<T[K1] & PropertyKey, T> | Record<T[K1] & PropertyKey, T[K2]> { |
| 844 | return this.reduce((obj, item) => { |
| 845 | obj[item[key] as string] ??= valueKey ? item[valueKey] : item; |
| 846 | return obj; |
| 847 | }, {} as any); |
| 848 | } |
| 849 | |
| 850 | /** Returns whether the collection has been initialized. Pass `fully = true` to also check that all items are initialized. */ |
| 851 | isInitialized(fully = false): boolean { |
no test coverage detected