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

jwtdecodemaster

v1.0.0

Published

Lightweight, zero-dependency JWT decoder for Node.js and browsers. Decode JWT tokens without verification.

Readme

🔐 jwtdecodemaster

npm version License: MIT

A lightweight, zero-dependency JWT decoder for Node.js and browsers. Decode JWT tokens without verification - perfect for extracting header and payload data from JSON Web Tokens.

✨ Features

  • 🚀 Zero dependencies - No external packages required
  • 🌐 Universal - Works in both Node.js and browsers
  • 📦 Lightweight - Minimal bundle size
  • 💪 TypeScript - Full TypeScript support with type definitions
  • Robust - Comprehensive error handling and validation
  • 🔒 Safe - Validates JWT format before decoding

📦 Installation

npm install jwtdecodemaster
yarn add jwtdecodemaster
pnpm add jwtdecodemaster

🚀 Usage

Basic Example

import { decodeJWT } from 'jwtdecodemaster';

const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';

try {
  const decoded = decodeJWT(token);

  console.log('Header:', decoded.header);
  // Output: { alg: 'HS256', typ: 'JWT' }

  console.log('Payload:', decoded.payload);
  // Output: { sub: '1234567890', name: 'John Doe', iat: 1516239022 }
} catch (error) {
  console.error('Failed to decode JWT:', error.message);
}

CommonJS

const { decodeJWT } = require('jwtdecodemaster');

const token = 'your.jwt.token';
const decoded = decodeJWT(token);

console.log(decoded.header);
console.log(decoded.payload);

Browser (ES Modules)

<script type="module">
  import { decodeJWT } from './node_modules/jwtdecodemaster/dist/index.js';

  const token = 'your.jwt.token';
  const decoded = decodeJWT(token);

  console.log(decoded);
</script>

📖 API

decodeJWT(token: string): DecodedJWT

Decodes a JWT token and returns the header and payload.

Parameters

  • token (string): The JWT token to decode

Returns

interface DecodedJWT {
  header: Record<string, any>;
  payload: Record<string, any>;
}

Throws

  • Error if the token is invalid or cannot be decoded

Examples

// Valid token
const result = decodeJWT('eyJhbGci...');
// Returns: { header: {...}, payload: {...} }

// Invalid token - throws error
decodeJWT('invalid.token');
// Throws: Error('Invalid JWT token: token must have 3 parts separated by dots')

// Empty token - throws error
decodeJWT('');
// Throws: Error('Invalid JWT token: token must be a non-empty string')

⚠️ Important Notes

This library does NOT verify tokens

jwtdecodemaster only decodes JWT tokens - it does NOT verify signatures or validate tokens. This means:

  • ❌ Does not check if the token is signed correctly
  • ❌ Does not validate expiration (exp claim)
  • ❌ Does not verify issuer (iss claim)
  • ✅ Only extracts and decodes header and payload data

Use this library only when you need to read token data without verification (e.g., client-side token inspection, debugging, logging).

For token verification, use libraries like:

🔧 Error Handling

The library provides detailed error messages for different failure scenarios:

try {
  const decoded = decodeJWT(token);
} catch (error) {
  // Possible error messages:
  // - "Invalid JWT token: token must be a non-empty string"
  // - "Invalid JWT token: token must have 3 parts separated by dots"
  // - "Invalid JWT token: all parts must be non-empty"
  // - "JWT part cannot be empty"
  // - "Base64 decode failed: ..."
  // - "Failed to decode JWT token: ..."
}

🌍 Browser Compatibility

Works in all modern browsers that support:

  • ES2020
  • atob() or TextDecoder
  • Uint8Array

Tested in:

  • ✅ Chrome/Edge (latest)
  • ✅ Firefox (latest)
  • ✅ Safari (latest)
  • ✅ Node.js 14+

📝 License

MIT © Cavid Salimov

🤝 Contributing

Contributions, issues, and feature requests are welcome!

📧 Support

If you have any questions or need help, please open an issue on GitHub.