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

@microscope-js/utils

v0.1.5

Published

Shared helpers for microscope-js: source normalization, MIME sniffing, HTML sanitization, zip-safety

Readme

@microscope-js/utils

npm Bundle Types Provenance

Shared low-level helpers for microscope-js: source normalization, MIME sniffing, hardened DOMPurify, zip-slip / zip-bomb defenses, DOM micro-helpers. If you find yourself writing the same helper in two renderers, add it here instead.

Install

pnpm add @microscope-js/utils

End-user apps usually get this transitively via @microscope-js/core — install it directly only when authoring a custom renderer.

What's in the box

Source normalization

import { normalizeSource, readAll, readHead, extOf, assertMaxSize } from '@microscope-js/utils';

const norm = await normalizeSource(file);   // -> { blob, mime, name, url }
const bytes = await readAll(norm.blob);      // Uint8Array
const head = await readHead(norm.blob, 32);  // first 32 bytes
assertMaxSize(norm.blob, 256 * 1024 * 1024); // throws MicroscopeError('TOO_LARGE')
const ext = extOf('Report.PDF');             // -> 'pdf'

MIME sniffing

import { sniffMime, sniffMimeFromBytes, mimeMatches } from '@microscope-js/utils';

await sniffMime(blob);                         // -> 'application/pdf' | null
sniffMimeFromBytes(new Uint8Array([0x25, 0x50, 0x44, 0x46])); // -> 'application/pdf'
mimeMatches('image/png', 'image/*');           // -> true

Hardened HTML sanitization

DOMPurify wrapped with a profile that forbids script, iframe, object, embed, form, meta, link, every on* attribute, and data: URIs except for safe image types.

import { sanitizeHtml, sanitizeToFragment } from '@microscope-js/utils';

container.innerHTML = sanitizeHtml(maybeEvilHtml);
container.appendChild(sanitizeToFragment(maybeEvilHtml));

Browser-only. Throws if imported in an SSR context.

Zip-slip + zip-bomb defenses

import { assertSafeZipEntry, ByteBudget } from '@microscope-js/utils';

const budget = new ByteBudget(512 * 1024 * 1024); // 512 MB uncompressed cap

for (const [path, entry] of Object.entries(zip.files)) {
  assertSafeZipEntry(path);          // rejects `..` segments + absolute paths
  const xml = await entry.async('string');
  budget.consume(xml.length);        // throws MicroscopeError('TOO_LARGE') if exceeded
}

DOM micro-helpers

import { createEl, clearContainer, anySignal, objectUrl, renderNativeMedia } from '@microscope-js/utils';

const img = createEl('img', { attrs: { src }, style: { maxWidth: '100%' } });
clearContainer(parent);

const merged = anySignal(userSignal, timeoutSignal);
const url = objectUrl(blob, (fn) => teardown.push(fn));   // auto-revoke

// One-liner native media renderer shared by renderer-video + renderer-audio
renderNativeMedia('video', source, container, { autoplay: false });

Error class

import { MicroscopeError } from '@microscope-js/utils';

throw new MicroscopeError('Source too large', 'TOO_LARGE');
// Codes: UNSUPPORTED | INVALID_SOURCE | TOO_LARGE | UNSAFE_ARCHIVE | RENDER_FAILED | ABORTED

See also

License

MIT