Comparing version 0.1.0 to 0.1.1
@@ -16,2 +16,3 @@ import { Segments, Node } from './types'; | ||
private parse; | ||
private parseString; | ||
concat: (...args: (string | number)[]) => any; | ||
@@ -18,0 +19,0 @@ slice: (start?: number, end?: number) => any; |
@@ -224,2 +224,3 @@ "use strict"; | ||
} | ||
item = _this.parseString(item); | ||
_this.segments.push(item); | ||
@@ -245,2 +246,5 @@ _this.entire = _this.segments.join('.'); | ||
} | ||
if (deleteCount === 0) { | ||
items = items.map(function (item) { return _this.parseString(item); }); | ||
} | ||
(_a = _this.segments).splice.apply(_a, __spreadArrays([start, deleteCount], items)); | ||
@@ -422,11 +426,3 @@ _this.entire = _this.segments.join('.'); | ||
segments: pattern.reduce(function (buf, key) { | ||
if (utils_1.isStr(key)) | ||
key = key.replace(/\s*/g, ''); | ||
try { | ||
var _a = _this.parse(key), segments = _a.segments, isMatchPattern = _a.isMatchPattern; | ||
return buf.concat(!isMatchPattern ? segments : key); | ||
} | ||
catch (e) { | ||
return buf.concat(key); | ||
} | ||
return buf.concat(_this.parseString(key)); | ||
}, []), | ||
@@ -446,2 +442,15 @@ isWildMatchPattern: false, | ||
}; | ||
Path.prototype.parseString = function (source) { | ||
if (utils_1.isStr(source)) { | ||
source = source.replace(/\s*/g, ''); | ||
try { | ||
var _a = this.parse(source), segments = _a.segments, isMatchPattern = _a.isMatchPattern; | ||
return !isMatchPattern ? segments : source; | ||
} | ||
catch (e) { | ||
return source; | ||
} | ||
} | ||
return source; | ||
}; | ||
Path.match = function (pattern) { | ||
@@ -448,0 +457,0 @@ var path = Path.getPath(pattern); |
{ | ||
"name": "cool-path", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Path Matcher/Getter/Setter for Object/Array", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -293,9 +293,3 @@ import { Parser } from './parser' | ||
segments: pattern.reduce((buf, key) => { | ||
if (isStr(key)) key = key.replace(/\s*/g, '') | ||
try { | ||
const { segments, isMatchPattern } = this.parse(key) | ||
return buf.concat(!isMatchPattern ? segments : key) | ||
} catch (e) { | ||
return buf.concat(key) | ||
} | ||
return buf.concat(this.parseString(key)) | ||
}, []), | ||
@@ -315,2 +309,15 @@ isWildMatchPattern: false, | ||
private parseString(source : any){ | ||
if(isStr(source)){ | ||
source = source.replace(/\s*/g,'') | ||
try { | ||
const { segments, isMatchPattern } = this.parse(source) | ||
return !isMatchPattern ? segments : source | ||
} catch (e) { | ||
return source | ||
} | ||
} | ||
return source | ||
} | ||
concat = (...args: Array<string | number>) => { | ||
@@ -334,2 +341,3 @@ if (this.isMatchPattern) { | ||
} | ||
item = this.parseString(item) | ||
this.segments.push(item) | ||
@@ -356,2 +364,5 @@ this.entire = this.segments.join('.') | ||
} | ||
if(deleteCount === 0){ | ||
items = items.map(item=>this.parseString(item)) | ||
} | ||
this.segments.splice(start, deleteCount, ...items) | ||
@@ -358,0 +369,0 @@ this.entire = this.segments.join('.') |
142351
4610