Collection · 13 utilities

Object utilities

Pick only the fields you need, understand shallow copies and keep prototype keys as data.

Pick properties from an object

Build a new object with only the requested own properties.

function pick({ value, keys }) { return Object.fromEntries(keys.filter(key => Object.hasOwn(val…object

Omit properties from an object

Keep the own enumerable fields that are not in a supplied list.

function omit({ value, keys }) { return Object.fromEntries(Object.entries(value).filter(([key])…object

Check if multiple objects are equal

Compare JSON serializations with the first object.

function areEqual(objects) { return objects.every(object => JSON.stringify(object) === JSON.str…object

Get the value at given path of an object

Follow a dot-separated path, stopping at a missing step.

function getValue({ path, object }) { return path.split('.').reduce((value, key) => (value == n…object

Immutably rename object keys

Return a copy with keys renamed through a mapping.

function renameKeys({ keysMap, object }) { return Object.fromEntries(Object.entries(object).map…object

Sort an object by its properties

Rebuild an object with its keys in sorted order.

function sortKeys(object) { return Object.fromEntries(Object.keys(object).sort().map(key => [ke…object

Shallow copy an object

Copy own enumerable properties into a new object.

function shallowCopy(object) { return { ...object }; }object

Get unique objects from an array by key

Keep one record per key value, the last one seen.

function uniqueBy({ objects, key }) { return [...new Map(objects.map(item => [item[key], item])…object

Try a function in the local code lab, then read its limits before using it in an application.

Type two or more characters. Try “duplicate”, “webhook” or “retry”.