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

vanilla-jwt

v0.9.0

Published

lightweight and simple JWT en-/decoder with signature check written in vanilla js

Readme

JWT - JSON Web Token (RFC7519) en-/decoder

lightweight and simple JWT en-/decoder with signature check written in vanilla js

This library uses as little code as possible while still implementing signature checking for HS256, HS384 and HS512.

It also supports setting the iat and checking the exp registered claim names.

Usage

Options for en- and decoding

opts are the configuration options as an object for en-/decoding. Currently the only mandatoy (and available key) is secrets. Which is itself an object with algorithms (alg) as keys and the secret as value.

Example:

const opts = {
    secrets: {
        "HS256": "Bvb1tVQRsu1fFFV626WEfQMZOBmIToGbGJMp0XYkpiB",
        "HS384": "s6TxfHOCxxizFt5f1iGOQMfjn9LshkmQqDhavazOsAHjeIX2qDZ0QiRjxMECTTj43",
        "HS512": "NcWpuqA0oKNshYKosta73vjlil3cc5jkZgOKF0PVYxxMmBdXiSYK1FPE0yw3yHAXEBtjGSPUBqwDAJtcPHM3CF",
    },
};

Decoding via jwtDecode( text, opts )

This function will return the payload object on success, and throw an error otherwise. If exp is set and in the past, an error will be thrown as well.

Parameters:

  • text: a JWT string
  • opts: see above

Example:

import { jwtDecode } from "./jwt.mjs"

const jwtSecret = "NuJlDdJmLS2WEAYIu9vTLGFmsTwGK3ZbPp3zmesayBgnFmscPzStKoM0ERDmbbGnqXjDIUSPMEUaMP7vRqTbPU";
const jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJleGFtcGxlLmNvbSIsImlhdCI6MTcwMDAwMDAwMCwiZXhwIjo0MDAwMDAwMDAwfQ.T9k4Gz7E1hRHXO7WFBN-n7vyP7_Em6-Pln_U1zU0Y4c";

const opts = {
    secrets: {
        "HS256": jwtSecret,
    },
};

console.log( jwtDecode( jwt, opts ) );
// output: { sub: 'example.com', iat: 1700000000, exp: 4000000000 }

Encoding via jwtEncode( obj, alg, opts )

Encode obj as JWT string using alg and secrets from opts

Parameters:

  • obj: payload object
  • alg: algorithm to use, see RFC7518 for details. currently supports HS256, HS384 and HS512
  • opts: see above

Example:

import { jwtEncode } from "./jwt.mjs"

const jwtSecret = "NuJlDdJmLS2WEAYIu9vTLGFmsTwGK3ZbPp3zmesayBgnFmscPzStKoM0ERDmbbGnqXjDIUSPMEUaMP7vRqTbPU";

const opts = {
    secrets: {
        "HS256": jwtSecret,
    },
};

console.log( jwtEncode({
  "sub": "example.com",
  "exp": Math.round((Date.now() + 24 * 3600 * 1000) / 1000), /* expire in 24h */
}, "HS256", opts) );
// output: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJleGFtcGxlLmNvbSIsImV4cCI6MTc1MjE3NTgwMSwiaWF0IjoxNzUyMDg5NDAxfQ.8v5_MysNPQhIYTehBNfu_2_ZUIvqGu7oVSPgExuuJPw