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

date

Locked, prototype-pollution-resistant copy of the global Date constructor and its statics.

The Date constructor is wrapped in a createDate factory (with all overloads preserved) and Date.now, Date.parse, and Date.UTC are captured at module-load time and frozen into a tamper-proof namespace, so timestamp work keeps producing trustworthy values even if the global Date is later patched. Effective only when imported before any untrusted code has had a chance to mutate the prototype chain.

API Reference§

ƒ Functions

§function

createDate(): Date

● Variables

§type

Date

(Safe copy) Namespace object containing Date factory and static methods. Note: Importing this imports all methods in this namespace (no tree-shaking).
§type

dateNow

(Safe copy) Returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
Example
const timestamp = dateNow()
// => 1704067200000 (example timestamp)
§type

dateParse

(Safe copy) Parses a string representation of a date.
Example
const timestamp = dateParse('2024-01-01T00:00:00Z')
// => 1704067200000
§type

dateUTC

(Safe copy) Returns the number of milliseconds in a Date object since January 1, 1970 UTC.
Example
const timestamp = dateUTC(2024, 0, 1, 12, 0, 0)
// => 1704110400000 (Jan 1, 2024 12:00:00 UTC)