diff --git a/package.json b/package.json index 6636037..8b94726 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "node": ">=8" }, "dependencies": { - "@medv/blessed": "^2.0.0", + "@medv/blessed": "^2.0.1", "chalk": "^3.0.0", "indent-string": "^4.0.0", "lossless-json": "^1.0.3", @@ -54,7 +54,7 @@ }, "devDependencies": { "ava": "^2.4.0", - "pkg": "^4.4.1", + "pkg": "^4.4.2", "release-it": "^12.4.3" } } diff --git a/reduce.js b/reduce.js index 39a38cc..bdee7c7 100644 --- a/reduce.js +++ b/reduce.js @@ -1,22 +1,30 @@ '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 json } if ('?' === code) { return Object.keys(json) } - const fx = eval(`function fn() { + if (/^\.\[/.test(code)) { + return eval(`function fn() { + return this${code.substring(1)} + }; fn`).call(json) + } + + if (/^\./.test(code)) { + return eval(`function fn() { + return this${code} + }; fn`).call(json) + } + + const fn = eval(`function fn() { return ${code} - }; fn`) + }; fn`).call(json) - const fn = fx.call(json) if (typeof fn === 'function') { return fn(json) }