Skip to content

Commit

Permalink
style: simplify code (#3506)
Browse files Browse the repository at this point in the history
* style: simplify code

* test: add test for isPathPattern
  • Loading branch information
hchlq authored Nov 2, 2022
1 parent 0c96914 commit d6a894f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 12 additions & 0 deletions packages/path/src/__tests__/basic.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Path } from '../'

const { isPathPattern, match } = Path

test('isPathPattern', () => {
expect(isPathPattern('obj')).toBeTruthy()
expect(isPathPattern(['obj', 'aa'])).toBeTruthy()
expect(isPathPattern(/^obj/)).toBeTruthy()

const matcher = match('obj.aa')
expect(isPathPattern(matcher)).toBeTruthy()
})
7 changes: 2 additions & 5 deletions packages/path/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,15 +513,12 @@ export class Path {
}

static isPathPattern(target: any): target is Pattern {
if (
return !!(
isStr(target) ||
isArr(target) ||
isRegExp(target) ||
(isFn(target) && target[isMatcher])
) {
return true
}
return false
)
}

static transform<T>(
Expand Down

0 comments on commit d6a894f

Please sign in to comment.