UNPKG

shelving

Version:

Toolkit for using data in JavaScript.

18 lines (17 loc) 542 B
/** Get the identifier from an item object. */ export function getIdentifier({ id }) { return id; } /** Get the identifiers from an iterable set item objects. */ export function* getIdentifiers(entities) { for (const { id } of entities) yield id; } /** Does a data object or data item object. */ export function hasIdentifier(item, id) { return item.id === id; } /** Merge an ID into a set of data to make an `ItemData` */ export function getItem(id, data) { return hasIdentifier(data, id) ? data : { ...data, id }; }