Comparing version 0.1.23 to 0.1.24
@@ -5,2 +5,3 @@ "use strict"; | ||
var utils_1 = require("./utils"); | ||
var isValid = function (val) { return val !== undefined && val !== null && val !== ''; }; | ||
var Matcher = (function () { | ||
@@ -10,3 +11,5 @@ function Matcher(tree) { | ||
this.matchNext = function (node, path) { | ||
return node.after ? _this.matchAtom(path, node.after) : !!path[_this.pos]; | ||
return node.after | ||
? _this.matchAtom(path, node.after) | ||
: isValid(path[_this.pos]); | ||
}; | ||
@@ -23,3 +26,3 @@ this.tree = tree; | ||
this.tail = node; | ||
if (path[this.pos + 1] && !node.after) { | ||
if (isValid(path[this.pos + 1]) && !node.after) { | ||
if (this.stack.length) { | ||
@@ -129,3 +132,3 @@ for (var i = this.stack.length - 1; i >= 0; i--) { | ||
return true; | ||
if (path[this.pos + 1]) | ||
if (isValid(path[this.pos + 1])) | ||
return false; | ||
@@ -132,0 +135,0 @@ if (this.pos == path.length - 1) |
{ | ||
"name": "cool-path", | ||
"version": "0.1.23", | ||
"version": "0.1.24", | ||
"description": "Path Matcher/Getter/Setter for Object/Array", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -23,2 +23,4 @@ import { | ||
const isValid = val => val !== undefined && val !== null && val !== '' | ||
export class Matcher { | ||
@@ -44,3 +46,5 @@ private tree: Node | ||
matchNext = (node: any, path: any) => { | ||
return node.after ? this.matchAtom(path, node.after) : !!path[this.pos] | ||
return node.after | ||
? this.matchAtom(path, node.after) | ||
: isValid(path[this.pos]) | ||
} | ||
@@ -50,3 +54,3 @@ | ||
this.tail = node | ||
if (path[this.pos + 1] && !node.after) { | ||
if (isValid(path[this.pos + 1]) && !node.after) { | ||
if (this.stack.length) { | ||
@@ -165,3 +169,3 @@ for (let i = this.stack.length - 1; i >= 0; i--) { | ||
if (this.stack.length > 0) return true | ||
if (path[this.pos + 1]) return false | ||
if (isValid(path[this.pos + 1])) return false | ||
if (this.pos == path.length - 1) return true | ||
@@ -168,0 +172,0 @@ } |
@@ -41,2 +41,6 @@ import expect from 'expect' | ||
).toEqual(false) | ||
const patttern2 = Path.parse('*(array)') | ||
expect( | ||
patttern2.matchAliasGroup(['array',0],['array',0]) | ||
).toEqual(false) | ||
}) | ||
@@ -105,2 +109,3 @@ | ||
'a.*': [['a'], ['b']], | ||
'*(array)': [['array','0']], | ||
'aa.bb.*': [['aa', 'bb']], | ||
@@ -107,0 +112,0 @@ 'a.*.b': [['a', 'k', 'b', 'd']], |
162615
5188