/
githubmirror
/
immutable-js
Обзор
Документация
Войти
/
githubmirror
/
immutable-js
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/functional/has.ts
18 строк
835 B
Julien Deniau
Remove runkit
24 май 2025, 01:13
24 май 2025, 01:13
2b47de5
Код
Авторство
О чём код?
import { isImmutable } from '../predicates/isImmutable'; import hasOwnProperty from '../utils/hasOwnProperty'; import isDataStructure from '../utils/isDataStructure'; /** * Returns true if the key is defined in the provided collection. * * A functional alternative to `collection.has(key)` which will also work with * plain Objects and Arrays as an alternative for * `collection.hasOwnProperty(key)`. */ export function has(collection: object, key: unknown): boolean { return isImmutable(collection) ? // @ts-expect-error key might be a number or symbol, which is not handled be Record key type collection.has(key) : // @ts-expect-error key might be anything else than PropertyKey, and will return false in that case but runtime is OK isDataStructure(collection) && hasOwnProperty.call(collection, key); }