@hyperfrontend/immutable-api-utils/built-in-copy/object

object

Locked, prototype-pollution-resistant copies of the global Object static methods.

References to Object.freeze, Object.create, Object.keys, Object.values, Object.entries, Object.assign, Object.defineProperty, and the rest of the Object static surface are captured at module-load time and frozen into a tamper-proof namespace, so downstream code keeps working even if the global Object is later patched. Effective only when imported before any untrusted code has had a chance to mutate the prototype chain.

API Reference

ƒ Functions

§function

hasOwn(obj: object, key: PropertyKey): boolean

(Safe copy) Safe wrapper for Object.prototype.hasOwnProperty.call(). Checks if an object has a property as its own (not inherited) property.

Parameters

NameTypeDescription
§obj
object
The object to check.
§key
PropertyKey
The property key to check.

Returns

boolean
True if the object has the property as its own property.

Example

Checking own properties

const user = { name: 'Alice' }
hasOwn(user, 'name') // => true
hasOwn(user, 'toString') // => false (inherited from prototype)
§function

typeTag(value: unknown): string

(Safe copy) Safe wrapper for Object.prototype.toString.call(). Returns the internal [[Class]] property of the object as a string tag.

Parameters

NameTypeDescription
§value
unknown
The value to get the type tag from.

Returns

string
The type tag string (e.g., "[object Array]").

Example

Getting type tags

typeTag([1, 2, 3]) // => '[object Array]'
typeTag(null) // => '[object Null]'
typeTag(Promise.resolve()) // => '[object Promise]'

Variables

§type

assign

(Safe copy) Copy the values of all enumerable own properties from one or more source objects to a target object. Returns the target object.
§type

create

(Safe copy) Creates an object that has the specified prototype or that has null prototype.
§type

defineProperties

(Safe copy) Adds one or more properties to an object, and/or modifies attributes of existing properties.
§type

defineProperty

(Safe copy) Adds a property to an object, or modifies attributes of an existing property.
§type

entries

(Safe copy) Returns an array of key/values of the enumerable own properties of an object.
§type

freeze

(Safe copy) Prevents modification of existing property attributes and values, and prevents the addition of new properties.
§type

fromEntries

(Safe copy) Returns an object from an iterable of key-value pairs.
§type

getOwnPropertyDescriptor

(Safe copy) Gets the own property descriptor of the specified object.
§type

getOwnPropertyDescriptors

(Safe copy) Gets the own property descriptors of the specified object.
§type

getOwnPropertyNames

(Safe copy) Returns the names of the own properties of an object.
§type

getOwnPropertySymbols

(Safe copy) Returns an array of all symbol properties found directly on object o.
§type

getPrototypeOf

(Safe copy) Returns the prototype of an object.
§type

isExtensible

(Safe copy) Returns a value that indicates whether new properties can be added to an object.
§type

isFrozen

(Safe copy) Returns true if existing property attributes and values cannot be modified in an object, and new properties cannot be added to the object.
§type

isSealed

(Safe copy) Returns true if existing property attributes cannot be modified in an object and new properties cannot be added to the object.
§type

keys

(Safe copy) Returns the names of the enumerable string properties and methods of an object.
§type

objectHasOwn

(Safe copy) Determines whether an object has a property with the specified name.
§type

preventExtensions

(Safe copy) Prevents the addition of new properties to an object.
§type

SafeObject

(Safe copy) Namespace object containing all Object static methods. Note: Importing this imports all methods in this namespace (no tree-shaking). Named SafeObject instead of Object to avoid shadowing global Object during CJS module initialization.
§type

seal

(Safe copy) Prevents the addition of new properties to an object.
§type

setPrototypeOf

(Safe copy) Sets the prototype of a specified object o to object proto or null.
§type

values

(Safe copy) Returns an array of values of the enumerable own properties of an object.