filter list change

This commit is contained in:
hydrabolt
2015-08-20 16:03:43 +01:00
parent 685e1750d5
commit 68ffb1410b
2 changed files with 17 additions and 11 deletions

View File

@@ -156,11 +156,11 @@ exports.List.prototype.concatSublists = function( whereList, discriminator ) {
exports.List.prototype.filter = function( key, value, onlyOne, caseInsen ) { exports.List.prototype.filter = function( key, value, onlyOne, caseInsen ) {
var results = []; var results = [];
value = change(value); value = change( value );
for ( index in this.contents ) { for ( index in this.contents ) {
var child = this.contents[ index ]; var child = this.contents[ index ];
if ( change(child[ key ]) == value ) { if ( change( child[ key ] ) == value ) {
if ( onlyOne ) { if ( onlyOne ) {
return child; return child;
} else { } else {
@@ -169,8 +169,8 @@ exports.List.prototype.filter = function( key, value, onlyOne, caseInsen ) {
} }
} }
function change(val){ function change( val ) {
if(caseInsen){ if ( caseInsen ) {
val = val.toUpperCase(); val = val.toUpperCase();
} }
return val; return val;
@@ -180,13 +180,16 @@ exports.List.prototype.filter = function( key, value, onlyOne, caseInsen ) {
return false; return false;
} }
return results; var retList = new List( this.discriminator );
retList.contents = results;
return retList;
} }
exports.List.prototype.deepFilter = function( keys, value, onlyOne ) { exports.List.prototype.deepFilter = function( keys, value, onlyOne ) {
var results = []; var results = [];
value = change(value); value = change( value );
for ( index in this.contents ) { for ( index in this.contents ) {
var child = this.contents[ index ]; var child = this.contents[ index ];
@@ -196,7 +199,7 @@ exports.List.prototype.deepFilter = function( keys, value, onlyOne ) {
buffer = buffer[ key ]; buffer = buffer[ key ];
} }
if ( change(buffer) == value ) { if ( change( buffer ) == value ) {
if ( onlyOne ) { if ( onlyOne ) {
return child; return child;
} else { } else {
@@ -205,8 +208,8 @@ exports.List.prototype.deepFilter = function( keys, value, onlyOne ) {
} }
} }
function change(val){ function change( val ) {
if(caseInsen){ if ( caseInsen ) {
val = val.toUpperCase(); val = val.toUpperCase();
} }
return val; return val;
@@ -215,6 +218,9 @@ exports.List.prototype.deepFilter = function( keys, value, onlyOne ) {
if ( onlyOne ) { if ( onlyOne ) {
return false; return false;
} }
var retList = new List( this.discriminator );
retList.contents = results;
return results; return retList;
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "discord.js", "name": "discord.js",
"version": "2.6.3", "version": "2.6.4",
"description": "A way to interface with the Discord API", "description": "A way to interface with the Discord API",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {