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

@dws-std/jwt

v1.1.1

Published

JWT utilities and helpers for secure token management.

Readme

🔐 DWS JWT

Signing and verifying JWTs shouldn't require boilerplate.
@dws-std/jwt wraps jose with sane defaults — HS256, standard claims pre-filled, human-readable expiration - so you can focus on what matters instead of re-reading the JWT spec.

📌 Table of Contents

🔧 Installation

bun add @dws-std/jwt

⚙️ Usage

signJWT

Signs a payload and returns a JWT string.
All standard claims (iss, sub, aud, jti, nbf, iat, exp) are included automatically - just pass your custom data and let the function handle the rest.

import { signJWT } from '@dws-std/jwt';

// Default expiration: 15 minutes
const token = await signJWT(secret, { userId: 42, role: 'admin' });

// Numeric offset in seconds
const token = await signJWT(secret, { userId: 42 }, 3600);

// Date object
const token = await signJWT(secret, { userId: 42 }, new Date(Date.now() + 3600_000));

// Human-readable — powered by @dws-std/common
const token = await signJWT(secret, { userId: 42 }, '1 hour');
const token = await signJWT(secret, { userId: 42 }, '30 minutes');
const token = await signJWT(secret, { userId: 42 }, '7 days');

The secret must be at least 32 characters long (HS256 requirement). Any shorter and it throws immediately — better to catch it at startup than in production.

Default claims can be overridden by providing them in the payload:

const token = await signJWT(secret, {
	iss: 'my-service',
	sub: 'user-123',
	aud: ['my-api'],
	userId: 42
});

verifyJWT

Verifies a token and returns the decoded payload. Throws if anything is wrong.

import { verifyJWT } from '@dws-std/jwt';

const { payload } = await verifyJWT(token, secret);
console.log(payload.userId);

Optionally validate iss and aud claims:

const { payload } = await verifyJWT(token, secret, {
	issuer: 'my-service',
	audience: 'my-api'
});

🚨 Error handling

All errors are Exception instances from @dws-std/error with a key you can check:

| Key | When | | ----------------------- | --------------------------------------------------------------- | | jwt.secret_too_weak | Secret is shorter than 32 characters | | jwt.expiration_passed | Expiration is in the past or equals now | | jwt.sign_error | jose failed to sign the token | | jwt.token_expired | Token is valid but past its expiry date | | jwt.unauthorized | Invalid signature, malformed token, or claim validation failure |

import { Exception } from '@dws-std/error';
import { JWT_ERROR_KEYS, verifyJWT } from '@dws-std/jwt';

try {
	const { payload } = await verifyJWT(token, secret);
} catch (error) {
	if (error instanceof Exception) {
		if (error.key === JWT_ERROR_KEYS.JWT_EXPIRED) {
			// Token expired — trigger a refresh
		}
		// Everything else is unauthorized
	}
}

⚖️ License

MIT - Feel free to use it.