MCPcopy Create free account
hub / github.com/Effect-TS/effect / bracketPathToTokens

Function bracketPathToTokens

packages/effect/src/SchemaGetter.ts:1805–1819  ·  view source on GitHub ↗
(bracketPath: string)

Source from the content-addressed store, hash-verified

1803const INDEX_REGEXP = /^\d+$/
1804
1805function bracketPathToTokens(bracketPath: string): Array<string | number> {
1806 // real empty path (from append("", value))
1807 if (bracketPath === "") {
1808 return [""]
1809 }
1810
1811 const replaced = bracketPath.replace(/\[(.*?)\]/g, ".$1")
1812 const parts = replaced.split(".")
1813 // if bracket path started with "[...]" we get ".foo" => ["", "foo"]; drop the synthetic first ""
1814 const start = replaced.startsWith(".") ? 1 : 0
1815
1816 return parts
1817 .slice(start)
1818 .map((part) => (INDEX_REGEXP.test(part) ? globalThis.Number(part) : part))
1819}
1820
1821/**
1822 * Builds a nested tree object from a list of bracket-path entries.

Callers 1

makeTreeRecordFunction · 0.85

Calls 3

replaceMethod · 0.45
splitMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected