To Path

Converts a deep key string into an array of path segments.

CategoryObjects
AuthorPol Gubau
Since1.0.0
Last Updated2025-03-15
TypeSync
CompatibilityUniversal

Example

  • Input

    toPath('a.b.c')

    Output:

    ['a', 'b', 'c']
  • Input

    toPath('a[b][c]')

    Output:

    ['a', 'b', 'c']
  • Input

    toPath('.a.b.c')

    Output:

    ['', 'a', 'b', 'c']
  • Input

    toPath('a["b.c"].d')

    Output:

    ['a', 'b.c', 'd']
  • Input

    toPath('')

    Output:

    []
  • Input

    toPath('.a[b].c.d[e]["f.g"].h')

    Output:

    ['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']

Return

An array of strings, each representing a segment of the path.

Type: string[]

Props

NameTypeDefaultRequiredDescription
deepKeystringYesThe deep key string to convert into an array of path segments.

Notes

This function parses a deep key string and splits it into its respective path segments. It handles various cases, such as quoted segments, bracket notation, and escaped characters.

Tags

  • toPath
  • deepKey
  • path
  • string
  • parse
  • array

Related