Function propertyPathIterator

  • Returns a validating iterator for either one PropertyPath or an iterable of property paths.

    A value satisfying isPropertyPath is always interpreted as one path before iterable detection occurs. This precedence is necessary because dotted strings and exact property-key arrays are themselves iterable.

    Consequently, an array containing only property keys represents one exact path:

    Parameters

    Returns IterableIterator<PropertyPath>

    A validating iterator that yields each property path in source order.

    [...propertyPathIterator(['actor', 'name'])];
    // [
    // ['actor', 'name']
    // ]

    To supply multiple dotted-string paths, use an iterable that is not itself a valid property path, such as a Set:

    [...propertyPathIterator(new Set([
    'actor.name',
    'actor.id'
    ]))];
    // ['actor.name', 'actor.id']

    An outer array of exact array paths is also unambiguous because its entries are arrays rather than property keys:

    [...propertyPathIterator([
    ['actor', 'name'],
    ['actor', 'id']
    ])];
    // [
    // ['actor', 'name'],
    // ['actor', 'id']
    // ]

    Iterable entries are validated lazily as iteration advances. An invalid entry throws when that entry is reached; valid preceding entries may already have been yielded. An empty iterable produces an empty iterator.

    Paths are yielded unchanged. Exact array paths are not normalized, copied, or frozen.

    During iteration if paths is neither a property path nor an iterable.

    During iteration if an iterable entry is not a valid property path.