Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Worlds

Hierarchy

Index

Constructors

constructor

  • new Worlds(entries?: readonly readonly [number, World][] | null): Worlds

Properties

Readonly size

size: number
returns

the number of elements in the Map.

Static Readonly default

default: typeof Collection = Collection

Methods

array

  • Creates an ordered array of the values of this collection, and caches it internally. The array will only be reconstructed if an item is added to or removed from the collection, or if you change the length of the array itself. If you don't want this caching behavior, use [...collection.values()] or Array.from(collection.values()) instead.

    Returns World[]

clear

  • clear(): void
  • Returns void

clone

concat

delete

  • delete(key: number): boolean

each

  • each(fn: (value: World, key: number, collection: Map<number, World>) => any, thisArg?: any): this
  • Identical to Map.forEach(), but returns the collection instead of undefined.

    example

    collection .each(user => console.log(user.username)) .filter(user => user.bot) .each(user => console.log(user.username));

    Parameters

    • fn: (value: World, key: number, collection: Map<number, World>) => any

      Function to execute for each element

        • (value: World, key: number, collection: Map<number, World>): any
        • Parameters

          Returns any

    • Optional thisArg: any

    Returns this

equals

  • Checks if this collection shares identical key-value pairings with another. This is different to checking for equality using equal-signs, because the collections may be different objects, but contain the same data.

    Parameters

    Returns boolean

    Whether the collections have identical contents

every

  • every(fn: (value: World, key: number, collection: this) => boolean): boolean
  • Checks if all items passes a test. Identical in behavior to Array.every().

    example

    collection.every(user => !user.bot);

    Parameters

    • fn: (value: World, key: number, collection: this) => boolean

      Function used to test (should return a boolean)

        • (value: World, key: number, collection: this): boolean
        • Parameters

          • value: World
          • key: number
          • collection: this

          Returns boolean

    Returns boolean

fetch

  • fetch(number?: undefined | number): Promise<World | undefined>

filter

  • Identical to Array.filter(), but returns a Collection instead of an Array.

    example

    collection.filter(user => user.username === 'Bob');

    Parameters

    • fn: (value: World, key: number, collection: this) => boolean

      The function to test with (should return boolean)

        • (value: World, key: number, collection: this): boolean
        • Parameters

          • value: World
          • key: number
          • collection: this

          Returns boolean

    Returns Collection<number, World>

find

  • find(fn: (value: World, key: number, collection: this) => boolean): World | undefined
  • Searches for a single item where the given function returns a truthy value. This behaves like Array.find(). All collections used in Discord.js are mapped using their id property, and if you want to find by id you should use the get method. See MDN for details.

    example

    collection.find(user => user.username === 'Bob');

    Parameters

    • fn: (value: World, key: number, collection: this) => boolean

      The function to test with (should return boolean)

        • (value: World, key: number, collection: this): boolean
        • Parameters

          • value: World
          • key: number
          • collection: this

          Returns boolean

    Returns World | undefined

findKey

  • findKey(fn: (value: World, key: number, collection: this) => boolean, thisArg?: any): number | undefined
  • Searches for the key of a single item where the given function returns a truthy value. This behaves like Array.findIndex(), but returns the key rather than the positional index.

    example

    collection.findKey(user => user.username === 'Bob');

    Parameters

    • fn: (value: World, key: number, collection: this) => boolean

      The function to test with (should return boolean)

        • (value: World, key: number, collection: this): boolean
        • Parameters

          • value: World
          • key: number
          • collection: this

          Returns boolean

    • Optional thisArg: any

    Returns number | undefined

first

  • first(): World | undefined
  • first(amount: number): World[]

firstKey

  • firstKey(): number | undefined
  • firstKey(amount: number): number[]

forEach

  • forEach(callbackfn: (value: World, key: number, map: Map<number, World>) => void, thisArg?: any): void
  • Executes a provided function once per each key/value pair in the Map, in insertion order.

    Parameters

    • callbackfn: (value: World, key: number, map: Map<number, World>) => void
        • Parameters

          Returns void

    • Optional thisArg: any

    Returns void

get

  • get(number: number): World | undefined

has

  • has(key: number): boolean
  • Parameters

    • key: number

    Returns boolean

    boolean indicating whether an element with the specified key exists or not.

