toPath

将一个路径字符串解析为一个由字符串键和数字索引组成的片段数组。

toPath

将一个路径字符串解析为一个由字符串键和数字索引组成的片段数组。

用法

import { toPath } from '@movk/core'

toPath('a.b[0].c') // => ['a', 'b', 0, 'c']
toPath('a[\'key with.dot\']') // => ['a', 'key with.dot']

API

toPath(path: string | (string | number)[]): (string | number)[]

参数

path
string | (string | number)[] required
路径字符串或片段数组。如果传入数组,将返回其副本。

返回值

(string | number)[]
返回解析后的片段数组。

Changelog

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