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

go-dice-api

v0.4.0

Published

This package is a work in progress. Trying to wrap the API to support TypeScript and a nicer API interface.

Downloads

4

Readme

GoDice JavaScript API Wrapper

This package is a work in progress. Trying to wrap the API to support TypeScript and a nicer API interface.

Due to licensing reasons... this package doesn't actually contain the API, and must be downloaded from the official repo: https://github.com/ParticulaCode/GoDiceJavaScriptAPI

Overview:

This supports the following features of the GoDice API:

  • Connecting to dice
  • Reading the value of the dice
  • Setting LED colors
  • Getting the battery level
  • Getting the colour of the die
  • React hooks (via go-dice-react)

Future features:

  • Hex support for LEDs
  • Self implemented API
  • RPG Dice Shell support

Support

Requires the Bluetooth Browser APIs, which are only available in Chrome and Chromium based browsers at time of writing.

Check MDN's browser support page for up-to-date info

Install

# install from NPM
npm install go-dice-api

# or with yarn if that's your cup-o-tea:
yarn add go-dice-api

Add the Official API to the page


<head>
    <script src="/path/to/godice.js"></script>

    <!-- Export the API so the module file can find it -->
    <script>window.GoDice = GoDice</script>

    <script src="/path/to/bundle.js"></script>
</head>

Usage

import { diceSet, Die, LED_OFF } from 'go-dice-api'

// Ask the user to connect a die
diceSet.requestDie()

diceSet.on('connected', (die: Die) => {
  // a die was connected!

  // Set the colour of the leds
  die.setLed([0, 0, 255]) // [Red, Green, Blue]
  die.setLed([0, 0, 255], [255, 0, 0]) // Set the two lights separately 
  die.setLed(LED_OFF)

  // Listen for the user to start rolling the dice
  die.on('rollStart', () => console.log("Rolling..."))

  // And then get the value they rolled
  die.on('value', (value: number) => console.log(`You rolled a ${value}`))

  // Actively request the battery level
  die.getBatteryLevel().then((level: number) => console.log(level))

  // Passively listen for the battery level
  die.on('batteryLevel', (level: number) => console.log(`Battery: ${level}%`)) // level: 0-100

  // Request the colour of the Die
  die.getColour().then((color: string) => console.log(color))
})