jsonpath-rs add "map", "get" function

This commit is contained in:
freestrings
2019-05-16 14:14:09 +09:00
parent 5b653ab8a0
commit 802640a6da
11 changed files with 142 additions and 17 deletions

View File

@ -42,18 +42,40 @@ class Selector {
if(typeof json != 'string') {
json = JSON.stringify(json)
}
this._selector.value_from_str(json);
this._selector.valueFromStr(json);
return this;
}
selectToStr() {
return this._selector.select_to_str();
return this.selectAsStr();
}
selectTo() {
return JSON.parse(this.selectToStr());
return this.selectAs();
}
selectAsStr() {
return this._selector.selectAsStr();
}
selectAs() {
return JSON.parse(this.selectAsStr());
}
map(func) {
this._selector.map((json) => {
var result = func.call(null, JSON.parse(json));
if(typeof result !== 'string') {
result = JSON.stringify(result);
}
return result;
});
return this;
}
get() {
return JSON.parse(this._selector.get());
}
}
module.exports = {