NodeJs 0.1.7 - support Selector(0.1.9)

This commit is contained in:
freestrings
2019-04-09 16:13:09 +09:00
parent ceadbcec84
commit d263e30c91
6 changed files with 701 additions and 79 deletions

View File

@ -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
};