MCPcopy Create free account
hub / github.com/solidjs/solid-router / parse

Function parse

src/recognizer/index.ts:207–259  ·  view source on GitHub ↗
(
  segments: Segment[],
  route: string,
  types: [number, number, number]
)

Source from the content-addressed store, hash-verified

205// segment. `shouldDecodes` will be populated with a boolean for each dyanamic/star
206// segment, indicating whether it should be decoded during recognition.
207function parse(
208 segments: Segment[],
209 route: string,
210 types: [number, number, number]
211): ParsedHandler {
212 // normalize route as not starting with a "/". Recognition will
213 // also normalize.
214 if (route.length > 0 && route.charCodeAt(0) === CHARS.SLASH) {
215 route = route.substr(1);
216 }
217
218 const parts = route.split("/");
219 let names: undefined | string[] = undefined;
220 let shouldDecodes: undefined | boolean[] = undefined;
221
222 for (let i = 0; i < parts.length; i++) {
223 let part = parts[i];
224 let type: SegmentType = 0;
225
226 if (part === "") {
227 type = SegmentType.Epsilon;
228 } else if (part.charCodeAt(0) === CHARS.COLON) {
229 type = SegmentType.Dynamic;
230 } else if (part.charCodeAt(0) === CHARS.STAR) {
231 type = SegmentType.Star;
232 } else {
233 type = SegmentType.Static;
234 }
235
236 if (type & SegmentFlags.Named) {
237 part = part.slice(1);
238 names = names || [];
239 names.push(part);
240
241 shouldDecodes = shouldDecodes || [];
242 shouldDecodes.push((type & SegmentFlags.Decoded) !== 0);
243 }
244
245 if (type & SegmentFlags.Counted) {
246 types[type as Counted]++;
247 }
248
249 segments.push({
250 type,
251 value: normalizeSegment(part)
252 });
253 }
254
255 return {
256 names: names || EmptyArray,
257 shouldDecodes: shouldDecodes || EmptyArray
258 } as ParsedHandler;
259}
260
261function isEqualCharSpec(
262 spec: CharSpec,

Callers 1

addMethod · 0.85

Calls 1

normalizeSegmentFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…