From d6a894f03f704c706285254bf98c0a4f0fc77130 Mon Sep 17 00:00:00 2001 From: huangcheng Date: Wed, 2 Nov 2022 12:16:44 +0800 Subject: [PATCH] style: simplify code (#3506) * style: simplify code * test: add test for isPathPattern --- packages/path/src/__tests__/basic.spec.ts | 12 ++++++++++++ packages/path/src/index.ts | 7 ++----- 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 packages/path/src/__tests__/basic.spec.ts diff --git a/packages/path/src/__tests__/basic.spec.ts b/packages/path/src/__tests__/basic.spec.ts new file mode 100644 index 00000000000..abb30ff17e4 --- /dev/null +++ b/packages/path/src/__tests__/basic.spec.ts @@ -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() +}) diff --git a/packages/path/src/index.ts b/packages/path/src/index.ts index fa274440cc5..1809eec4bca 100644 --- a/packages/path/src/index.ts +++ b/packages/path/src/index.ts @@ -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(