mirror of
https://github.com/fluencelabs/jsonpath
synced 2025-03-30 13:41:04 +00:00
34 lines
737 B
JavaScript
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
|
|
}; |