Comparing version 0.1.4 to 0.1.5
@@ -5,3 +5,3 @@ 'use strict'; | ||
isValidCondition = _require.isValidCondition, | ||
replaceVariable = _require.replaceVariable, | ||
getVariableValue = _require.getVariableValue, | ||
callExpression = _require.callExpression; | ||
@@ -22,3 +22,3 @@ | ||
} else { | ||
value.push(replaceVariable(expression[i], context)); | ||
value.push(getVariableValue(expression[i], context)); | ||
} | ||
@@ -25,0 +25,0 @@ |
{ | ||
"name": "jsexp", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -7,3 +7,3 @@ 'use strict'; | ||
isValidCondition = _require.isValidCondition, | ||
replaceVariable = _require.replaceVariable; | ||
getVariableValue = _require.getVariableValue; | ||
/** | ||
@@ -30,3 +30,3 @@ * 数组转字符串 | ||
} else { | ||
var replacedValue = replaceVariable(expression[i], context); | ||
var replacedValue = getVariableValue(expression[i], context); | ||
value.push(typeof replacedValue === 'string' ? "'".concat(replacedValue, "'") : replacedValue); | ||
@@ -33,0 +33,0 @@ } |
23
utils.js
@@ -28,2 +28,3 @@ 'use strict'; | ||
var rVariable = /^@(.+)/; | ||
var rDeepPath = /^\d+\./; | ||
@@ -33,4 +34,10 @@ function isValidCondition(expression) { | ||
} | ||
/** | ||
* @param variable {string} | ||
* @param context {object|array} | ||
* @returns {string|*} | ||
*/ | ||
function replaceVariable(variable, context) { | ||
function getVariableValue(variable, context) { | ||
if (context && typeof variable === 'string' && rVariable.test(variable)) { | ||
@@ -40,4 +47,4 @@ var key = variable.substr(1); | ||
if (Array.isArray(context)) { | ||
for (var i = 0; i < context.length; i++) { | ||
var value = get(context[i], key); | ||
if (rDeepPath.test(key)) { | ||
var value = get(context, key); | ||
@@ -47,2 +54,10 @@ if (value !== undefined) { | ||
} | ||
} else { | ||
for (var i = context.length - 1; i >= 0; i--) { | ||
var _value = get(context[i], key); | ||
if (_value !== undefined) { | ||
return _value; | ||
} | ||
} | ||
} | ||
@@ -67,4 +82,4 @@ } else { | ||
isValidCondition: isValidCondition, | ||
replaceVariable: replaceVariable, | ||
getVariableValue: getVariableValue, | ||
callExpression: callExpression | ||
}; |
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
35141
1101