MCPcopy Create free account
hub / github.com/observablehq/framework / compilePattern

Function compilePattern

src/route.ts:110–118  ·  view source on GitHub ↗
(file: string)

Source from the content-addressed store, hash-verified

108}
109
110function compilePattern(file: string): RegExp {
111 let pattern = "^";
112 let i = 0;
113 for (let match: RegExpExecArray | null, re = /\[([a-z_]\w*)\]/gi; (match = re.exec(file)); i = re.lastIndex) {
114 pattern += `${requote(file.slice(i, match.index))}(?<${match[1]}>.+)`;
115 }
116 pattern += `${requote(file.slice(i))}$`;
117 return new RegExp(pattern, "i");
118}
119
120export function requote(text: string): string {
121 return text.replace(/[\\^$*+?|[\]().{}]/g, "\\$&");

Callers 1

matchParamsFunction · 0.85

Calls 2

requoteFunction · 0.85
execMethod · 0.45

Tested by

no test coverage detected