Class: Queue

Queue

new Queue(arropt)

Create a queue of playlist entries.

Parameters:
Name Type Attributes Description
arr Array <optional>

An array of playlist entries.

Source:

Members

queue

Array of entries.

Source:

Methods

add(entry)

Add an entry to the end of the queue.

Parameters:
Name Type Description
entry Track | Album | Artist

The entry to add.

Source:

alternate(fn) → {Queue}

Group entries and interleave them.

Parameters:
Name Type Description
fn function

A grouping function. Takes an entry as input and returns a grouping key, a string, as output.

Source:
Returns:
  • Itself.
Type
Queue

concat(queue) → {Queue}

Concatenate with another queue.

Parameters:
Name Type Description
queue Queue

Another queue to append to this queue.

Source:
Returns:
  • A new queue containing all the entries from this queue followed by all the entries from the other queue.
Type
Queue

contains(entry) → {boolean}

Whether the queue contains an entry.

Parameters:
Name Type Description
entry Track | Album | Artist

The entry to check for.

Source:
Returns:
  • true if the queue contains entry, false otherwise.
Type
boolean

dedup() → {Promise|Queue}

Remove duplicate entries. If a track occurs more than once, the version with the highest Spotify popularity is preferred.

Source:
Returns:
  • Itself.
Type
Promise | Queue

dispatch() → {Promise|Queue}

Dispatch all entries in sequence. Ensure that only one entry is dispatched at a time.

Source:
Returns:

A queue of results.

Type
Promise | Queue

filter(fn) → {Queue}

Filter the queue by a predicate.

Parameters:
Name Type Description
fn function

A predicate function. Takes the current entry as input and returns true if it passes the test, false otherwise.

Source:
Returns:
  • A new queue.
Type
Queue

flatten() → {Queue}

Transform a nested queue into a flat queue. [1, [2, [3, [4]], 5]] => [1, 2, 3, 4, 5].

Source:
Returns:
  • Itself.
Type
Queue

forEach(fn) → {Queue}

Iterate over the queue.

Parameters:
Name Type Description
fn function

An iterator function. Takes the current entry as input and returns the modified value as output.

Source:
Returns:
  • Itself.
Type
Queue

forEachPromise(fn) → {Promise|Queue}

Similar to Queue.forEach(), but with promises. Each iteration must return a promise (e.g., by invoking a promise-returning method).

The execution is strictly sequential to prevent overloading the server. (If parallel execution is needed, use a library function like Promise.all() instead.)

Parameters:
Name Type Description
fn function

An iterator function. Takes an entry as input and returns a promise.

Source:
Returns:

A promise that invokes each promise in sequence. The promise's value is a queue of the values of each invoked promise.

Type
Promise | Queue

get(idx)

Get a playlist entry.

Parameters:
Name Type Description
idx integer

The index of the entry. The indices start at 0.

Source:

group(fn) → {Queue}

Group entries.

Parameters:
Name Type Description
fn function

A grouping function. Takes an entry as input and returns a grouping key, a string, as output.

Source:
Returns:
  • Itself.
Type
Queue

groupBy(fn) → {Queue}

Group entries.

Parameters:
Name Type Description
fn function

A grouping function. Takes an entry as input and returns a grouping key, a string, as output.

Source:
Returns:
  • Itself.
Type
Queue

indexOf(obj)

Get the index of an entry.

Parameters:
Name Type Description
obj Object

The entry to find.

Source:
Returns:

The index of obj, or -1 if not found. The indices start at 0.

interleave() → {Queue}

Interleave a nested queue into a flat queue.

Source:
Returns:
  • Itself.
Type
Queue

isEmpty() → {boolean}

Whether the playlist is empty.

Source:
Returns:
  • true if empty, false otherwise.
Type
boolean

map(fn) → {Queue}

Map a function over the queue.

Parameters:
Name Type Description
fn function

An iterator function. Takes the current entry as input and returns the modified value as output.

Source:
Returns:
  • A new queue.
Type
Queue

orderByLastfm() → {Queue}

Order the playlist entries by Last.fm playcount.

Source:
Returns:
  • Itself.
Type
Queue

orderByPopularity() → {Queue}

Order the playlist entries by Spotify popularity.

Source:
Returns:
  • Itself.
Type
Queue

reverse() → {Queue}

Reverse the order of the queue.

Source:
Returns:
  • Itself.
Type
Queue

set(idx, entry)

Set a playlist entry.

Parameters:
Name Type Description
idx integer

The index of the entry. The indices start at 0. If out of bounds, the entry is added at the end.

entry Object

The entry to add.

Source:

shift() → {Object}

Remove the first element from the queue.

Source:
Returns:
  • The first element, or undefined if the queue is empty.
Type
Object

shuffle() → {Queue}

Shuffle the elements in the queue. Uses the Fisher-Yates algorithm.

Source:
Returns:
  • Itself.
Type
Queue

size() → {integer}

The playlist size.

Source:
Returns:
  • The number of entries.
Type
integer

slice(start, end) → {Queue}

Slice a queue.

Parameters:
Name Type Description
start integer

The index of the first element.

end integer

The index of the last element (not included).

Source:
Returns:
  • A new queue containing all elements from start (inclusive) to end (exclusive).
Type
Queue

sort(fn) → {Queue}

Sort the queue.

Parameters:
Name Type Description
fn function

A sorting function. Takes two entries as input and returns -1 if the first entry is less than the second, 1 if the first entry is greater than the second, and 0 if the entries are equal.

Source:
Returns:
  • Itself.
Type
Queue

toArray() → {Array}

Convert queue to array.

Source:
Returns:

An array of playlist entries.

Type
Array