npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

playback-queue

v1.0.0

Published

A node module for creating and operating on a playback queue. Includes history, shuffling, and repetition.

Downloads

6

Readme

playback-queue

A node module for creating and operating on a music playback queue. Includes history, shuffling, and repeating.

Usage

npm install --save playback-queue

  import PlaybackQueue from 'playback-queue'

  const options = {};
  const queue = new PlaybackQueue(options);

Options

  • tracks: An array of tracks (or any other object you want in the queue). These will be the objects processed and returned by the queue.
    • type: array
    • default: []
  • shuffle: A flag indicating whether or not playback (and returned tracks) should be randomly shuffled.
    • type: boolean
    • default: false
  • repeat: A string indicating how playback should be repeated.
    • type: string
    • values: ['playlist', 'track', 'none']
    • default: 'playlist'

API

PlaybackQueue, once instantiated, exposes a handful of methods with which to operate on the queue and retrieve objects. Any methods not intended for outside use are prefixed with an underscore (_).

Methods

setTracks(tracks)

Manually sets the playlist of tracks in the queue, then resets all states (except shuffle and repeat) and selects the first track.

nextTrack()

Selects and returns the next track to be played, based on current repeat and shuffle states. Updates state and queues accordingly.

previousTrack()

Selects and returns the previous track played based on play history. Returns previous song in current playlist if no history. Updates state and queues accordingly.

selectTrack(track)

Manually selects the given track, updating state and queues accordingly. Note: Throws an error if provided track is not in current playlist.

toggleShuffle()

Toggles the shuffle state between shuffled and not shuffled.

toggleRepeat()

Toggles the shuffle state between 'playlist', 'track', and 'none'.

sortTracks(attr, asc)

Sorts the current playlist by the provided attribute (key). Also takes an asc parameter, specifying whether the sort should be ascending or not. Defaults to true.

Properties

  • queuePool
  • currentTrack
  • currentIndex
  • isShuffled
  • repeatState
  • shufflePool
  • shuffleIndex
  • playHistory
  • historyIndex

Running tests

  1. git clone https://github.com/jakemmarsh/playback-queue.git
  2. cd playback-queue
  3. npm install
  4. npm test (or npm run test-watch to continuously run on file change)