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

tesselate

v0.0.2

Published

Easily load tessel modules — without .ready()

Downloads

20

Readme

tesselate

Easy tessel module loading

tesselate is a dependency injector for tessel modules, abstracting away the need to nest multiple ‘ready’ listeners and callbacks within each other, or use promises or generators (or multiple, internal loaded flags).

tesselate requires ‘tessel’ for you so you don’t have to. Your code exists as a callback to the the invocation of the tesselate function. Obviously, you must have globally npm installed tessel.

Features

  • Ensures that all modules are loaded before your code runs
  • Small library footprint size — only 11kb once packaged
  • Shortcut sytax allows you to just list the modules you want in an array
  • Has no external dependencies
  • Development flag useful for debugging

Quickstart

Require tesselate and invoke it, passing in a config object and your code, as a callback.

// Load and immediately run tesselate module
require(‘tesselate’)({
  modules: {
    A: [‘accel-mma84’, ‘accel’], // load accelerometer module, aliased as ‘accel’ on port A
    B: [‘ir-attx4’, ‘ir’]        // load IR module, aliased as ‘ir’ on port B
  },
  development: true              // enable development logging, useful for debugging
}, function(tessel, m){

  // returns tessel to you as 'tessel'

  // returns your modules to you as properties of object m
  // refer to the IR module as m.ir, or the accelerometer module as m.accel

  //your code here
});

Shortcut syntax

Instead of a config object, just pass in an array with the names of the npm modules of the modules you want, ordered by port. So for ports A, B, C and D, pass in [moduleA, moduleB, moduleC, moduleD], respectively.

/* if accel and ble were plugged into ports A and B, respectively... */
require('tesselate')(['accel-mma84', 'ble-ble113a'], function(tessel, m) {
  //refer to each module by its prefix
  //i.e., refer to accel module as m.accel, or ble module as m.ble
  //your code here
});

Shortcut syntax supported modules

module name | given alias
----------- | ------------
ble-ble113a | ble
accel-mma84 | accel
ambient-attx4 | ambient
audio-vs1053b | audio
camera-vc0706 | camera
climate-si7005 | climate
climate-si7020 | climate
gprs-sim900 | gprs
gps-a2235h | gps
ir-attx4 | infrared
sdcard | sdcard
rf-nrf24 | nrf
relay-mono | relay
rfid-pn532 | rfid
servo-pca9685 | servo

For newbies

  • In your terminal / command line
    • Navigate to your project folder
    • Make sure you've installed tessel (sudo npm install -g tessel)
    • Run npm init (hit enter for all options if you're lazy)
    • npm install the tessel modules that your code uses (npm install --save <>)
    • npm install the tesselate module (npm install tesselate --save)
  • In your main .js file
    • Require and use the tesselate module using the quickstart format above or getting-fancy format below
    • Hardware hack yourself to heaven :)

Details

The tesselate module returns a function that should be invoked once, with the signature: tesselate(optionsObject, yourCode)

The optionsObject should be an object literal of the form:

{
  modules: {
    /* capitalised Name of port: ['name of required tessel npm module', 'name you'd like to use to refer to the module'] */
    A: [‘accel-mma84’, ‘accel’], 
    B: [‘ir-attx4’, ‘ir’],
  },
  
  development: true // Optional. True by default. Set to false to deactivate debugging logs

}

yourCode is an anonymous function that is passed m, an object with your modules loaded as properties with the names you gave them and the 'tessel' module, which was required for you. It is invoked for you as soon as all modules report that they're ready. If you require other modules before requiring and calling tesselate, they will be available to you in the callback function as well, as they are preserved in the callback's closure scope.

tesselate(optionsObject, function(tessel, m){
  //your code here, referring to tessel as tessel and your modules as m.yourGivenModuleName
});

Known possible improvements

  • Use ES6 generators to remove the need for a callback
    • Tessel runtime does not have generators built in

Refused 'improvements'

  • Catching module loading errors inside the loader, passing to callback
    • You probably want to know if your module fails to load, and not hush it up.