Skip to content

Commit 443ea51

Browse files
committed
feat(vue-jsx): add filter
1 parent 2600cc3 commit 443ea51

File tree

2 files changed

+203
-157
lines changed

2 files changed

+203
-157
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export function exactRegex(input: string): RegExp {
2+
return new RegExp(`^${escapeRegex(input)}$`)
3+
}
4+
5+
const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g
6+
function escapeRegex(str: string): string {
7+
return str.replace(escapeRegexRE, '\\$&')
8+
}
9+
10+
export function matchWithQuery(input: string | RegExp): string | RegExp {
11+
if (typeof input === 'string') {
12+
return `${input}{?*,}`
13+
}
14+
return addQueryToRegex(input)
15+
}
16+
17+
function addQueryToRegex(input: RegExp) {
18+
return new RegExp(
19+
// replace `$` with `(?:\?.*)?$` (ignore `\$`)
20+
input.source.replace(/(?<!\\)\$/g, '(?:\\?.*)?$'),
21+
input.flags,
22+
)
23+
}

0 commit comments

Comments
 (0)