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 🙏

© 2026 – Pkg Stats / Ryan Hefner

buff.js

v2.0.13

Published

Translate ArrayBuffers to strings and vice versa in JavaScript.

Readme

Buff.js

Translate ArrayBuffers to strings and vice versa in JavaScript. This library is mainly useful for sending WebSocket messages as Binary packets.

Browser

Insert the script tag into your markup:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/buff.min.js"></script>

Usage in the browser:

// Load the module
const Buff = require("buff.js");

// Translates the string "test" info an ArrayBuffer.
const buffer = Buff.Write("test"); 

// Translates the ArrayBuffer back into the string "test".
const string = Buff.Read(buffer); 

console.log(string, ' <--> ', buffer);
console.log('# Buffer.js works!');

Node.JS

Install with the command:

npm i buff.js

Usage in Node.js:

// Load the module
const Buff = require("buff.js");

// Translates the string "test" info an ArrayBuffer.
const buffer = Buff.Write("test"); 

// Translates the ArrayBuffer back into the string "test".
const string = Buff.Read(buffer); 

console.log(string, ' <--> ', buffer);
console.log('# Buffer.js works!');

WebSockets Example

Client example:


// Setup the lib for the websocket server.
const Buff = require("buff.js");

let socket = new Object();

socket.setup = function(url) {
  let _this = this;
  setInterval(function(){
    if (!_this.ws || _this.ws.readyState === 3) {
      socket.connect(url);
    }
  },5000);
  socket.connect(url);
};

socket.connect = function(url) {
  let _this = this;
  console.log('[SOCKET]','Connecting to gateway...');
  try {

    // Create new websocket connection

    _this.ws = new WebSocket(url);

    // Set binary type so we can send ArrayBuffers

    _this.ws.binaryType = 'arraybuffer';
    _this.ws.callbacks = new Object();

    // Handler for when the client establishes a successful connection with the server.

    _this.ws.onopen = function() {
      console.log('[SOCKET]','Secure connection established!');
    };

    // Handler for recieving and processing messages from the server.

    _this.ws.onmessage = function(event) {

      // Convert the view of the ArrayBuffer into the raw data.

      const message = JSON.parse(Buff.Read(event.data));
      console.log('[SOCKET]','Received',message);

    };

    // Handler for when the client looses connection to the server.

    _this.ws.onclose = function() {
      console.log('[SOCKET]','Connection lost, retrying...');
    };

  } catch(error) {
    console.log('[SOCKET]','Connection lost, retrying...');
  }
};

socket.send = function(message) {
  let _this = this;
  if (!message) return;
  if (!_this.ws || _this.ws.readyState === 3) {
    console.log('[SOCKET]','Queuing request...');
    setTimeout(function(){
      socket.send(message);
    },5000);
    return;
  }

  // Convert message into binary data (array).

  if (typeof message === 'object') message = JSON.stringify(message);
  if (typeof message === 'function') return;

  console.log('[SOCKET]','Sent',message);

  _this.ws.send(Buff.Write(message));
};

socket.connect('ws://127.0.0.1:8080');

Server example:


const WebSocket = require('ws');
const Buff = require('buff.js');
const path = require('path');
const fs = require('fs');

const wss = new WebSocket.Server({
  port: 8080
});

let helpers = {
  random: function(length) {
    let text = '',
      possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    for (let i = 0; i < (length || 10); i++)
      text += possible.charAt(Math.floor(Math.random()*possible.length));
    return text;
  }
};

wss.on('connection',function(socket){
  socket.on('message',function(data){

    // Convert back to raw data.

    const message = Buff.Read(data);

    // Echo the message back to the sender and compare the raw data and ArrayBuffer.

    socket.send(data);
    console.log('"'+message+'"',' <--> ',data);

  });
});