Skip to content

Commit

Permalink
feat: filter 行为修改
Browse files Browse the repository at this point in the history
BREAKING CHANGE: useProviders, discardProviders 默认为严格模式
  • Loading branch information
geekdada committed Jul 9, 2020
1 parent 7b004bd commit 9e0ddf7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
2 changes: 0 additions & 2 deletions lib/misc/deprecation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export const DEP003 = 'useProvider 将在之后版本改为默认使用严格模式';
export const DEP004 = 'discardProviders 将在之后版本改为默认使用严格模式';
export const DEP005 = 'surgioConfig.surgeConfig.shadowsocksFormat: "custom" 已不推荐使用,请改为 "ss"';
export const DEP006 = 'surgioConfig.surgeConfig.v2ray: "external" 已不推荐使用,请改为 "native"';
17 changes: 2 additions & 15 deletions lib/utils/filter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import _ from 'lodash';
import { deprecate } from 'util';

import { DEP003, DEP004 } from '../misc/deprecation';
import flag, { TAIWAN } from '../misc/flag_cn';
import { NodeNameFilterType, NodeTypeEnum, SimpleNodeConfig, SortedNodeNameFilterType } from '../types';

const showDEP003 = deprecate(_.noop, DEP003, 'DEP003');
const showDEP004 = deprecate(_.noop, DEP004, 'DEP004');

// tslint:disable-next-line:max-classes-per-file
export class SortFilterWithSortedFilters implements SortedNodeNameFilterType {
public supportSort = true;
Expand Down Expand Up @@ -100,29 +95,21 @@ export const useRegexp = (regexp: RegExp): NodeNameFilterType => {
return item => regexp.test(item.nodeName);
};

export const useProviders = (keywords: ReadonlyArray<string>, isStrict?: boolean): NodeNameFilterType => {
export const useProviders = (keywords: ReadonlyArray<string>, isStrict = true): NodeNameFilterType => {
// istanbul ignore next
if (!Array.isArray(keywords)) {
throw new Error('keywords 请使用数组');
}

if (!isStrict) {
showDEP003();
}

return item => keywords.some(keyword => isStrict ? item?.provider?.name === keyword : item?.provider?.name.includes(keyword));
};

export const discardProviders = (keywords: ReadonlyArray<string>, isStrict?: boolean): NodeNameFilterType => {
export const discardProviders = (keywords: ReadonlyArray<string>, isStrict = true): NodeNameFilterType => {
// istanbul ignore next
if (!Array.isArray(keywords)) {
throw new Error('keywords 请使用数组');
}

if (!isStrict) {
showDEP004();
}

return item => !keywords.some(keyword => isStrict ? item?.provider?.name === keyword : item?.provider?.name.includes(keyword));
};

Expand Down

0 comments on commit 9e0ddf7

Please sign in to comment.