mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
Most arrays are now using lists.
This commit is contained in:
96
lib/list.js
96
lib/list.js
@@ -1,74 +1,74 @@
|
||||
exports.List = function(discriminator) {
|
||||
this.discriminator = discriminator;
|
||||
this.contents = [];
|
||||
exports.List = function( discriminator ) {
|
||||
this.discriminator = discriminator;
|
||||
this.contents = [];
|
||||
}
|
||||
|
||||
exports.List.prototype.add = function(child){
|
||||
if(child.constructor === Array){
|
||||
exports.List.prototype.add = function( child ) {
|
||||
if ( child.constructor === Array ) {
|
||||
|
||||
children = child;
|
||||
for(child of children){
|
||||
if( this.filter( this.discriminator, child[this.discriminator] ).length === 0 )
|
||||
this.contents.push(child);
|
||||
}
|
||||
children = child;
|
||||
for ( child of children ) {
|
||||
if ( this.filter( this.discriminator, child[ this.discriminator ] ).length === 0 )
|
||||
this.contents.push( child );
|
||||
}
|
||||
|
||||
}else{
|
||||
if( this.filter( this.discriminator, child[this.discriminator] ).length === 0 )
|
||||
this.contents.push(child);
|
||||
}
|
||||
} else {
|
||||
if ( this.filter( this.discriminator, child[ this.discriminator ] ).length === 0 )
|
||||
this.contents.push( child );
|
||||
}
|
||||
}
|
||||
|
||||
exports.List.prototype.length = function(){
|
||||
return this.contents.length;
|
||||
exports.List.prototype.length = function() {
|
||||
return this.contents.length;
|
||||
}
|
||||
|
||||
exports.List.prototype.removeIndex = function(index){
|
||||
this.contents.splice(index, 1);
|
||||
exports.List.prototype.removeIndex = function( index ) {
|
||||
this.contents.splice( index, 1 );
|
||||
}
|
||||
|
||||
exports.List.prototype.removeChild = function(child){
|
||||
exports.List.prototype.removeElement = function( child ) {
|
||||
|
||||
var index = this.contents.indexOf(child);
|
||||
var index = this.contents.indexOf( child );
|
||||
|
||||
if( index === -1 ){
|
||||
return false;
|
||||
}
|
||||
if ( index === -1 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.removeIndex(index);
|
||||
this.removeIndex( index );
|
||||
|
||||
}
|
||||
|
||||
exports.List.prototype.concatSublists = function(whereList, discriminator){
|
||||
//this is meant to look at the contents, and assuming the contents are all lists, concatenate their values.
|
||||
exports.List.prototype.concatSublists = function( whereList, discriminator ) {
|
||||
//this is meant to look at the contents, and assuming the contents are all lists, concatenate their values.
|
||||
|
||||
var concatList = new exports.List(discriminator);
|
||||
var concatList = new exports.List( discriminator );
|
||||
|
||||
for(item of this.contents){
|
||||
var itemList = item[whereList];
|
||||
concatList.add(itemList.contents);
|
||||
}
|
||||
for ( item of this.contents ) {
|
||||
var itemList = item[ whereList ];
|
||||
concatList.add( itemList.contents );
|
||||
}
|
||||
|
||||
return concatList;
|
||||
return concatList;
|
||||
}
|
||||
|
||||
exports.List.prototype.filter = function(key, value, onlyOne) {
|
||||
exports.List.prototype.filter = function( key, value, onlyOne ) {
|
||||
|
||||
var results = [];
|
||||
var results = [];
|
||||
|
||||
for (index in this.contents) {
|
||||
var child = this.contents[index];
|
||||
if (child[key] == value) {
|
||||
if (onlyOne) {
|
||||
return child;
|
||||
} else {
|
||||
results.push(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
for ( index in this.contents ) {
|
||||
var child = this.contents[ index ];
|
||||
if ( child[ key ] == value ) {
|
||||
if ( onlyOne ) {
|
||||
return child;
|
||||
} else {
|
||||
results.push( child );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(onlyOne){
|
||||
return false;
|
||||
}
|
||||
if ( onlyOne ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return results;
|
||||
return results;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user