toPath

Parse a path string into an array of segments, supporting dot and bracket notation, the basis for safe nested property access.

Usage

toPath parses a path string into an array of segments.

import { toPath } from '@movk/core'

toPath('a.b[0].c') // ['a', 'b', 0, 'c']
toPath('a[\'x.y\']') // ['a', 'x.y']

API

toPath(path)

Parse a path string into an array of segments.

Parameters

path
PathInput required
A path string or array of segments.

Returns

returns
PathSegments
The parsed array of path segments.

Changelog

No recent changes
Copyright © 2024 - 2026 YiXuan - MIT License