1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
// https://github.com/lodash/lodash/blob/4.17.15/lodash.js#L6735-L6744
let rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g
let reEscapeChar = /\\(\\)?/g
export function stringToPath(string: string): string[] {
let result: string[] = []
if (string.charCodeAt(0) === 46 /* . */) {
result.push('')
}
// @ts-ignore
string.replace(rePropName, (match, number, quote, subString) => {
result.push(quote ? subString.replace(reEscapeChar, '$1') : number || match)
})
return result
}
|