Skip to content

p-object

The object module provides utility functions for working with JavaScript objects.

use p-object as o

Returns an array of the object’s own property names.

Returns an array of the object’s own property values.

Returns an array of [key, value] pairs.

Returns the number of own properties.

Returns true if the object has the specified own property.

Returns true if a and b are the same value (Object.is semantics).

use p-object as o
const obj be [name be ///Purus///, version be 1]
o.keys[obj] -- ["name", "version"]
o.values[obj] -- ["Purus", 1]
o.entries[obj] -- [["name", "Purus"], ["version", 1]]
o.len[obj] -- 2
o.hasown[obj; ///name///] -- true

Creates an object from an array of [key, value] pairs.

Creates a new object with the specified prototype and optional property descriptors.

Copies own properties from source objects to the target object. Returns the target.

Merges multiple objects into a new object (shallow merge).

Returns a deep clone of the object (using structuredClone).

use p-object as o
const a be [x be 1]
const b be [y be 2]
o.merge[a; b] -- { x: 1, y: 2 }
o.clone[a] -- { x: 1 } (deep copy)
const pairs be [[///a///; 1]; [///b///; 2]]
o.fromentries[pairs] -- { a: 1, b: 2 }

Freezes an object (prevents modification). Returns the frozen object.

Seals an object (prevents adding/removing properties but allows modifying existing). Returns the sealed object.

Returns true if the object is frozen.

Returns true if the object is sealed.

use p-object as o
const obj be [x be 1]
o.freeze[obj]
o.isfrozen[obj] -- true

Returns a new object containing only the specified keys.

Returns a new object excluding the specified keys.

use p-object as o
const obj be [a be 1; b be 2; c be 3]
o.pick[obj; [///a///; ///c///]] -- { a: 1, c: 3 }
o.omit[obj; [///b///]] -- { a: 1, c: 3 }