You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fx/reduce.js

27 lines
452 B
JavaScript

'use strict'
function reduce(json, code) {
if (/^\./.test(code)) {
const fx = eval(`function fn() {
return ${code === '.' ? 'this' : 'this' + code}
}; fn`)
return fx.call(json)
}
if ('?' === code) {
return Object.keys(json)
}
const fx = eval(`function fn() {
return ${code}
}; fn`)
const fn = fx.call(json)
if (typeof fn === 'function') {
return fn(json)
}
return fn
}
module.exports = reduce