MCPcopy Index your code
hub / github.com/CopilotKit/CopilotKit / likeToRegExp

Function likeToRegExp

showcase/harness/src/fleet/queue-client.test.ts:150–168  ·  view source on GitHub ↗

* Convert a PB `~`/`!~` LIKE pattern into an anchored RegExp, faithful to * PocketBase 0.22's semantics: the SQL is built as `LIKE ... ESCAPE '\'` * (pocketbase tools/search/filter.go), so a `\`-escaped `%`/`_` is a LITERAL * character while unescaped `%`/`_` are wildcards. The fakes must honor t

(pattern: string)

Source from the content-addressed store, hash-verified

148 * just the least-surprising fallback, not a verified PB contract.
149 */
150function likeToRegExp(pattern: string): RegExp {
151 const escapeRegExp = (ch: string): string =>
152 ch.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
153 let out = "";
154 for (let i = 0; i < pattern.length; i++) {
155 const ch = pattern[i];
156 if (ch === "\\" && i + 1 < pattern.length) {
157 out += escapeRegExp(pattern[i + 1]);
158 i += 1;
159 } else if (ch === "%") {
160 out += ".*";
161 } else if (ch === "_") {
162 out += ".";
163 } else {
164 out += escapeRegExp(ch);
165 }
166 }
167 return new RegExp(`^${out}$`);
168}
169
170/** The row shape the shared filter matcher evaluates. */
171interface FilterableRow {

Callers 1

rowMatchesFilterFunction · 0.85

Calls 1

escapeRegExpFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…