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

@elsassph/fast-source-map

v0.3.0

Published

fast source mapping decode/encode

Downloads

413

Readme

Fast Source Map Build Status

Keeping the JIT gods happy since circa 2015

When working with sourcemaps, VLQ encoding and decoding typically dominiates cost. To address this, this library provides a Fast VLQ encoder & decoder for JavaScript. By reducing allocations, minimizing transformations, and writing JIT friendly code we are able to drammatically improve performance.

How much faster? At the time this README was written, decoding scala.js.map took:

v8: 4.6.85.28
node: 5.0.0
os: 10.10.3
hw: 2.5 GHz Intel Core i7, 16gb
  • source-map: ~5,000ms
  • fast-source-map ~ 500ms

Usage

First we will need to have our sourceMap.mappings stored as a buffer. We have future plans to work directly on a sourceMap buffer, as that will allow for more ideal performance. Even without, the performance improvements are still well worth it.

var buffer = /* try to leave the map inert, and in buffer form. Otherwise convert to buffer */

Typically, the following steps are required:

Setup the reader

The reader can read mappings from any array of ascii values. We will use Uint8Array in this example.

let map = JSON.parse(fs.readFileSync('path/to/source/to/decode.js.map', 'utf8'));

let byteArray = new Uint8Array(map.mappings.length);
let buffer = Buffer.from(byteArray.buffer);
buffer.write(map.mappings, 0, 'ascii');

const SM = require("fast-source-map");
let reader = new SM.IntBufferReader(byteArray, 0, byteArray.length);

Setup the decoder

let decoder = new SM.Decoder();
let mappingsDecoder = new SM.MappingsDecoder(decoder);

Now for some actual decoding

mappingsDecoder.decode(reader);
decoder.mappings // => is the quickly decoded

To concatenate multiple source maps

const decodeFile = SM.decodeFile;

let concatenator = new SM.SourceMapConcatenator();
concatenator.push(decodeFile('path/to/file-1.js.map'));
concatenator.push(decodeFile('path/to/file-2.js.map'));
concatenator.push(decodeFile('path/to/file-3.js.map'));

concatenator.toJSON(); // => the concatenated source maps

Now to reconcatenate the source maps after a source file is removed.

// file-2.js.map is removed
concatenator.splice(1, 1);
concatenator.toJSON(); // => the concatenated source maps

And reconcatenate again after adding back other files.

// an updated file 2 and a new file 4 are added
concatenator.splice(1, 0, decodeFile('path/to/file-2-updated.js.map'));
concatenator.push(decodeFile('path/to/file-4.js.map'));
concatenator.toJSON(); // => the concatenated source maps