Skip to content

Commit 8b7d396

Browse files
committed
refactor: simplify resolve regex
1 parent 375d997 commit 8b7d396

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/options/index.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,7 @@ async function resolveWorkspace(
117117
}
118118

119119
if (options.filter) {
120-
if (
121-
typeof options.filter === 'string' &&
122-
options.filter.length > 2 &&
123-
options.filter[0] === '/' &&
124-
options.filter.at(-1) === '/'
125-
) {
126-
options.filter = new RegExp(options.filter.slice(1, -1))
127-
}
120+
options.filter = resolveRegex(options.filter)
128121
packages = packages.filter((path) => {
129122
return typeof options.filter === 'string'
130123
? path.includes(options.filter)

src/utils/general.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ export function resolveComma<T extends string>(arr: T[]): T[] {
1616
return arr.flatMap((format) => format.split(',') as T[])
1717
}
1818

19-
export function resolveRegex(str: string): string | RegExp {
20-
if (str.length > 2 && str[0] === '/' && str.at(-1) === '/') {
19+
export function resolveRegex<T>(str: T): T | RegExp {
20+
if (
21+
typeof str === 'string' &&
22+
str.length > 2 &&
23+
str[0] === '/' &&
24+
str.at(-1) === '/'
25+
) {
2126
return new RegExp(str.slice(1, -1))
2227
}
2328
return str

0 commit comments

Comments
 (0)