openrosa-xpath-evaluator
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "openrosa-xpath-evaluator", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Wrapper for browsers' XPath evaluator with added support for OpenRosa extensions.", | ||
@@ -14,3 +14,3 @@ "main": "src/openrosa-xpath.js", | ||
"jshint": "^2.8.0", | ||
"karma": "^0.12.37", | ||
"karma": "^1.5.0", | ||
"karma-chai": "^0.1.0", | ||
@@ -17,0 +17,0 @@ "karma-chrome-launcher": "^0.2.0", |
@@ -48,3 +48,3 @@ /* | ||
callExtended = function(name, args) { | ||
var argVals = [], argString, res, i; | ||
var argVals = [], res, i; | ||
for(i=0; i<args.length; ++i) argVals.push(args[i].v); | ||
@@ -77,7 +77,6 @@ res = extendedFuncs[name].apply(null, argVals); | ||
return 'str'; | ||
}, | ||
___end_vars___; | ||
}; | ||
this.evaluate = function(input) { | ||
var cur, stack = [{ t:'root', tokens:[] }], | ||
var i, cur, stack = [{ t:'root', tokens:[] }], | ||
peek = function() { return stack[stack.length-1]; }, | ||
@@ -92,3 +91,3 @@ err = function(message) { throw new Error((message||'') + ' [stack=' + JSON.stringify(stack) + '] [cur=' + JSON.stringify(cur) + ']'); }, | ||
if(extendedProcessors.handleInfix) { | ||
var res = extendedProcessors.handleInfix(lhs, op, rhs); | ||
var res = extendedProcessors.handleInfix(err, lhs, op, rhs); | ||
if(res && res.t === 'continue') { | ||
@@ -118,3 +117,3 @@ lhs = res.lhs; op = res.op; rhs = res.rhs; res = null; | ||
evalOpAt = function(tokens, opIndex) { | ||
res = evalOp( | ||
var res = evalOp( | ||
tokens[opIndex - 1], | ||
@@ -131,3 +130,3 @@ tokens[opIndex], | ||
// handle infix operators | ||
var i, ops, tokens; | ||
var i, j, ops, tokens; | ||
tokens = peek().tokens; | ||
@@ -146,10 +145,6 @@ | ||
handleXpathExpr = function() { | ||
var v = cur.v.trim(), | ||
evaluated = toInternalResult(wrapped(cur.v)); | ||
var evaluated = toInternalResult(wrapped(cur.v)); | ||
peek().tokens.push(evaluated); | ||
newCurrent(); | ||
}, | ||
lastChar = function() { | ||
if(i > 0) return input.charAt(i-1); | ||
}, | ||
nextChar = function() { | ||
@@ -163,3 +158,9 @@ if(i < input.length -1) return input.charAt(i+1); | ||
}, | ||
___end_vars___; | ||
prevToken = function() { | ||
var peeked = peek().tokens; | ||
return peeked[peeked.length - 1]; | ||
}, | ||
isNum = function(c) { | ||
return c >= '0' && c <= '9'; | ||
}; | ||
@@ -169,3 +170,3 @@ newCurrent(); | ||
for(i=0; i<input.length; ++i) { | ||
c = input.charAt(i); | ||
var c = input.charAt(i); | ||
if(cur.t === 'str') { | ||
@@ -187,17 +188,7 @@ if(c === cur.quote) { | ||
} | ||
switch(c) { | ||
case '0': | ||
case '1': | ||
case '2': | ||
case '3': | ||
case '4': | ||
case '5': | ||
case '6': | ||
case '7': | ||
case '8': | ||
case '9': | ||
if(isNum(c)) { | ||
if(cur.v === '') { | ||
cur = { t:'num', string:c }; | ||
} else cur.v += c; | ||
break; | ||
} else switch(c) { | ||
case "'": | ||
@@ -245,3 +236,3 @@ case '"': | ||
break; | ||
} else if(peek().tokens.length === 0) { | ||
} else if(peek().tokens.length === 0 || prevToken().t === 'op') { | ||
// -ve number | ||
@@ -313,3 +304,3 @@ cur = { t:'num', string:'-' }; | ||
if(cur.t !== '?' || cur.v !== '' || (cur.tokens && current.tokens.length)) err('Current item not evaluated!'); | ||
if(cur.t !== '?' || cur.v !== '' || (cur.tokens && cur.tokens.length)) err('Current item not evaluated!'); | ||
if(stack.length > 1) err('Stuff left on stack.'); | ||
@@ -316,0 +307,0 @@ if(stack[0].t !== 'root') err('Weird stuff on stack.'); |
var openrosa_xpath_extensions = (function() { | ||
var ___start_vars___, | ||
var | ||
MILLIS_PER_DAY = 1000 * 60 * 60 * 24, | ||
@@ -129,4 +129,3 @@ MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], | ||
func, | ||
now_and_today = function() { return XPR.date(new Date()); }, | ||
___end_vars___; | ||
now_and_today = function() { return XPR.date(new Date()); }; | ||
@@ -229,3 +228,3 @@ func = { | ||
}, | ||
handleInfix: function(lhs, op, rhs) { | ||
handleInfix: function(err, lhs, op, rhs) { | ||
if(lhs.t === 'date' || rhs.t === 'date') { | ||
@@ -232,0 +231,0 @@ // For comparisons, we must make sure that both values are numbers |
@@ -107,2 +107,22 @@ define(['src/extended-xpath', 'chai', 'lodash'], function(ExtendedXpathEvaluator, chai, _) { | ||
/^7$/, | ||
'1 > 0': | ||
/^true$/, | ||
'1 > 1': | ||
/^false$/, | ||
'1 < 1': | ||
/^false$/, | ||
'1 > -1': | ||
/^true$/, | ||
'1 < -1': | ||
/^false$/, | ||
'-1 > 1': | ||
/^false$/, | ||
'-1 < 1': | ||
/^true$/, | ||
'-1 > -1': | ||
/^false$/, | ||
'-1 < -1': | ||
/^false$/, | ||
'-1 < -2': | ||
/^false$/, | ||
}, | ||
@@ -109,0 +129,0 @@ trickyStandardXpath_supported = [ |
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
146958
15
2373