MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / parseHash

Function parseHash

ui/src/lib/router.svelte.ts:127–195  ·  view source on GitHub ↗
(hash: string)

Source from the content-addressed store, hash-verified

125}
126
127export function parseHash(hash: string): RouterLocation {
128 const raw = hash.startsWith('#') ? hash.slice(1) : hash;
129 const q = raw.indexOf('?');
130 const pathPart = q < 0 ? raw : raw.slice(0, q);
131 const params = new URLSearchParams(q < 0 ? '' : raw.slice(q + 1));
132 const segments = pathPart.split('/').filter(Boolean).map(decodeSegment);
133 const line = parseLine(params);
134
135 const [head, ...rest] = segments;
136 let route: Route;
137 if (head === undefined) {
138 route = { view: 'home' };
139 } else if (head === 's') {
140 // `#/s` on its own is the tab, not a 404: nothing is chosen yet.
141 route = { view: 'symbol', id: rest.length > 0 ? rest.join('/') : null, line };
142 } else if (head === 'file' && rest.length > 0) {
143 route = { view: 'file', path: rest.join('/'), line, source: params.get('src') === '1' };
144 } else if (head === 'map' && rest.length === 0) {
145 // The map's shape travels in the URL like the trail does: a link to
146 // "src/vs at depth 2, tests on" has to reopen the same picture. Absent, it
147 // stays absent: the answering side reads the repository and picks a depth,
148 // and a 1 defaulted in here would silently override that with the one
149 // grouping — top-level directories — that is wrong for every project whose
150 // program lives under a single `src/`.
151 const root = params.get('root');
152 const depth = Number.parseInt(params.get('depth') ?? '', 10);
153 route = {
154 view: 'map',
155 root: root === null ? null : root,
156 depth: Number.isFinite(depth) && depth >= 1 && depth <= 4 ? depth : null,
157 tests: params.get('tests') === '1',
158 };
159 } else if (head === 'entry' && rest.length === 0) {
160 route = { view: 'entry' };
161 } else if (head === 'screens' && rest.length === 0) {
162 route = { view: 'screens' };
163 } else if (head === 'steps' && rest.length === 0) {
164 // The anchor travels in the URL, so "what happens on the review screen"
165 // is a link that reopens as the same picture.
166 const depth = Number.parseInt(params.get('depth') ?? '', 10);
167 const reading = params.get('view');
168 route = {
169 view: 'steps',
170 anchor: params.get('anchor'),
171 symbol: params.get('symbol'),
172 depth: Number.isFinite(depth) && depth >= 1 && depth <= 14 ? depth : null,
173 through: params.get('through') === '1',
174 reading: reading === 'order' || reading === 'tree' ? reading : null,
175 };
176 } else if (head === 'dead' && rest.length === 0) {
177 // The widening travels in the URL like the map's shape does: a link to
178 // "including exported symbols" has to reopen the same list.
179 route = { view: 'dead', exported: params.get('exported') === '1' };
180 } else if (head === 'flow' && rest.length === 0) {
181 // The question travels in the URL exactly as it was asked, so a flow can be
182 // linked in a review and reopen as the same path.
183 route = {
184 view: 'flow',

Callers 3

router.svelte.tsFile · 0.85
syncFunction · 0.85
ui-package.test.tsFile · 0.85

Calls 4

parseLineFunction · 0.85
mapMethod · 0.80
getMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected