Skip to content
Browse files

regexp .match requires String

  • Loading branch information...
1 parent b979a5f commit ee53c18f6eab82250ad6b9b9c4140d71f513890a @dvv dvv committed Nov 27, 2010
Showing with 13 additions and 4 deletions.
  1. +13 −4 lib/js-array.js
View
17 lib/js-array.js
@@ -130,9 +130,15 @@ exports.operators = {
var argc = arguments.length;
return this.map(function(object){
var selected = [];
- for(var i = 0; i < argc; i++){
- var propertyName = args[i];
- selected.push(object[propertyName]);
+ if (argc === 0) {
+ for(var i in object) if (object.hasOwnProperty(i)) {
+ selected.push(object[i]);
+ }
+ } else {
+ for(var i = 0; i < argc; i++){
+ var propertyName = args[i];
+ selected.push(object[propertyName]);
+ }
}
return selected;
});
@@ -337,11 +343,14 @@ function query(query, options, target){
if(value && typeof value === "object" && !(value instanceof Array)){
var jsOperator = exports.jsOperatorMap[value.name];
if(jsOperator){
+ var item = 'item.' + value.args[0];
if (jsOperator === '===' && value.args[1] instanceof RegExp){
+ // N.B. matching requires String
+ item = 'String(item.' + value.args[0] + ')';
jsOperator = '.match('+value.args[1]+')&&""===';
value.args[1] = '';
}
- return "(function(){var filtered = []; for(var i = 0, length = this.length; i < length; i++){var item = this[i];if(item." + value.args[0] + jsOperator + queryToJS(value.args[1]) + "){filtered.push(item);}} return filtered;})";
+ return "(function(){var filtered = []; for(var i = 0, length = this.length; i < length; i++){var item = this[i];if(" + item + jsOperator + queryToJS(value.args[1]) + "){filtered.push(item);}} return filtered;})";
}else{
return "(function(){return (operators['" + value.name + "']||exports.missingOperator('" + value.name + "')).call(this" +
(value && value.args && value.args.length > 0 ? (", " + value.args.map(queryToJS).join(",")) : "") +

0 comments on commit ee53c18

Please sign in to comment.
Something went wrong with that request. Please try again.