Comparing version 0.2.0 to 0.2.1
@@ -0,0 +0,0 @@ "use strict"; |
@@ -144,2 +144,3 @@ "use strict"; | ||
fn: parse, | ||
eval: parse, | ||
expr: function expr(input) { | ||
@@ -146,0 +147,0 @@ if ((typeof input === "undefined" ? "undefined" : _typeof(input)) == "object") return jsontokens(input);else return tokens(input); |
@@ -1,3 +0,3 @@ | ||
/*! jsexpr 2018-06-10 */ | ||
/*! jsexpr 2018-06-11 */ | ||
"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r};!function u(i,f,c){function p(t,r){if(!f[t]){if(!i[t]){var n="function"==typeof require&&require;if(!r&&n)return n(t,!0);if(a)return a(t,!0);var o=new Error("Cannot find module '"+t+"'");throw o.code="MODULE_NOT_FOUND",o}var e=f[t]={exports:{}};i[t][0].call(e.exports,function(r){return p(i[t][1][r]||r)},e,e.exports,u,i,f,c)}return f[t].exports}for(var a="function"==typeof require&&require,r=0;r<c.length;r++)p(c[r]);return p}({1:[function(t,n,o){(function(){this.jsexpr;var r=t("./index.js");void 0!==o&&(void 0!==n&&n.exports&&(o=n.exports=r),o.jsexpr=r),"undefined"!=typeof window&&(window.jsexpr=r)}).call(this)},{"./index.js":2}],2:[function(r,t,n){var o=r("./lib/expression");t.exports=o},{"./lib/expression":3}],3:[function(r,t,n){var o=r("extend"),u=/\$\{[^\}]+\}/g;function i(r,t){var n,o=(n=r,t.split(".").forEach(function(r){null!=n&&null!=n&&(n=n[r])}),n||void 0);return void 0===o?"":o}function f(o){if("${JSON}"==o)return function(r){return JSON.stringify(r,null,2)};var e=[];return(o.match(u)||[]).forEach(function(t){var r=o.indexOf(t),n=o.substring(0,r);o=o.substring(r+t.length),e.push(n),e.push(function(r){return i(r,t.replace(/\$|\{|\}/g,""))})}),e.push(o),function(t){return e.map(function(r){return"string"==typeof r?r:r(t)}).join("")}}function e(n){var i=[];return function o(e,u){e&&Object.keys(e).forEach(function(r){var t=u+(u?".":"")+r,n=e[r];"string"==typeof n?i.push({path:t,fn:f(n)}):o(n,t)})}(n,""),function(t){var r=i.map(function(r){return{path:r.path,value:r.fn(t)}}).reduce(function(r,t){return r[t.path]=t.value,r},{});return function n(o,e,u){return o&&Object.keys(o).forEach(function(r){var t=u+(u?".":"")+r;e[t]&&(o[r]=e[t]),"object"==_typeof(o[r])&&n(o[r],e,t)}),o}(o(!0,{},n),r,"")}}t.exports={fn:function(n){var r=n.match(u);r&&r.forEach(function(r){var t=r.replace(/[\$\{\}]/g,"").trim();n=n.replace(r,"__val(entry,'"+t+"')")});var t=new Function("entry","__val","return ("+n+")");return function(r){return t(r,i)}},expr:function(r){return"object"==(void 0===r?"undefined":_typeof(r))?e(r):f(r)}}},{extend:4}],4:[function(r,t,n){var e=Object.prototype.hasOwnProperty,u=Object.prototype.toString,s=function(r){return"function"==typeof Array.isArray?Array.isArray(r):"[object Array]"===u.call(r)},l=function(r){if(!r||"[object Object]"!==u.call(r))return!1;var t,n=e.call(r,"constructor"),o=r.constructor&&r.constructor.prototype&&e.call(r.constructor.prototype,"isPrototypeOf");if(r.constructor&&!n&&!o)return!1;for(t in r);return void 0===t||e.call(r,t)};t.exports=function r(){var t,n,o,e,u,i,f=arguments[0],c=1,p=arguments.length,a=!1;for("boolean"==typeof f&&(a=f,f=arguments[1]||{},c=2),(null==f||"object"!==(void 0===f?"undefined":_typeof(f))&&"function"!=typeof f)&&(f={});c<p;++c)if(null!=(t=arguments[c]))for(n in t)o=f[n],f!==(e=t[n])&&(a&&e&&(l(e)||(u=s(e)))?(u?(u=!1,i=o&&s(o)?o:[]):i=o&&l(o)?o:{},f[n]=r(a,i,e)):void 0!==e&&(f[n]=e));return f}},{}]},{},[1]); | ||
"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r};!function u(i,f,c){function a(t,r){if(!f[t]){if(!i[t]){var n="function"==typeof require&&require;if(!r&&n)return n(t,!0);if(p)return p(t,!0);var o=new Error("Cannot find module '"+t+"'");throw o.code="MODULE_NOT_FOUND",o}var e=f[t]={exports:{}};i[t][0].call(e.exports,function(r){return a(i[t][1][r]||r)},e,e.exports,u,i,f,c)}return f[t].exports}for(var p="function"==typeof require&&require,r=0;r<c.length;r++)a(c[r]);return a}({1:[function(t,n,o){(function(){this.jsexpr;var r=t("./index.js");void 0!==o&&(void 0!==n&&n.exports&&(o=n.exports=r),o.jsexpr=r),"undefined"!=typeof window&&(window.jsexpr=r)}).call(this)},{"./index.js":2}],2:[function(r,t,n){var o=r("./lib/expression");t.exports=o},{"./lib/expression":3}],3:[function(r,t,n){var o=r("extend"),u=/\$\{[^\}]+\}/g;function i(r,t){var n,o=(n=r,t.split(".").forEach(function(r){null!=n&&null!=n&&(n=n[r])}),n||void 0);return void 0===o?"":o}function e(n){var r=n.match(u);r&&r.forEach(function(r){var t=r.replace(/[\$\{\}]/g,"").trim();n=n.replace(r,"__val(entry,'"+t+"')")});var t=new Function("entry","__val","return ("+n+")");return function(r){return t(r,i)}}function f(o){if("${JSON}"==o)return function(r){return JSON.stringify(r,null,2)};var e=[];return(o.match(u)||[]).forEach(function(t){var r=o.indexOf(t),n=o.substring(0,r);o=o.substring(r+t.length),e.push(n),e.push(function(r){return i(r,t.replace(/\$|\{|\}/g,""))})}),e.push(o),function(t){return e.map(function(r){return"string"==typeof r?r:r(t)}).join("")}}function c(n){var i=[];return function o(e,u){e&&Object.keys(e).forEach(function(r){var t=u+(u?".":"")+r,n=e[r];"string"==typeof n?i.push({path:t,fn:f(n)}):o(n,t)})}(n,""),function(t){var r=i.map(function(r){return{path:r.path,value:r.fn(t)}}).reduce(function(r,t){return r[t.path]=t.value,r},{});return function n(o,e,u){return o&&Object.keys(o).forEach(function(r){var t=u+(u?".":"")+r;e[t]&&(o[r]=e[t]),"object"==_typeof(o[r])&&n(o[r],e,t)}),o}(o(!0,{},n),r,"")}}t.exports={fn:e,eval:e,expr:function(r){return"object"==(void 0===r?"undefined":_typeof(r))?c(r):f(r)}}},{extend:4}],4:[function(r,t,n){var e=Object.prototype.hasOwnProperty,u=Object.prototype.toString,s=function(r){return"function"==typeof Array.isArray?Array.isArray(r):"[object Array]"===u.call(r)},l=function(r){if(!r||"[object Object]"!==u.call(r))return!1;var t,n=e.call(r,"constructor"),o=r.constructor&&r.constructor.prototype&&e.call(r.constructor.prototype,"isPrototypeOf");if(r.constructor&&!n&&!o)return!1;for(t in r);return void 0===t||e.call(r,t)};t.exports=function r(){var t,n,o,e,u,i,f=arguments[0],c=1,a=arguments.length,p=!1;for("boolean"==typeof f&&(p=f,f=arguments[1]||{},c=2),(null==f||"object"!==(void 0===f?"undefined":_typeof(f))&&"function"!=typeof f)&&(f={});c<a;++c)if(null!=(t=arguments[c]))for(n in t)o=f[n],f!==(e=t[n])&&(p&&e&&(l(e)||(u=s(e)))?(u?(u=!1,i=o&&s(o)?o:[]):i=o&&l(o)?o:{},f[n]=r(p,i,e)):void 0!==e&&(f[n]=e));return f}},{}]},{},[1]); |
@@ -104,2 +104,3 @@ "use strict"; | ||
fn: parse, | ||
eval: parse, | ||
expr: function expr(input) { | ||
@@ -106,0 +107,0 @@ if ((typeof input === "undefined" ? "undefined" : _typeof(input)) == "object") return jsontokens(input);else return tokens(input); |
@@ -0,0 +0,0 @@ const expression = require('./'); |
@@ -25,3 +25,3 @@ module.exports = function(grunt) { | ||
expand: true, | ||
src: ['*.js','lib/*.js'], | ||
src: ['index.js','browser.js','lib/*.js'], | ||
dest: 'dist/node', | ||
@@ -28,0 +28,0 @@ ext: '.js' |
@@ -0,0 +0,0 @@ /*jshint esversion: 6 */ |
@@ -100,2 +100,3 @@ const extend = require("extend"); | ||
fn : parse, | ||
eval : parse, | ||
expr(input){ | ||
@@ -102,0 +103,0 @@ if(typeof(input)=="object") |
{ | ||
"name": "jsexpr", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "String and JSON expression interpolator and evaluator. Interpolates or evaluates a string against a json object, or transforms an object into another based on a json template", | ||
"main": "dist/node/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test-debug": "mocha --inspect-brk", | ||
"test": "mocha" | ||
}, | ||
@@ -24,11 +25,13 @@ "keywords": [ | ||
"devDependencies": { | ||
"babel-core": "^6.26.3", | ||
"babel-preset-es2015": "^6.24.1", | ||
"grunt": "^1.0.1", | ||
"grunt-babel": "^6.0.0", | ||
"grunt-browserify": "^5.0.0", | ||
"grunt": "^1.0.3", | ||
"grunt-babel": "^7.0.0", | ||
"grunt-browserify": "^5.3.0", | ||
"grunt-contrib-clean": "^1.1.0", | ||
"grunt-contrib-uglify": "^3.0.1", | ||
"load-grunt-tasks": "^3.5.2", | ||
"grunt-contrib-uglify": "^3.3.0", | ||
"load-grunt-tasks": "^4.0.0", | ||
"mocha": "^5.2.0", | ||
"uglify": "^0.1.5" | ||
} | ||
} |
@@ -0,0 +0,0 @@ # jsexpr |
@@ -1,23 +0,64 @@ | ||
const expression = require('../'); | ||
const | ||
expression = require("../"), | ||
assert = require('assert'); | ||
var fn = expression.fn("(${host}=='mymachine' || ${host}=='yourmachine') && ${appName}=='su'"); | ||
var expr = expression.expr("/var/${date}/${client.address}/file.log"); | ||
var jsexpr = expression.expr({ | ||
time : "${client}/${address.host}:${address.port}", | ||
data : { | ||
request : { | ||
headers : "${headers}" | ||
describe('Expression parser', function() { | ||
it('Should parse expression', function() { | ||
try { | ||
let fn1 = expression.fn('(${a} + ${b}) / ${c} + ${d.e}'); | ||
assert.ok("Expression parsed"); | ||
}catch(err) { | ||
assert.fail("Error thrown"); | ||
} | ||
} | ||
}); | ||
it('Should throw error', function() { | ||
try { | ||
var error = null; | ||
let fn2 = expression.fn('(${a} < ${d.e}'); | ||
}catch(err) { | ||
error = err; | ||
} | ||
assert(error!=null,); | ||
}); | ||
}); | ||
console.log(fn({host:"mymachine",appName:23})); | ||
console.log(expr({date:"2017-01-01",client:{address:"localhost"}})); | ||
console.log(jsexpr({ | ||
client : "HOST001", | ||
address : { | ||
host : "localhost", | ||
port : 8080 | ||
}, | ||
headers : "Content-Type: application/json" | ||
})); | ||
describe('String evaluation', function() { | ||
let fn1 = expression.fn('(${a} + ${b}) / ${c} + ${d.e}'); | ||
let fn2 = expression.fn('${a} < ${d.e}'); | ||
it('Should perform operation', function() { | ||
let res = fn1({a:5,b:10,c:3,d:{e:30}}); | ||
assert.equal(35,res); | ||
}); | ||
it('Should perform operation with missing value', function() { | ||
let res = fn1({b:10,c:2,d:{e:30}}); | ||
assert.equal(35,res); | ||
}); | ||
it('Should fail operation with missing values', function() { | ||
let res = fn1({d:{e:30}}); | ||
assert(isNaN(res)); | ||
}); | ||
it('Should evaluate condition (true)', function() { | ||
let res = fn2({a:5,d:{e:30}}); | ||
assert.equal(true,res); | ||
}); | ||
it('Should evaluate condition (false)', function() { | ||
let res = fn2({a:30,d:{e:30}}); | ||
assert.equal(false,res); | ||
}); | ||
}); | ||
describe('String interpolation', function() { | ||
let fn1 = expression.expr('(${a} + ${b}) / ${c} + ${d.e}'); | ||
let fn2 = expression.expr('${a} < ${d.e}'); | ||
it('Should interpolate operation', function() { | ||
let res = fn1({a:5,b:10,c:3,d:{e:30}}); | ||
assert.equal('(5 + 10) / 3 + 30',res); | ||
}); | ||
it('Should interpolate with missing values', function() { | ||
let res = fn1({b:10,c:2,d:{e:30}}); | ||
assert.equal('( + 10) / 2 + 30',res); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
45879
609
3
4
10
19