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

@turbowarp/mist

v0.0.2

Published

API for interacting with TurboWarp cloud variables

Downloads

69

Readme

Mist

A barebones library for interacting with cloud variable servers.

What Mist will do for you:

  • A simple event-driven API
  • Automatic reconnection if the server restarts
  • Strict input validation to detect bad code early
  • Forces you to provide a valid User-Agent (if used in Node.js)

What Mist won't do for you:

  • Encode or decode strings/lists/etc. as numbers. We just provide the means to talk to talk to cloud variables. You have to provide encoding and decoding on your own.
  • Authentication, for example to connect to clouddata.scratch.mit.edu.
  • Interacting with any other API. It's just cloud variables.
  • A lot of customization options. We're trying to keep it simple. Mist is small enough and has few enough dependencies that forking it to meet your needs shouldn't be that hard.
  • Rate limiting. Be reasonable, okay?

You are expected to read https://docs.turbowarp.org/cloud-variables#advanced before using Mist.

Usage in Node.js

Install:

npm install @turbowarp/mist

Simple usage:

const Mist = require('@turbowarp/mist');

const connection = new Mist({
    // Can be any text, not just numbers
    projectId: '',

    // You must add your contact information here; see https://docs.turbowarp.org/cloud-variables#user-agent
    userAgent: '',

    // You can also send a username if you want but we recommend just using the default which is guaranteed
    // to always work.
    // username: 'player2345',

    // You can specify a different cloud host here:
    // cloudHost: 'wss://clouddata.turbowarp.org',
});

connection.on('connected', () => {
    // Event is fired each time a connection is successfully opened
    // Note that at this point **no variables have any values yet**
    console.log('Connected!');
});

connection.on('reconnecting', () => {
    // Event is fired each time a connection is lost (server restart, internet outage, etc.)
    console.log('Connection lost, trying to reconnect...');
});

connection.on('set', (name, value) => {
    // Event is fired each time a value is received for a variable
    console.log(name, 'was set to', value);
});

connection.on('error', (error) => {
    // Event is fired when there is an unrecoverable error. At this point the connection
    // is permanently terminated and will not automatically reconnect. Examples include
    // an invalid username or invalid User-Agent but do not include a server restart
    // (as that will trigger the reconnection logic instead).
    console.error(error);
});

const interval = setInterval(() => {
    // Instead of event-driven APIs, you can also use get() which returns the most recently
    // received or set value of a given variable. If you don't include "☁ " then we will add
    // it for you. Unknown variables return `undefined`.
    const value = connection.get('my variable') || 0;

    if (value >= 30) {
        // close() will immediately end the connection. No events will be fired.
        connection.close();
        console.log('Closing!');
        clearInterval(interval);
    } else {
        // Update a variable by calling set() anywhere. Like get(), if you don't include "☁ "
        // then we will add it for you. If called before the connection is opened, it will be
        // saved in a queue to be sent when the connection opens.
        connection.set('my variable', value + 1);
        console.log('☁ my variable is being set to', connection.get('☁ my variable'));
    }
}, 1000);

Usage in browsers

It should work if you use a build tool like webpack. Only difference is that the User-Agent is not required (and is in fact ignored). Standalone script tag version to come eventually.

License

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.