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 🙏

© 2025 – Pkg Stats / Ryan Hefner

storage-socket

v1.0.4

Published

Communication socket between browser tabs using LocalStorage

Readme

storage-socket

Communication socket between browser tabs using LocalStorage.

NB : Sharing tabs must share the same origin and protocol.

Compatible js & ts

install :

npm install storage-socket

Import

js

const {StorageSocket} = require('storage-socket');

ts

import {StorageSocket} from "storage-socket";

Use


const myGroup='group 1';//

const socket = new StorageSocket(myGroup);

API

StorageSocket

class StorageSocket{
	/**
	* 
	* @param {string} group clients shared group.
	* Use different group names for separated information channels.
	*/
	constructor(group){/*...*/}

	/**
	* readonly {int} current instance id
	*/
	id

	/**
	* readonly {number[]} all id list
	*/
	clients

	/**
	* readonly {number[]} peers id list (clients excluding current instance)
	*/
	peers

	/**
	* readonly {boolean} Ready state
	*/
	ready

	/**
	* Socket events listening
	* @param {'ready'|'close'|'enter'|'leave'|'message'|'question'} type 
	* callback trigger types :
	* ready : When the socket is ready
	* close : When the socket closes
	* enter : When a peer enters.
	* leave : When a peer leaves.
	* message : When a peer used 'send(yourId|"all",data)'.
	* question : When a peer used 'ask(yourId|"all",data)'.
	* @param {function(message: StorageMessage|any): void }} callback
	*/
	on(type,callback){/*...*/}

	/**
	* sends a "message" event
	* @param {number|"all"} id : target peer id ( ts must use sendAll(data) instead of send("all",data) )
	* @param {any} data 
	*/
	send(id,data){/*...*/}

	/**
	* sends a "question" event 
	* @param {number|"all"} id : target peer id ( ts must use askAll(data) instead of ask("all",data) )
	* @param {any} data 
	* @return Promise<any> : resolved when the question is answered ( using message.send(reponse) )
	*/
	ask(id,data){/*...*/}
	
	/**
	* sends to all peers
	* @param {any} data 
	*/
	sendAll(data){/*...*/}

	/**
	* asks to all peers
	* @param {any} data 
	* @return Array<Promise<any>>
	*/
	askAll(data){/*...*/}
}

StorageMessage


	class StorageMessage extends MessageData{
		/**
		* {'ready'|'close'|'enter'|'leave'|'message'|'question'} the message type
		*/
		type:string;
		/**
		* {number} the sender id
		*/
		from:number;
		/**
		* {number} the target id
		*/
		to:number;
		/**
		* {any} the sent data
		*/
		data:any;

		/**
		* sends a message to the sender
		* @param {any} data 
		*/
		send(data){/*...*/}

		/**
		* asks question to the sender. Does not work if message.type = 'question'.
		* @param {any} data 
		* @return Promise<any> : resolved when the question is answered ( using message.send(reponse) )
		*/
		ask(data){/*...*/}

	}

Test

open several tabs containig this script :

js

const {test_storage_socket} = require('storage-socket');
test_storage_socket();

ts

import {test_storage_socket} from "storage-socket";
test_storage_socket();

Exemple :

	let socket=new StorageSocket('ys2');
	console.log('peers',socket.peers);
	socket.on('message',msg=>{
		console.log('on msg !!',msg);
	});
	socket.on('enter',msg=>{
		console.log('on enter',msg);
	});
	socket.on('leave',msg=>{
		console.log('on leave',msg);
	});
	socket.on('question',msg=>{
		console.log('on question asked ',msg);
		if(msg.data.txt==='OO R U ?'){
			msg.send({txt:'i am '+document.location.href});
		}
		
	});
	
	setTimeout(() => { 
		socket.send('all','hello!'+Math.random());
	}, 1000);
	setTimeout(() => { 
		
		console.log('ss2 ask');
		socket.askAll({txt:'OO R U ?'})
		.map(p=>{
			p.then(r=>{
				console.log('reponse',r);
			});
		});
	}, 3000);