Function pathKeyIterator

  • Returns an iterator of property-key path arrays useful with safeAccess and safeSet by traversing the given object. Enumerable string and symbol keys are included, and numeric array indexes may be enabled.

    Traversal may be bounded by absolute property paths relative to data. prefixPath selects one branch and keeps all yielded paths absolute. stopPath yields the selected path itself and prunes every descendant beneath it. maxDepth limits traversal relative to prefixPath, or relative to the root when no prefix is supplied. Properties reached at the maximum depth are yielded as terminal paths and are not traversed further.

    maxResults limits the number of yielded paths. maxVisits limits the number of enumerable properties and array indexes inspected; exceeding this budget throws before another property value is read. These limits reduce exposure to unexpectedly broad objects, sparse arrays with extreme lengths, getters, and proxy traps. Exceptions raised by getters or proxy operations are intentionally propagated.

    When both path bounds are supplied, stopPath must equal or descend from prefixPath. If maxDepth is also supplied, traversal stops at whichever boundary is reached first.

    Note: Keys are only generated for ordinary objects and arrays; Map and Set are not indexed. Array elements are treated as terminal paths even when their values are objects.

    Parameters

    • data: object

      An object to traverse for property path keys.

    • Optionaloptions: PathKeyIteratorOptions

      Traversal options.

      Defines bounded traversal options for pathKeyIterator.

      Returned paths remain absolute when a prefix is selected. stopPath must equal or descend from prefixPath when both are supplied.

      • OptionalarrayIndex?: boolean

        Whether numeric array indexes are included.

        false
        
      • OptionalhasOwnOnly?: boolean

        Whether traversal is restricted to enumerable own properties.

        true
        
      • OptionalmaxDepth?: number

        Maximum number of property-key segments traversed beneath a selected prefix, or beneath the root when no prefix is supplied. A value of 0 selects only the prefix itself when the iterator supports a prefix.

      • OptionalmaxResults?: number

        Maximum number of paths or entries yielded by one traversal. Reaching this limit truncates normally.

      • OptionalmaxVisits?: number

        Maximum number of object properties or trie nodes processed during iterative traversal. Exceeding this limit throws.

      • OptionalprefixPath?: PropertyPath

        Absolute enumerable property path selecting the object branch where traversal begins.

      • OptionalstopPath?: PropertyPath

        Absolute property path yielded as terminal while pruning all descendants beneath it.

    Returns IterableIterator<readonly PropertyKey[]>

    An iterator of absolute readonly property-key paths.

    If data, a boolean option, a numeric limit, or a property-path option is invalid.

    If options.stopPath is outside options.prefixPath or options.maxVisits is exceeded.