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

braid-shelf

v0.0.3

Published

Library for collaborative json over http using braid.

Downloads

22

Readme

braid-shelf

Collaborative JSON over Braid-HTTP

This library provides a simple HTTP route handler, along with client code, enabling fast JSON synchronization over a standard protocol.

Demo

This will run a server with a collaboratively-editable JSON editor:

npm install
node server.js

Now open these URLs in your browser:

  • http://localhost:19999/demo?editor (to edit JSON collaboratively)
  • http://localhost:19999/any-other-path?editor (to create a new resource)

General Use on Server

Install it in your project:

npm install braid-shelf

Import the request handler into your code, and use it to handle HTTP requests wherever you want:

var braid_shelf = require("braid-shelf")

http_server.on("request", (req, res) => {
  // Your server logic...

  // Whenever desired, serve braid shelf for this request/response:
  braid_shelf.serve(req, res)
})

Server API

braid_shelf.db_folder = './braid_shelf_db' // <-- this is the default

  • This is where the shelf history files will be stored for each resource.
  • This folder will be created if it doesn't exist.
  • The files for a resource will all be prefixed with a url-encoding of key within this folder.

braid_shelf.serve(req, res, options)

  • req: Incoming HTTP request object.
  • res: Outgoing HTTP response object.
  • options: An object containing additional options:
    • key: ID of JSON resource to sync with. Defaults to req.url.
  • Handles Braid-HTTP GET, PUT, and DELETE requests for a specific JSON resource.

await braid_shelf.get(key)

  • key: ID of JSON resource.
  • Returns the shelf [data, version] tuple, or undefined if it doesn't exist.

await braid_shelf.get(key, options)

  • key: ID of JSON resource.
  • options: An object containing additional options:
    • subscribe: cb: Subscribes to the state, and calls cb with the initial state and each update. The function cb will be called with {version, body}.
    • peer: Unique string ID that identifies the peer making the subscription. Mutations will not be echoed back to the same peer that PUTs them.

await braid_shelf.put(key, options)

  • key: ID of JSON resource.
  • options: An object containing:
    • version: The version being PUT, as an array of strings.
    • body: The JSON body as a string.
    • peer: Identifies this peer. This mutation will not be echoed back to subscriptions with the same peer.

await braid_shelf.delete(key)

  • key: ID of JSON resource.
  • Deletes the resource and its persistence files.

await braid_shelf.list()

  • Returns an array of all existing resource keys.

General Use on Client

<script src="https://unpkg.com/braid-http@~1.3/braid-http-client.js"></script>
<script src="https://unpkg.com/shelf-merge"></script>
<script>

let shelf = [null, 0]
let peer = Math.random().toString(36).substr(2)

// Subscribe to updates
braid_fetch('/my-resource', {
    subscribe: true,
    retry: true,
    peer,
}).then((res) => {
    res.subscribe((update) => {
        shelf_merge(shelf, [JSON.parse(update.body_text), JSON.parse(update.version[0])])
        console.log('Current data:', shelf[0])
    })
})

// Send an update
function put(new_data) {
    let change = shelf_merge(shelf, new_data)
    if (change) braid_fetch('/my-resource', {
        method: 'PUT',
        peer,
        version: [JSON.stringify(change[1])],
        body: JSON.stringify(change[0])
    })
}

</script>

See editor.html for a working example.