/
githubmirror
/
immutable-js
Обзор
Документация
Войти
/
githubmirror
/
immutable-js
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v4.3.6
src/functional/remove.js
30 строк
890 B
Lee Byron
Relicence and copyright (#1814)
18 июн 2021, 01:53
Не верифицирован
18 июн 2021, 01:53
5155a7f
Код
Авторство
О чём код?
import { isImmutable } from '../predicates/isImmutable'; import hasOwnProperty from '../utils/hasOwnProperty'; import isDataStructure from '../utils/isDataStructure'; import shallowCopy from '../utils/shallowCopy'; export function remove(collection, key) { if (!isDataStructure(collection)) { throw new TypeError( 'Cannot update non-data-structure value: ' + collection ); } if (isImmutable(collection)) { if (!collection.remove) { throw new TypeError( 'Cannot update immutable value without .remove() method: ' + collection ); } return collection.remove(key); } if (!hasOwnProperty.call(collection, key)) { return collection; } const collectionCopy = shallowCopy(collection); if (Array.isArray(collectionCopy)) { collectionCopy.splice(key, 1); } else { delete collectionCopy[key]; } return collectionCopy; }