Skip to content

Commit

Permalink
feat: add error message
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Oct 7, 2019
1 parent 7071954 commit 69b6bff
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/utils/filter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'lodash';

import { NodeNameFilterType, SimpleNodeConfig } from '../types';

export const mergeFilters = (filters: ReadonlyArray<NodeNameFilterType>, isStrict?: boolean): NodeNameFilterType => {
Expand All @@ -7,10 +9,20 @@ export const mergeFilters = (filters: ReadonlyArray<NodeNameFilterType>, isStric
};

export const useKeywords = (keywords: ReadonlyArray<string>, 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);
};

Expand Down

0 comments on commit 69b6bff

Please sign in to comment.