MCPcopy Index your code
hub / github.com/TanStack/form / makePathArray

Function makePathArray

packages/form-core/src/utils.ts:154–188  ·  view source on GitHub ↗
(str: string | Array<string | number>)

Source from the content-addressed store, hash-verified

152 * @private
153 */
154export function makePathArray(str: string | Array<string | number>) {
155 if (Array.isArray(str)) {
156 return [...str]
157 }
158
159 if (typeof str !== 'string') {
160 throw new Error('Path must be a string.')
161 }
162
163 return (
164 str
165 // Leading `[` may lead to wrong parsing down the line
166 // (Example: '[0][1]' should be '0.1', not '.0.1')
167 .replace(/(^\[)|]/gm, '')
168 .replace(/\[/g, '.')
169 .replace(reLineOfOnlyDigits, intReplace)
170 .replace(reDigitsBetweenDots, `.${intReplace}.`)
171 .replace(reStartWithDigitThenDot, `${intReplace}.`)
172 .replace(reDotWithDigitsToEnd, `.${intReplace}`)
173 .replace(reMultipleDots, '.')
174 .split('.')
175 .map((d) => {
176 if (d.startsWith(intPrefix)) {
177 const numStr = d.substring(intPrefix.length)
178 const num = parseInt(numStr, 10)
179
180 if (String(num) === numStr) {
181 return num
182 }
183 return numStr
184 }
185 return d
186 })
187 )
188}
189
190/**
191 * @private

Callers 5

FieldGroupApiClass · 0.90
getByFunction · 0.85
setByFunction · 0.85
deleteByFunction · 0.85
utils.spec.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected