MCPcopy
hub / github.com/remix-run/remix / RoutePattern

Class RoutePattern

packages/route-pattern/src/lib/route-pattern.ts:80–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78 * `source`, `toString()`, `toJSON()`, and {@link getRoutePatternCaptures} for inspection.
79 */
80export class RoutePattern<source extends string = string> {
81 declare readonly [brand]: source
82
83 /** Parsed parts of this pattern. Internal; not part of the public API. */
84 readonly _parts: RoutePatternParts
85
86 /**
87 * Create a new `RoutePattern` from its parsed parts.
88 *
89 * The parts are not part of the public API. Use {@link RoutePattern.parse} to create a pattern
90 * from a source string.
91 *
92 * @param parts The parsed parts of the pattern.
93 */
94 constructor(parts: RoutePatternParts) {
95 this._parts = parts
96 }
97
98 /**
99 * Create a new `RoutePattern` by parsing a source string.
100 *
101 * @param source The route pattern source string.
102 * @returns The parsed route pattern.
103 */
104 static parse<source extends string>(source: source): RoutePattern<source> {
105 return parsePattern(source)
106 }
107
108 /** Normalized string representation of this pattern. */
109 get source(): string {
110 return serializePattern(this._parts)
111 }
112
113 /**
114 * Returns a string representing this route pattern.
115 *
116 * @returns The same normalized pattern string as `RoutePattern.source`.
117 */
118 toString(): string {
119 return this.source
120 }
121
122 /**
123 * Returns a JSON-serializable object containing each serialized part of this route pattern.
124 *
125 * @returns The serialized protocol, hostname, port, pathname, and search.
126 */
127 toJSON(): RoutePatternJSON {
128 return serializePatternParts(this._parts)
129 }
130}
131
132export function createRoutePattern<source extends string>(
133 parts: RoutePatternParts,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…