Skip to content

Object

Functions to manipulate objects immutably and type-safely. All functions preserve the original object and return a new value.

How to import?

The library exposes the DObject and O namespaces from the main entry or via direct import (tree-shaking friendly), which lets you only load what you need.

typescript
import { DObject, O } from "@duplojs/utils";
import * as DObject from "@duplojs/utils/object";
import * as O from "@duplojs/utils/object";

Access and extraction

keys

Returns an array of an object's keys with precise typing.

values

Returns an array of an object's values.

entries

Returns an array of an object's key-value pairs with strict typing.

entry

Creates a typed key-value pair (tuple).

fromEntries

Builds an object from an array of key-value pairs.

getProperty

Retrieves the value of a property from an object.

getDeepProperty

Retrieves the value of a deep property via a path (path notation).

Transformation

pick

Creates a new object by selecting only certain properties.

omit

Creates a new object by excluding certain properties.

assign

Merges multiple objects together (similar to Object.assign but type-safe).

override

Overrides an object's properties with another object's, ignoring undefined values.

transformProperty

Transforms a specific property of an object via a function.

transformProperties

Transforms multiple properties of an object via functions.

to

Transforms a value into a new object according to a transformation schema.

Checking and filtering

hasKeys

Checks whether an object has certain keys (type guard).

discriminate

Discriminates an object by the value of a property (type guard for unions).

deepDiscriminate

Discriminates an object by the value of a deep property (type guard for unions).

Released under the MIT license.