MCPcopy Index your code
hub / github.com/deepstreamIO/deepstream.io / tokenize

Function tokenize

src/utils/json-path.ts:71–105  ·  view source on GitHub ↗

* Parses the path. Splits it into * keys for objects and indices for arrays.

(path: string)

Source from the content-addressed store, hash-verified

69 * keys for objects and indices for arrays.
70 */
71function tokenize (path: string): Array<string | number> {
72 const tokens: Array<string | number> = []
73
74 const parts = path.split('.')
75
76 for (let i = 0; i < parts.length; i++) {
77 const part = parts[i].trim()
78
79 if (part.length === 0) {
80 continue
81 }
82
83 const arrayIndexes: string[] = part.split(SPLIT_REG_EXP)
84
85 if (arrayIndexes.length === 0) {
86 // TODO
87 continue
88 }
89
90 if (FORBIDDEN_KEYS.has(arrayIndexes[0])) {
91 throw new Error(`invalid path: forbidden key '${arrayIndexes[0]}'`)
92 }
93
94 tokens.push(arrayIndexes[0])
95
96 for (let j = 1; j < arrayIndexes.length; j++) {
97 if (arrayIndexes[j].length === 0) {
98 continue
99 }
100
101 tokens.push(Number(arrayIndexes[j]))
102 }
103 }
104 return tokens
105}

Callers 3

getValueFunction · 0.85
setValueFunction · 0.85
isValidPathFunction · 0.85

Calls 1

hasMethod · 0.45

Tested by

no test coverage detected