Comparing version 0.7.4 to 0.7.5
@@ -0,0 +0,0 @@ "use strict"; |
@@ -56,4 +56,5 @@ "use strict"; | ||
if (!CACHE[key]) { | ||
var rkey = key.replace(/'/g, "\\'"); | ||
var rx = /^[a-zA-Z$_@]/; | ||
var fn = eval("(function(){\n\t\t\t\tlet rx = /^[a-zA-Z$_]/;\n\t\t\t\treturn '" + key + "'.startsWith('this.') || '" + key + "'=='this' || !rx.test('" + key + "')?\n\t\t\t\t\tfunction() {\n\t\t\t\t\t\tlet r = undefined;\n\t\t\t\t\t\ttry {r=" + key + ";}\n\t\t\t\t\t\tcatch(err){}\n\t\t\t\t\t\treturn r;\n\t\t\t\t\t} :\n\t\t\t\t\tfunction() {\n\t\t\t\t\t\tlet r = undefined;\n\t\t\t\t\t\ttry {r=this." + (rx.test(key) ? key : '$___$') + ";}\n\t\t\t\t\t\tcatch(err){try{r=" + key + ";}catch(err){}}\n\t\t\t\t\t\treturn r;\n\t\t\t\t\t}\n\t\t\t})()"); | ||
var fn = eval("(function(){\n\t\t\t\tlet rx = /^[a-zA-Z$_]/;\n\t\t\t\treturn '" + rkey + "'.startsWith('this.') || '" + rkey + "'=='this' || !rx.test('" + rkey + "')?\n\t\t\t\t\tfunction() {\n\t\t\t\t\t\tlet r = undefined;\n\t\t\t\t\t\ttry {r=" + key + ";}\n\t\t\t\t\t\tcatch(err){}\n\t\t\t\t\t\treturn r;\n\t\t\t\t\t} :\n\t\t\t\t\tfunction() {\n\t\t\t\t\t\tlet r = undefined;\n\t\t\t\t\t\ttry {r=this." + (rx.test(key) ? key : '$___$') + ";}\n\t\t\t\t\t\tcatch(err){try{r=" + key + ";}catch(err){}}\n\t\t\t\t\t\treturn r;\n\t\t\t\t\t}\n\t\t\t})()"); | ||
CACHE[key] = fn; | ||
@@ -110,3 +111,3 @@ } | ||
m.forEach(function (token) { | ||
var key = token.replace(RX_RPL_PARSE, "$1").trim(); | ||
var key = token.replace(RX_RPL_PARSE, "$1").trim().replace(/'/g, "\\'"); | ||
expr = expr.replace(token, "__val(entry,'" + key + "')"); | ||
@@ -249,2 +250,4 @@ }); | ||
var toStr = Object.prototype.toString; | ||
var defineProperty = Object.defineProperty; | ||
var gOPD = Object.getOwnPropertyDescriptor; | ||
@@ -279,2 +282,31 @@ var isArray = function isArray(arr) { | ||
// If name is '__proto__', and Object.defineProperty is available, define __proto__ as an own property on target | ||
var setProperty = function setProperty(target, options) { | ||
if (defineProperty && options.name === '__proto__') { | ||
defineProperty(target, options.name, { | ||
enumerable: true, | ||
configurable: true, | ||
value: options.newValue, | ||
writable: true | ||
}); | ||
} else { | ||
target[options.name] = options.newValue; | ||
} | ||
}; | ||
// Return undefined instead of __proto__ if '__proto__' is not an own property | ||
var getProperty = function getProperty(obj, name) { | ||
if (name === '__proto__') { | ||
if (!hasOwn.call(obj, name)) { | ||
return void 0; | ||
} else if (gOPD) { | ||
// In early versions of node, obj['__proto__'] is buggy when obj has | ||
// __proto__ as an own property. Object.getOwnPropertyDescriptor() works. | ||
return gOPD(obj, name).value; | ||
} | ||
} | ||
return obj[name]; | ||
}; | ||
module.exports = function extend() { | ||
@@ -304,4 +336,4 @@ var options, name, src, copy, copyIsArray, clone; | ||
for (name in options) { | ||
src = target[name]; | ||
copy = options[name]; | ||
src = getProperty(target, name); | ||
copy = getProperty(options, name); | ||
@@ -320,7 +352,7 @@ // Prevent never-ending loop | ||
// Never move original objects, clone them | ||
target[name] = extend(deep, clone, copy); | ||
setProperty(target, { name: name, newValue: extend(deep, clone, copy) }); | ||
// Don't bring in undefined values | ||
} else if (typeof copy !== 'undefined') { | ||
target[name] = copy; | ||
setProperty(target, { name: name, newValue: copy }); | ||
} | ||
@@ -327,0 +359,0 @@ } |
@@ -1,3 +0,3 @@ | ||
/*! jsexpr 2019-11-27 */ | ||
/*! jsexpr 2020-03-11 */ | ||
"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!function i(u,c,f){function a(n,t){if(!c[n]){if(!u[n]){var r="function"==typeof require&&require;if(!t&&r)return r(n,!0);if(s)return s(n,!0);var e=new Error("Cannot find module '"+n+"'");throw e.code="MODULE_NOT_FOUND",e}var o=c[n]={exports:{}};u[n][0].call(o.exports,function(t){return a(u[n][1][t]||t)},o,o.exports,i,u,c,f)}return c[n].exports}for(var s="function"==typeof require&&require,t=0;t<f.length;t++)a(f[t]);return a}({1:[function(n,r,e){(function(){this.jsexpr;var t=n("./index.js");void 0!==e&&(void 0!==r&&r.exports&&(e=r.exports=t),e.jsexpr=t),"undefined"!=typeof window&&(window.jsexpr=t)}).call(this)},{"./index.js":2}],2:[function(t,n,r){var e=t("./lib");n.exports=e},{"./lib":4}],3:[function(require,module,exports){var extend=require("extend");function instance(token){var RX=new RegExp("\\"+token+"\\{[^\\}]+\\}","g"),RX_RPL_PARSE=new RegExp("\\"+token+"\\{([^\\}]+)\\}"),RX_RPL_TOKEN=new RegExp("\\"+token+"\\{|\\}","g"),RX_JSON_TOKEN=new RegExp("^\\"+token+"\\{JSON(:(\\d+|([^:]+(:(\\d+))?)))?\\}$"),CACHE={};function cacheeval(obj,key){if(!CACHE[key]){var rx=/^[a-zA-Z$_@]/,fn=eval("(function(){\n\t\t\t\tlet rx = /^[a-zA-Z$_]/;\n\t\t\t\treturn '"+key+"'.startsWith('this.') || '"+key+"'=='this' || !rx.test('"+key+"')?\n\t\t\t\t\tfunction() {\n\t\t\t\t\t\tlet r = undefined;\n\t\t\t\t\t\ttry {r="+key+";}\n\t\t\t\t\t\tcatch(err){}\n\t\t\t\t\t\treturn r;\n\t\t\t\t\t} :\n\t\t\t\t\tfunction() {\n\t\t\t\t\t\tlet r = undefined;\n\t\t\t\t\t\ttry {r=this."+(rx.test(key)?key:"$___$")+";}\n\t\t\t\t\t\tcatch(err){try{r="+key+";}catch(err){}}\n\t\t\t\t\t\treturn r;\n\t\t\t\t\t}\n\t\t\t})()");CACHE[key]=fn}return CACHE[key].call(obj)}function fneval(obj,key){try{return eval("this."+key)}catch(t){return}}function fnassign(path){return eval("(function(){\n\t\t\treturn function(obj,val) {\n\t\t\t\ttry {\n\t\t\t\t\treturn obj."+path+" = val;\n\t\t\t\t}catch(err) {}\n\t\t\t}\n\t\t})()")}var EVALS={eval:function(t,n){var r=fneval.call(t,t,n);return void 0===r?"":r},iteval:function(n,t){t.split(".").forEach(function(t){null!=n&&null!=n&&(n=n[t])});var r=n||void 0;return void 0===r?"":r},ceval:function(t,n){var r=cacheeval(t,n);return void 0===r?"":r},valwalk:function(t,n,r){if(!t)return t;for(var e in t){var o=r+(r?".":"")+e,i=n[o];void 0!==i?t[e]=i:"object"==_typeof(t[e])&&EVALS.valwalk(t[e],n,o)}return t}};function parse(r,n){n=n||"ceval";var t=r.match(RX);t&&t.forEach(function(t){var n=t.replace(RX_RPL_PARSE,"$1").trim();r=r.replace(t,"__val(entry,'"+n+"')")});var e=new Function("entry","__val","return ("+r+")");return function(t){return e(t,EVALS[n])}}function tokens(o,i){if(i=EVALS[i||"ceval"],RX_JSON_TOKEN.test(o)){var t=o.replace(RX_RPL_TOKEN,"").split(":"),n=t[1],r=t[2];2==t.length?isNaN(n)?r=2:(n="this",r=t[1]):1==t.length&&(n="this",r=2),r=parseInt(r);var e=tokens("${"+n+"}");return function(t){return JSON.stringify(e(t),null,r)}}var u,c=[];return(o.match(RX)||[]).forEach(function(t){var n=o.indexOf(t),r=o.substring(0,n),e=t.replace(RX_RPL_TOKEN,"");o=o.substring(n+t.length),c.push(r),c.push(function(t){return i(t,e)})}),c.push(o),c=c.filter(function(t){return""!=t}),1<(u=c.length)?function(t){for(var n="",r=0;r<u;r++){var e=c[r];n+="string"==typeof e?e:e(t)}return n}:function(t){var n=c[0];return"string"==typeof n?n:n(t)}}function jsontokens(o){var i,u=[];return function e(o,i){o&&Object.keys(o).forEach(function(t){var n=i+(i?".":"")+t,r=o[t];"string"==typeof r?u.push({path:n,fn:tokens(r)}):e(r,n)})}(o,""),i=u.length,function(t){for(var n={},r=0;r<i;r++){var e=u[r];n[e.path]=e.fn(t)}return EVALS.valwalk(extend(!0,{},o),n,"")}}function exprfn(n,t){return"number"==typeof n?function(t){return n}:"object"==(void 0===n?"undefined":_typeof(n))?jsontokens(n,t):tokens(n)}return{fn:parse,eval:parse,assign:fnassign,expr:exprfn,expression:exprfn}}module.exports=instance},{extend:5}],4:[function(t,n,r){var e=t("./expression"),o=e("$");o.newInstance=function(t){return e(t)},n.exports=o},{"./expression":3}],5:[function(t,n,r){var o=Object.prototype.hasOwnProperty,i=Object.prototype.toString,l=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},p=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var n,r=o.call(t,"constructor"),e=t.constructor&&t.constructor.prototype&&o.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!r&&!e)return!1;for(n in t);return void 0===n||o.call(t,n)};n.exports=function t(){var n,r,e,o,i,u,c=arguments[0],f=1,a=arguments.length,s=!1;for("boolean"==typeof c&&(s=c,c=arguments[1]||{},f=2),(null==c||"object"!==(void 0===c?"undefined":_typeof(c))&&"function"!=typeof c)&&(c={});f<a;++f)if(null!=(n=arguments[f]))for(r in n)e=c[r],c!==(o=n[r])&&(s&&o&&(p(o)||(i=l(o)))?(i?(i=!1,u=e&&l(e)?e:[]):u=e&&p(e)?e:{},c[r]=t(s,u,o)):void 0!==o&&(c[r]=o));return c}},{}]},{},[1]); | ||
"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!function i(u,a,c){function f(n,t){if(!a[n]){if(!u[n]){var r="function"==typeof require&&require;if(!t&&r)return r(n,!0);if(l)return l(n,!0);var e=new Error("Cannot find module '"+n+"'");throw e.code="MODULE_NOT_FOUND",e}var o=a[n]={exports:{}};u[n][0].call(o.exports,function(t){return f(u[n][1][t]||t)},o,o.exports,i,u,a,c)}return a[n].exports}for(var l="function"==typeof require&&require,t=0;t<c.length;t++)f(c[t]);return f}({1:[function(n,r,e){(function(){this.jsexpr;var t=n("./index.js");void 0!==e&&(void 0!==r&&r.exports&&(e=r.exports=t),e.jsexpr=t),"undefined"!=typeof window&&(window.jsexpr=t)}).call(this)},{"./index.js":2}],2:[function(t,n,r){var e=t("./lib");n.exports=e},{"./lib":4}],3:[function(require,module,exports){var extend=require("extend");function instance(token){var RX=new RegExp("\\"+token+"\\{[^\\}]+\\}","g"),RX_RPL_PARSE=new RegExp("\\"+token+"\\{([^\\}]+)\\}"),RX_RPL_TOKEN=new RegExp("\\"+token+"\\{|\\}","g"),RX_JSON_TOKEN=new RegExp("^\\"+token+"\\{JSON(:(\\d+|([^:]+(:(\\d+))?)))?\\}$"),CACHE={};function cacheeval(obj,key){if(!CACHE[key]){var rkey=key.replace(/'/g,"\\'"),rx=/^[a-zA-Z$_@]/,fn=eval("(function(){\n\t\t\t\tlet rx = /^[a-zA-Z$_]/;\n\t\t\t\treturn '"+rkey+"'.startsWith('this.') || '"+rkey+"'=='this' || !rx.test('"+rkey+"')?\n\t\t\t\t\tfunction() {\n\t\t\t\t\t\tlet r = undefined;\n\t\t\t\t\t\ttry {r="+key+";}\n\t\t\t\t\t\tcatch(err){}\n\t\t\t\t\t\treturn r;\n\t\t\t\t\t} :\n\t\t\t\t\tfunction() {\n\t\t\t\t\t\tlet r = undefined;\n\t\t\t\t\t\ttry {r=this."+(rx.test(key)?key:"$___$")+";}\n\t\t\t\t\t\tcatch(err){try{r="+key+";}catch(err){}}\n\t\t\t\t\t\treturn r;\n\t\t\t\t\t}\n\t\t\t})()");CACHE[key]=fn}return CACHE[key].call(obj)}function fneval(obj,key){try{return eval("this."+key)}catch(t){return}}function fnassign(path){return eval("(function(){\n\t\t\treturn function(obj,val) {\n\t\t\t\ttry {\n\t\t\t\t\treturn obj."+path+" = val;\n\t\t\t\t}catch(err) {}\n\t\t\t}\n\t\t})()")}var EVALS={eval:function(t,n){var r=fneval.call(t,t,n);return void 0===r?"":r},iteval:function(n,t){t.split(".").forEach(function(t){null!=n&&null!=n&&(n=n[t])});var r=n||void 0;return void 0===r?"":r},ceval:function(t,n){var r=cacheeval(t,n);return void 0===r?"":r},valwalk:function(t,n,r){if(!t)return t;for(var e in t){var o=r+(r?".":"")+e,i=n[o];void 0!==i?t[e]=i:"object"==_typeof(t[e])&&EVALS.valwalk(t[e],n,o)}return t}};function parse(r,n){n=n||"ceval";var t=r.match(RX);t&&t.forEach(function(t){var n=t.replace(RX_RPL_PARSE,"$1").trim().replace(/'/g,"\\'");r=r.replace(t,"__val(entry,'"+n+"')")});var e=new Function("entry","__val","return ("+r+")");return function(t){return e(t,EVALS[n])}}function tokens(o,i){if(i=EVALS[i||"ceval"],RX_JSON_TOKEN.test(o)){var t=o.replace(RX_RPL_TOKEN,"").split(":"),n=t[1],r=t[2];2==t.length?isNaN(n)?r=2:(n="this",r=t[1]):1==t.length&&(n="this",r=2),r=parseInt(r);var e=tokens("${"+n+"}");return function(t){return JSON.stringify(e(t),null,r)}}var u,a=[];return(o.match(RX)||[]).forEach(function(t){var n=o.indexOf(t),r=o.substring(0,n),e=t.replace(RX_RPL_TOKEN,"");o=o.substring(n+t.length),a.push(r),a.push(function(t){return i(t,e)})}),a.push(o),a=a.filter(function(t){return""!=t}),1<(u=a.length)?function(t){for(var n="",r=0;r<u;r++){var e=a[r];n+="string"==typeof e?e:e(t)}return n}:function(t){var n=a[0];return"string"==typeof n?n:n(t)}}function jsontokens(o){var i,u=[];return function e(o,i){o&&Object.keys(o).forEach(function(t){var n=i+(i?".":"")+t,r=o[t];"string"==typeof r?u.push({path:n,fn:tokens(r)}):e(r,n)})}(o,""),i=u.length,function(t){for(var n={},r=0;r<i;r++){var e=u[r];n[e.path]=e.fn(t)}return EVALS.valwalk(extend(!0,{},o),n,"")}}function exprfn(n,t){return"number"==typeof n?function(t){return n}:"object"==(void 0===n?"undefined":_typeof(n))?jsontokens(n,t):tokens(n)}return{fn:parse,eval:parse,assign:fnassign,expr:exprfn,expression:exprfn}}module.exports=instance},{extend:5}],4:[function(t,n,r){var e=t("./expression"),o=e("$");o.newInstance=function(t){return e(t)},n.exports=o},{"./expression":3}],5:[function(t,n,r){var o=Object.prototype.hasOwnProperty,i=Object.prototype.toString,e=Object.defineProperty,u=Object.getOwnPropertyDescriptor,s=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},p=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var n,r=o.call(t,"constructor"),e=t.constructor&&t.constructor.prototype&&o.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!r&&!e)return!1;for(n in t);return void 0===n||o.call(t,n)},v=function(t,n){e&&"__proto__"===n.name?e(t,n.name,{enumerable:!0,configurable:!0,value:n.newValue,writable:!0}):t[n.name]=n.newValue},y=function(t,n){if("__proto__"===n){if(!o.call(t,n))return;if(u)return u(t,n).value}return t[n]};n.exports=function t(){var n,r,e,o,i,u,a=arguments[0],c=1,f=arguments.length,l=!1;for("boolean"==typeof a&&(l=a,a=arguments[1]||{},c=2),(null==a||"object"!==(void 0===a?"undefined":_typeof(a))&&"function"!=typeof a)&&(a={});c<f;++c)if(null!=(n=arguments[c]))for(r in n)e=y(a,r),a!==(o=y(n,r))&&(l&&o&&(p(o)||(i=s(o)))?(i?(i=!1,u=e&&s(e)?e:[]):u=e&&p(e)?e:{},v(a,{name:r,newValue:t(l,u,o)})):void 0!==o&&v(a,{name:r,newValue:o}));return a}},{}]},{},[1]); |
@@ -16,4 +16,5 @@ 'use strict'; | ||
if (!CACHE[key]) { | ||
var rkey = key.replace(/'/g, "\\'"); | ||
var rx = /^[a-zA-Z$_@]/; | ||
var fn = eval('(function(){\n\t\t\t\tlet rx = /^[a-zA-Z$_]/;\n\t\t\t\treturn \'' + key + '\'.startsWith(\'this.\') || \'' + key + '\'==\'this\' || !rx.test(\'' + key + '\')?\n\t\t\t\t\tfunction() {\n\t\t\t\t\t\tlet r = undefined;\n\t\t\t\t\t\ttry {r=' + key + ';}\n\t\t\t\t\t\tcatch(err){}\n\t\t\t\t\t\treturn r;\n\t\t\t\t\t} :\n\t\t\t\t\tfunction() {\n\t\t\t\t\t\tlet r = undefined;\n\t\t\t\t\t\ttry {r=this.' + (rx.test(key) ? key : '$___$') + ';}\n\t\t\t\t\t\tcatch(err){try{r=' + key + ';}catch(err){}}\n\t\t\t\t\t\treturn r;\n\t\t\t\t\t}\n\t\t\t})()'); | ||
var fn = eval('(function(){\n\t\t\t\tlet rx = /^[a-zA-Z$_]/;\n\t\t\t\treturn \'' + rkey + '\'.startsWith(\'this.\') || \'' + rkey + '\'==\'this\' || !rx.test(\'' + rkey + '\')?\n\t\t\t\t\tfunction() {\n\t\t\t\t\t\tlet r = undefined;\n\t\t\t\t\t\ttry {r=' + key + ';}\n\t\t\t\t\t\tcatch(err){}\n\t\t\t\t\t\treturn r;\n\t\t\t\t\t} :\n\t\t\t\t\tfunction() {\n\t\t\t\t\t\tlet r = undefined;\n\t\t\t\t\t\ttry {r=this.' + (rx.test(key) ? key : '$___$') + ';}\n\t\t\t\t\t\tcatch(err){try{r=' + key + ';}catch(err){}}\n\t\t\t\t\t\treturn r;\n\t\t\t\t\t}\n\t\t\t})()'); | ||
CACHE[key] = fn; | ||
@@ -70,3 +71,3 @@ } | ||
m.forEach(function (token) { | ||
var key = token.replace(RX_RPL_PARSE, "$1").trim(); | ||
var key = token.replace(RX_RPL_PARSE, "$1").trim().replace(/'/g, "\\'"); | ||
expr = expr.replace(token, "__val(entry,'" + key + "')"); | ||
@@ -73,0 +74,0 @@ }); |
@@ -0,0 +0,0 @@ const expression = require('../../dist/node'); |
@@ -0,0 +0,0 @@ module.exports = function(grunt) { |
@@ -0,0 +0,0 @@ /*jshint esversion: 6 */ |
@@ -0,0 +0,0 @@ const extend = require("extend"); |
@@ -0,0 +0,0 @@ let expression = require('./expression'); |
{ | ||
"name": "jsexpr", | ||
"version": "0.7.4", | ||
"version": "0.7.5", | ||
"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", | ||
@@ -5,0 +5,0 @@ "main": "dist/node/index.js", |
@@ -0,0 +0,0 @@ # jsexpr |
@@ -68,4 +68,12 @@ const expr = require('./index.js'); | ||
let test07 = { | ||
obj : {a:new Date()}, | ||
xps : [ | ||
{type:'expr', xp:"${a.toLocaleTimeString('en')}"}, | ||
] | ||
}; | ||
runTest(test04); | ||
runTest(test05); | ||
runTest(test06); | ||
runTest(test07); |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ const |
@@ -0,0 +0,0 @@ const |
@@ -0,0 +0,0 @@ const |
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
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
77193
1024