mirror of
https://github.com/fluencelabs/jsonpath
synced 2025-06-14 16:41:26 +00:00
NodeJs 0.1.7 - support Selector(0.1.9)
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
const { Compile, Selector, selectStr } = require('../native');
|
||||
const { CompileFn, SelectorFn, selectStr, Selector: _Selector } = require('../native');
|
||||
|
||||
function compile(path) {
|
||||
let compile = new Compile(path);
|
||||
let compile = new CompileFn(path);
|
||||
return (json) => {
|
||||
if(typeof json != 'string') {
|
||||
json = JSON.stringify(json)
|
||||
@ -14,9 +14,9 @@ function selector(json) {
|
||||
if(typeof json != 'string') {
|
||||
json = JSON.stringify(json)
|
||||
}
|
||||
let selector = new Selector(json);
|
||||
let selector = new SelectorFn(json);
|
||||
return (path) => {
|
||||
return JSON.parse(selector.selector(path));
|
||||
return JSON.parse(selector.select(path));
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,8 +27,38 @@ function select(json, path) {
|
||||
return JSON.parse(selectStr(json, path));
|
||||
}
|
||||
|
||||
class Selector {
|
||||
constructor() {
|
||||
this._selector = new _Selector();
|
||||
return this;
|
||||
}
|
||||
|
||||
path(path) {
|
||||
this._selector.path(path);
|
||||
return this;
|
||||
}
|
||||
|
||||
value(json) {
|
||||
if(typeof json != 'string') {
|
||||
json = JSON.stringify(json)
|
||||
}
|
||||
this._selector.value_from_str(json);
|
||||
return this;
|
||||
}
|
||||
|
||||
selectToStr() {
|
||||
return this._selector.select_to_str();
|
||||
}
|
||||
|
||||
selectTo() {
|
||||
return JSON.parse(this.selectToStr());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
compile,
|
||||
selector,
|
||||
select
|
||||
select,
|
||||
Selector
|
||||
};
|
Reference in New Issue
Block a user