Skip to content

Commit

Permalink
Create caseInsenstiveCompare GetValue and fixed issues with ||
Browse files Browse the repository at this point in the history
  • Loading branch information
KoryNunn committed Aug 4, 2012
1 parent 32c9de3 commit 6eeceae
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions gel.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,15 @@
},
"||": function orTruthy() {
// does a truthy "or", like the JS "||"
var argsLength = arguments.length;
for (var i = 1; i < argsLength; i++) {
if (!(arguments[i] || arguments[i - 1])) return false;
var argsLength = arguments.length,
last = arguments[0];

if(argsLength){
for (var i = 0; i < argsLength - 1; i++) {
last = arguments[i] || arguments[i + 1];
}
}
return arguments[argsLength - 1];
return last;
},
"+": function add() {
// add all arguments (force numbers) (args:0+)
Expand Down Expand Up @@ -527,7 +531,7 @@
throw "parameter was not an object";
}
},
"filterKeys": function filter() {
"filterKeys": function filterKeys() {
var args = Array.prototype.slice.call(arguments),
filteredObject;
if (args.length < 2) {
Expand All @@ -541,7 +545,11 @@
if(Array.isArray(objectToFilter)){
filteredObject = [];
}else{
filteredObject = new objectToFilter.prototype.constructor();
if(objectToFilter.prototype){
filteredObject = new objectToFilter.prototype.constructor();
}else{
filteredObject = {};
}
}

for(var key in objectToFilter){
Expand Down Expand Up @@ -709,6 +717,13 @@

return result;
},
"getValue": function getValue() {
// make an object (args:0+)
var argsLength = arguments.length;
if (argsLength !== 2) throw "getValue function needs 2 arguments";

return arguments[0][arguments[1]];
},
"date": function() {
return Date();
},
Expand All @@ -720,6 +735,14 @@
},
"toJSON": function makeLambda() {
return JSON.stringify(arguments[0]);
},
"caseInsenstiveCompare": function caseInsenstiveCompare(){
var argsLength = arguments.length;
if (argsLength <= 1) throw "caseInsenstiveCompare function needs more than one argument";
for (var i = 1; i < argsLength; i++) {
if (arguments[i].toLowerCase() !== arguments[i - 1].toLowerCase()) return false;
}
return true;
}

};
Expand All @@ -738,9 +761,10 @@
var memoisedTokens = {};

function tokenise(expression, inRecursion, typeOfNest) {
if(memoisedTokens[expression]){
return memoisedTokens[expression];
}
var memoiseKey = expression;
// if(memoisedTokens[expression]){
// return memoisedTokens[expression];
// }
if(!expression){
return [];
}
Expand Down Expand Up @@ -820,7 +844,7 @@
throw "Invalid nesting in " + originalExpression;
}

memoisedTokens[expression] = tokens;
memoisedTokens[memoiseKey] = tokens;

return tokens;
}
Expand Down Expand Up @@ -928,7 +952,7 @@
if (!value) {
value = scopedVariables[token.value];
}
if (!value) {
if (!scopedVariables.hasOwnProperty(token.value)) {
throw strings.UnknownIdentifier.format(token.value);
}

Expand Down

0 comments on commit 6eeceae

Please sign in to comment.