@neutrium/utilities - v3.1.0
    Preparing search index...

    Function immutableSnapshot

    • Copy and deeply freeze plain data without retaining caller-owned objects. Supports primitives, local plain/null-prototype records and local arrays. Preserves cycles, shared references, array holes, symbols and property enumerability. Rejects functions, accessors and other prototypes with TypeError. Never invokes getters; proxy reflection traps can run and their errors propagate. Each call makes a fresh graph. Primitives pass through unchanged. Traversal does not use recursive calls.

      Type Parameters

      • T

      Parameters

      • value: T

      Returns DeepReadonly<T>

    • Override own root properties before copying and freezing a data graph. Existing properties retain their enumerability; new properties use the override's enumerability. Overrides are copied into the same graph, so references to the input root resolve to the snapshot root. Nested properties are not merged or defaulted. Overrides must be plain records. Roots may also be arrays, but array length and index overrides are rejected. Accessors are rejected even when overridden. Replaced values are not traversed; proxy reflection errors propagate unchanged.

      Type Parameters

      • T extends object
      • Overrides extends object

      Parameters

      Returns DeepReadonly<{}>

      const source: { locale?: string; self?: unknown } = {};
      source.self = source;
      const snapshot = immutableSnapshot(source, { locale: 'en-US' });
      snapshot.self === snapshot; // true
      snapshot.locale; // 'en-US'