/
githubmirror
/
immutable-js
Обзор
Документация
Войти
/
githubmirror
/
immutable-js
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v5.1.6
src/functional/getIn.ts
33 строки
1 KB
Julien Deniau
sort all imports via eslint
12 июн 2025, 01:23
12 июн 2025, 01:23
67a4fa9
Код
Авторство
О чём код?
import type { KeyPath } from '../../type-definitions/immutable'; import { NOT_SET } from '../TrieUtils'; import coerceKeyPath from '../utils/coerceKeyPath'; import { get } from './get'; type GetType = typeof get; type GetTypeParameters = Parameters<GetType>; type CollectionType = GetTypeParameters[0]; type Key = GetTypeParameters[1]; /** * Returns the value at the provided key path starting at the provided * collection, or notSetValue if the key path is not defined. * * A functional alternative to `collection.getIn(keypath)` which will also * work with plain Objects and Arrays. */ export function getIn( collection: CollectionType, searchKeyPath: KeyPath<Key>, notSetValue?: GetTypeParameters[2] ): ReturnType<GetType> { const keyPath = coerceKeyPath(searchKeyPath); let i = 0; while (i !== keyPath.length) { // @ts-expect-error keyPath[i++] can not be undefined by design collection = get(collection, keyPath[i++], NOT_SET); if (collection === NOT_SET) { return notSetValue; } } return collection; }