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

wbn

v0.0.9

Published

Generator and parser for the application/webbundle format, defined in draft-ietf-wpack-bundled-responses-01.

Downloads

1,357

Readme

Web Bundles

This is a Node.js module for serializing and parsing the application/webbundle format defined in the Web Bundles draft spec.

Installation

Using npm:

npm install wbn

Usage

Please be aware that the API is not yet stable and is subject to change any time.

Creating a Bundle:

import * as fs from 'fs';
import * as wbn from 'wbn';

const builder = new wbn.BundleBuilder();
builder.addExchange(
  'https://example.com/', // URL
  200, // response code
  { 'Content-Type': 'text/html' }, // response headers
  '<html>Hello, Web Bundle!</html>' // response body (string or Uint8Array)
);
builder.setPrimaryURL('https://example.com/'); // entry point URL

fs.writeFileSync('out.wbn', builder.createBundle());

Reading a Bundle:

import * as fs from 'fs';
import * as wbn from 'wbn';

const buf = fs.readFileSync('out.wbn');
const bundle = new wbn.Bundle(buf);
const exchanges = [];
for (const url of bundle.urls) {
  const resp = bundle.getResponse(url);
  exchanges.push({
    url,
    status: resp.status,
    headers: resp.headers,
    body: new TextDecoder('utf-8').decode(resp.body),
  });
}
console.log(
  JSON.stringify(
    {
      version: bundle.version, // format version
      exchanges,
    },
    null,
    2
  )
);

CLI

This package also includes wbn command which lets you build a web bundle from a local directory. For example, if you have all the necessary files for https://example.com/ in static/ directory, run the following command:

$ wbn --dir static \
      --baseURL https://example.com/ \
      --output out.wbn

Run wbn --help for full options.

Note: currently this CLI only covers a subset of the functionality offered by gen-bundle Go tool.

Backwards compatibility

This module supports creating and parsing Web Bundles that follow different draft versions of the format specification. In particular:

To create a new bundle with the b1 format, pass the version value to the constructor:

const builder = (new wbn.BundleBuilder('b1'))
  .setPrimaryURL('https://example.com/')
  .setManifestURL('https://example.com/manifest.json')
  .addExchange(...);

fs.writeFileSync('out_b1.wbn', builder.createBundle());

Likewise, the wbn command can optionally take a --formatVersion b1 parameter when creating a new Web Bundle.

This module also takes care of selecting the right format version automatically when reading a bundle. Check the property bundle.version to know the decoded bundle's format version.

Using Bundles

Generated bundles can be opened with web browsers supporting web bundles.

Chrome (79+) experimentally supports navigation to Web Bundles with some limitations. See this document for more details.

Chrome (104+) supports <script type=webbundle>.

Release Notes

0.0.9

  • Add support for overriding headers.

0.0.8

  • Now wbn package provides both ES modules and CommonJS exports.
  • Dependency on the Node.js API has been removed from the wbn module, making it easier to use the module in browsers.

0.0.7

  • Now BundleBuilder accepts relative resource URLs. Relative URLs can be used in <script type=webbundle> where relative URLs are resolved using the bundle's URL as base URL.

0.0.6