Skip to content

Commit

Permalink
perf(path): simplified code (#3933)
Browse files Browse the repository at this point in the history
  • Loading branch information
hchlq authored Aug 15, 2023
1 parent 5a126e2 commit 8861ef5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/path/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,10 @@ export class Path {
if (this.isMatchPattern) {
throw new Error(`${this.entire} cannot be transformed`)
}
const args = this.segments.reduce((buf, key) => {
return new RegExp(regexp).test(key as string) ? buf.concat(key) : buf
}, [])
const reg = new RegExp(regexp)
const args = this.segments.filter((key) =>
reg.test(key as string)
) as string[]
return callback(...args)
}

Expand Down

0 comments on commit 8861ef5

Please sign in to comment.