keyArray

  • keyArray(): number[]
  • Creates an ordered array of the keys of this collection, and caches it internally. The array will only be reconstructed if an item is added to or removed from the collection, or if you change the length of the array itself. If you don't want this caching behavior, use [...collection.keys()] or Array.from(collection.keys()) instead.

    Returns number[]

last

  • last(): World | undefined
  • last(amount: number): World[]

lastKey

  • lastKey(): number | undefined
  • lastKey(amount: number): number[]

map

  • map<T>(fn: (value: World, key: number, collection: this) => T): T[]
  • Maps each item to another value into an array. Identical in behavior to Array.map().

    example

    collection.map(user => user.tag);

    Type parameters

    • T

    Parameters

    • fn: (value: World, key: number, collection: this) => T

      Function that produces an element of the new array, taking three arguments

        • (value: World, key: number, collection: this): T
        • Parameters

          • value: World
          • key: number
          • collection: this

          Returns T

    Returns T[]

mapValues

  • mapValues<T>(fn: (value: World, key: number, collection: this) => T): Collection<number, T>
  • Maps each item to another value into a collection. Identical in behavior to Array.map().

    example

    collection.mapValues(user => user.tag);

    Type parameters

    • T

    Parameters

    • fn: (value: World, key: number, collection: this) => T

      Function that produces an element of the new collection, taking three arguments

        • (value: World, key: number, collection: this): T
        • Parameters

          • value: World
          • key: number
          • collection: this

          Returns T

    Returns Collection<number, T>

random

randomKey

  • randomKey(): number
  • randomKey(amount: number): number[]

reduce

  • reduce<T>(fn: (accumulator: any, value: World, key: number, collection: this) => T, initialValue?: T): T
  • Applies a function to produce a single value. Identical in behavior to Array.reduce().

    example

    collection.reduce((acc, guild) => acc + guild.memberCount, 0);

    Type parameters

    • T

    Parameters

    • fn: (accumulator: any, value: World, key: number, collection: this) => T

      Function used to reduce, taking four arguments; accumulator, currentValue, currentKey, and collection

        • (accumulator: any, value: World, key: number, collection: this): T
        • Parameters

          • accumulator: any
          • value: World
          • key: number
          • collection: this

          Returns T

    • Optional initialValue: T

    Returns T

set

  • set(key: number, value: World): this

some

  • some(fn: (value: World, key: number, collection: this) => boolean): boolean
  • Checks if there exists an item that passes a test. Identical in behavior to Array.some().

    example

    collection.some(user => user.discriminator === '0000');

    Parameters

    • fn: (value: World, key: number, collection: this) => boolean

      Function used to test (should return a boolean)

        • (value: World, key: number, collection: this): boolean
        • Parameters

          • value: World
          • key: number
          • collection: this

          Returns boolean

    Returns boolean

sort

  • sort(compareFunction?: (firstValue: World, secondValue: World, firstKey: number, secondKey: number) => number): this
  • The sort() method sorts the elements of a collection and returns it. The sort is not necessarily stable. The default sort order is according to string Unicode code points.

    example

    collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);

    Parameters

    • Default value compareFunction: (firstValue: World, secondValue: World, firstKey: number, secondKey: number) => number = (x, y): number =>Number(x > y) || Number(x === y) - 1
        • (firstValue: World, secondValue: World, firstKey: number, secondKey: number): number
        • Parameters

          • firstValue: World
          • secondValue: World
          • firstKey: number
          • secondKey: number

          Returns number

    Returns this

sweep

  • sweep(fn: (value: World, key: number, collection: this) => boolean): number
  • Removes entries that satisfy the provided filter function.

    Parameters

    • fn: (value: World, key: number, collection: this) => boolean

      Function used to test (should return a boolean)

        • (value: World, key: number, collection: this): boolean
        • Parameters

          • value: World
          • key: number
          • collection: this

          Returns boolean

    Returns number

    The number of removed entries

tap

  • tap(fn: (collection: this) => any): this
  • Runs a function on the collection and returns the collection.

    example

    collection .tap(coll => console.log(coll.size)) .filter(user => user.bot) .tap(coll => console.log(coll.size))

    Parameters

    • fn: (collection: this) => any

      Function to execute

        • (collection: this): any
        • Parameters

          • collection: this

          Returns any

    Returns this