To Path
Converts a deep key string into an array of path segments.
Category | Objects |
Author | Pol Gubau |
Since | 1.0.0 |
Last Updated | 2025-03-15 |
Type | Sync |
Compatibility | Universal |
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
Name | Type | Default | Required | Description |
---|---|---|---|---|
deepKey | string | Yes | The 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