MCPcopy Index your code
hub / github.com/TanStack/router / parsePathname

Function parsePathname

packages/router-core/tests/optional-path-params.test.ts:28–55  ·  view source on GitHub ↗
(to: string | undefined)

Source from the content-addressed store, hash-verified

26
27 describe('parsePathname with optional params', () => {
28 const parsePathname = (to: string | undefined) => {
29 let cursor = 0
30 let data
31 const path = to ?? ''
32 const segments: Array<PathSegment> = []
33 while (cursor < path.length) {
34 const start = cursor
35 data = parseSegment(path, start, data)
36 const end = data[5]
37 cursor = end + 1
38 const type = data[0]
39 const value = path.substring(data[2], data[3])
40 const prefix = path.substring(start, data[1])
41 const suffix = path.substring(data[4], end)
42 const segment: PathSegment = {
43 type,
44 value,
45 }
46 if (prefix) {
47 segment.prefixSegment = prefix
48 }
49 if (suffix) {
50 segment.suffixSegment = suffix
51 }
52 segments.push(segment)
53 }
54 return segments
55 }
56 it.each([
57 {
58 name: 'regular optional param',

Callers 1

Calls 1

parseSegmentFunction · 0.90

Tested by

no test coverage detected