Comparing version 0.1.17 to 0.1.18
@@ -8,2 +8,3 @@ import { Segments, Node, Pattern } from './types'; | ||
isWildMatchPattern: boolean; | ||
haveExcludePattern: boolean; | ||
tree: Node; | ||
@@ -31,2 +32,3 @@ private matchCache; | ||
match: (pattern: Pattern) => boolean; | ||
matchAliasGroup: (...patterns: Pattern[]) => boolean; | ||
existIn: (source?: any, start?: number | Path) => boolean; | ||
@@ -33,0 +35,0 @@ getIn: (source?: any) => any; |
@@ -279,2 +279,16 @@ "use strict"; | ||
}; | ||
this.matchAliasGroup = function () { | ||
var patterns = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
patterns[_i] = arguments[_i]; | ||
} | ||
if (patterns.length === 0) | ||
return false; | ||
if (_this.haveExcludePattern) { | ||
return patterns.every(function (pattern) { return _this.match(pattern); }); | ||
} | ||
else { | ||
return patterns.some(function (pattern) { return _this.match(pattern); }); | ||
} | ||
}; | ||
this.existIn = function (source, start) { | ||
@@ -295,3 +309,3 @@ if (start === void 0) { start = 0; } | ||
}; | ||
var _a = this.parse(input), tree = _a.tree, segments = _a.segments, entire = _a.entire, isMatchPattern = _a.isMatchPattern, isWildMatchPattern = _a.isWildMatchPattern; | ||
var _a = this.parse(input), tree = _a.tree, segments = _a.segments, entire = _a.entire, isMatchPattern = _a.isMatchPattern, isWildMatchPattern = _a.isWildMatchPattern, haveExcludePattern = _a.haveExcludePattern; | ||
this.entire = entire; | ||
@@ -301,2 +315,3 @@ this.segments = segments; | ||
this.isWildMatchPattern = isWildMatchPattern; | ||
this.haveExcludePattern = haveExcludePattern; | ||
this.tree = tree; | ||
@@ -327,2 +342,3 @@ this.matchCache = new lru_1.LRUMap(200); | ||
isMatchPattern: pattern.isMatchPattern, | ||
haveExcludePattern: pattern.haveExcludePattern, | ||
tree: pattern.tree | ||
@@ -337,2 +353,3 @@ }; | ||
isWildMatchPattern: false, | ||
haveExcludePattern: false, | ||
isMatchPattern: false | ||
@@ -349,2 +366,3 @@ }; | ||
isWildMatchPattern: false, | ||
haveExcludePattern: false, | ||
isMatchPattern: false | ||
@@ -358,2 +376,3 @@ }; | ||
isWildMatchPattern: parser.isWildMatchPattern, | ||
haveExcludePattern: parser.haveExcludePattern, | ||
isMatchPattern: true, | ||
@@ -374,2 +393,3 @@ tree: tree | ||
isWildMatchPattern: false, | ||
haveExcludePattern: false, | ||
isMatchPattern: false | ||
@@ -383,2 +403,3 @@ }; | ||
isWildMatchPattern: false, | ||
haveExcludePattern: false, | ||
isMatchPattern: false | ||
@@ -385,0 +406,0 @@ }; |
@@ -7,2 +7,3 @@ import { Tokenizer } from './tokenizer'; | ||
isWildMatchPattern: boolean; | ||
haveExcludePattern: boolean; | ||
data: { | ||
@@ -9,0 +10,0 @@ segments: Segments; |
@@ -247,2 +247,3 @@ "use strict"; | ||
node.isExclude = true; | ||
this.haveExcludePattern = true; | ||
this.next(); | ||
@@ -249,0 +250,0 @@ break; |
{ | ||
"name": "cool-path", | ||
"version": "0.1.17", | ||
"version": "0.1.18", | ||
"description": "Path Matcher/Getter/Setter for Object/Array", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -138,2 +138,3 @@ import { Parser } from './parser' | ||
public isWildMatchPattern: boolean | ||
public haveExcludePattern: boolean | ||
public tree: Node | ||
@@ -149,3 +150,4 @@ private matchCache: any | ||
isMatchPattern, | ||
isWildMatchPattern | ||
isWildMatchPattern, | ||
haveExcludePattern | ||
} = this.parse(input) | ||
@@ -156,2 +158,3 @@ this.entire = entire | ||
this.isWildMatchPattern = isWildMatchPattern | ||
this.haveExcludePattern = haveExcludePattern | ||
this.tree = tree as Node | ||
@@ -181,2 +184,3 @@ this.matchCache = new LRUMap(200) | ||
isMatchPattern: pattern.isMatchPattern, | ||
haveExcludePattern: pattern.haveExcludePattern, | ||
tree: pattern.tree | ||
@@ -190,2 +194,3 @@ } | ||
isWildMatchPattern: false, | ||
haveExcludePattern: false, | ||
isMatchPattern: false | ||
@@ -202,2 +207,3 @@ } | ||
isWildMatchPattern: false, | ||
haveExcludePattern: false, | ||
isMatchPattern: false | ||
@@ -210,2 +216,3 @@ } | ||
isWildMatchPattern: parser.isWildMatchPattern, | ||
haveExcludePattern: parser.haveExcludePattern, | ||
isMatchPattern: true, | ||
@@ -224,2 +231,3 @@ tree | ||
isWildMatchPattern: false, | ||
haveExcludePattern: false, | ||
isMatchPattern: false | ||
@@ -232,2 +240,3 @@ } | ||
isWildMatchPattern: false, | ||
haveExcludePattern: false, | ||
isMatchPattern: false | ||
@@ -397,2 +406,12 @@ } | ||
//别名组匹配 | ||
matchAliasGroup = (...patterns: Pattern[]) => { | ||
if (patterns.length === 0) return false | ||
if (this.haveExcludePattern) { | ||
return patterns.every(pattern => this.match(pattern)) | ||
} else { | ||
return patterns.some(pattern => this.match(pattern)) | ||
} | ||
} | ||
existIn = (source?: any, start: number | Path = 0) => { | ||
@@ -399,0 +418,0 @@ return existIn(this.segments, source, start) |
@@ -43,2 +43,4 @@ import { Tokenizer } from './tokenizer' | ||
public haveExcludePattern:boolean | ||
public data: { | ||
@@ -308,2 +310,3 @@ segments: Segments | ||
node.isExclude = true | ||
this.haveExcludePattern = true | ||
this.next() | ||
@@ -310,0 +313,0 @@ break |
@@ -34,2 +34,9 @@ import expect from 'expect' | ||
test('test matchGroup',()=>{ | ||
const pattern = new Path('*(aa,bb,cc)') | ||
expect(pattern.matchAliasGroup('aa','bb','dd')).toEqual(true) | ||
const excludePattern = new Path('aa.bb.*(11,22,33).*(!aa,bb,cc)') | ||
expect(excludePattern.matchAliasGroup('aa.bb.11.mm','aa.bb.22.bb','aa.bb.33.cc')).toEqual(false) | ||
}) | ||
match({ | ||
@@ -36,0 +43,0 @@ '*': [[], ['aa'], ['aa', 'bb', 'cc'], ['aa', 'dd', 'gg']], |
160729
5129