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

scatter-js

v2.5.2

Published

This is an importable javascript library that allows web applications to directly interface with Scatter Desktop.

Downloads

13

Readme

Scatter JS

This is an importable javascript library that allows web applications to directly interface with Scatter Desktop.

Installation

// ES Module style
import ScatterJS from 'scatter-js/dist/scatter.esm';

// CommonJS style
import ScatterJS from 'scatter-js/dist/scatter.cjs';
 
//or
 
const ScatterJS = require('scatter-js/dist/scatter.<SUFFIX>');

You can also just drop the scatter.min.js bundle from the dist/ directory here right into your html file and use it as a fully packed browser-ready package.

<script src="path/to/scatter.min.js"></script>

CDN:

Coming soon.

ScatterJS Usage

This library catches both Scatter Desktop and Scatter Classic ( old extension ) depending on the existence of either.

Making a connection

ScatterJS.scatter.connect("Put_Your_App_Name_Here").then(connected => {
    if(!connected) {
        // User does not have Scatter Desktop or Classic installed. 
        return false;
    }
    
    // Use `scatter` normally now.
    ScatterJS.scatter.getIdentity(...);
});

Connection Options

{
    // You may specify a maximum timeout for checking if a user has Scatter installed
    initTimeout:10000,
}

Don't forget to null out the window.scatter reference!

scatter-js binds to the window reference if it notices that an application has a window on global scope. This is useful for <script src="..."> imports for sites without nodejs/npm, but is also semi-dangerous.

If you don't null out the window reference then extensions will be able to catch it on the window's scope and pretend to send requests from your authorized application.

The best practice is to offload the scatter reference to your own global/state variable and nullify the window ref.

setStateVariable(window.scatter);
 
window.scatter = null;

Offloading the scatter object to state from nodejs/es/cjs

A lot of projects already integrated with Scatter expect scatter to be it's own object. You can easily mimic that by offloading the ScatterJS.scatter object to your previously saved state variables.

( The reason this ScatterJS wrapper/holder exists is because if the extension is found it needs to overwrite the .scatter object without losing the reference passed down the tree to your app. )

const scatter = ScatterJS.scatter;
 
// or state savers ( store ) such as redux or vuex 
setStateVariable(ScatterJS.scatter);

Scatter ( eosjs / web3 ) Usage

See the Developer Documentation to find out how to interact with Scatter and various blockchains.

Scatter sits on top of eosjs or web3, so learn to use those depending on which blockchain you are interfacing with.

Switching from Extension only to Extension+Desktop support.

Replace

document.addEventListener('scatterLoaded', () => {
    this.scatter = window.scatter;
    window.scatter = null;
});

With ( for nodejs )

import ScatterJS from 'scatter-js/dist/scatter.esm';

ScatterJS.scatter.connect('YOUR_APP_NAME').then(connected => {
    if(connected){
        this.scatter = ScatterJS.scatter;
        window.scatter = null;
    }
});

Or ( for html/js )

<script src="path/to/scatter.min.js"></script>

scatter.connect('YOUR_APP_NAME').then(connected => {
    if(connected){
        this.scatter = scatter;
        window.scatter = null;
    }
});