Skip to content

KeyPath

KeyPath = KeyPath.Component | KeyPath.Self

Defined in: keyPath.ts:11, keyPath.ts:13

Key paths represent paths to access nested properties in an object

Key paths can be either:

  • A dot-notation string representing nested properties (e.g. "user.address.street")
  • A special Self symbol representing the current object

Component = string & object

Defined in: keyPath.ts:15

Branded type for key path components

[keyPathBrand]: unknown


Self = symbol & object

Defined in: keyPath.ts:17, keyPath.ts:19

Branded type for a self-referencing key path

[keyPathBrand]: unknown

Self: KeyPath.Self

Defined in: keyPath.ts:17, keyPath.ts:19

Self path symbol


build(...keys): KeyPath

Defined in: keyPath.ts:41

Build a key path from an array of keys

...(string | number | KeyPath | null)[]

KeyPath

The constructed key path

  • Joins keys with dots
  • Ignores null values
  • Ignores empty strings
  • Handles KeyPath.Self

getAncestors(keyPath, includeSelf?): Generator<KeyPath>

Defined in: keyPath.ts:97

Get all ancestors of a key path

KeyPath

boolean = true

Whether to include the path itself

Generator<KeyPath>

  • KeyPath.Self for single-level paths when includeSelf is false
  • Key paths starting from the closest ancestor and moving up to the root

getParentKey(keyPath): KeyPath

Defined in: keyPath.ts:82

Get the parent key of a key path

KeyPath

KeyPath

The parent key or a self path if the key path is a self path


getRelative(keyPath, prefixKeyPath): KeyPath | null

Defined in: keyPath.ts:70

Get the relative key path from a prefix key path

KeyPath

KeyPath

KeyPath | null

  • null if the key path is not a child of the prefix
  • KeyPath.Self if the paths are identical
  • The original path if the prefix is KeyPath.Self

isSelf(keyPath): keyPath is KeyPath.Self

Defined in: keyPath.ts:26

Whether a key path is a self path

Empty strings are also considered self paths.

KeyPath

keyPath is KeyPath.Self