diff --git a/lib/utils/filter.ts b/lib/utils/filter.ts index 0c140d563..8bd1ea66c 100644 --- a/lib/utils/filter.ts +++ b/lib/utils/filter.ts @@ -1,3 +1,5 @@ +import _ from 'lodash'; + import { NodeNameFilterType, SimpleNodeConfig } from '../types'; export const mergeFilters = (filters: ReadonlyArray, isStrict?: boolean): NodeNameFilterType => { @@ -7,10 +9,20 @@ export const mergeFilters = (filters: ReadonlyArray, isStric }; export const useKeywords = (keywords: ReadonlyArray, isStrict?: boolean): NodeNameFilterType => { + // istanbul ignore next + if (!Array.isArray(keywords)) { + throw new Error('keywords 请使用数组。'); + } + return item => keywords[isStrict ? 'every' : 'some'](keyword => item.nodeName.includes(keyword)); }; export const useRegexp = (regexp: RegExp): NodeNameFilterType => { + // istanbul ignore next + if (!_.isRegExp(regexp)) { + throw new Error('入参不是一个合法的正则表达式。'); + } + return item => regexp.test(item.nodeName); };