jsonpath/nodejs/lib/index.js
2019-03-20 23:18:18 +09:00

34 lines
737 B
JavaScript

const { Compile, Selector, selectStr } = require('../native');
function compile(path) {
let compile = new Compile(path);
return (json) => {
if(typeof json != 'string') {
json = JSON.stringify(json)
}
return JSON.parse(compile.template(json));
};
}
function selector(json) {
if(typeof json != 'string') {
json = JSON.stringify(json)
}
let selector = new Selector(json);
return (path) => {
return JSON.parse(selector.selector(path));
}
}
function select(json, path) {
if(typeof json != 'string') {
json = JSON.stringify(json)
}
return JSON.parse(selectStr(json, path));
}
module.exports = {
compile,
selector,
select
};