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

is-jwt-token

v1.0.0

Published

A lightweight utility to validate JWT token format

Readme

is-jwt-token

A lightweight utility to validate JWT (JSON Web Token) format. This package provides a single function to quickly check if a string is a properly formatted JWT token.

Features

  • Zero dependencies - Lightweight and secure
  • Single function - Simple and focused API
  • Fast validation - Optimized for performance
  • TypeScript friendly - Works with TypeScript projects
  • Comprehensive validation - Validates structure, encoding, and JSON format
  • Production ready - Thoroughly tested

Installation

npm install is-jwt-token

Usage

const isJWT = require('is-jwt-token');

// Valid JWT token
const validToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';

console.log(isJWT(validToken)); // true

// Invalid tokens
console.log(isJWT('invalid.token')); // false
console.log(isJWT('not-a-token')); // false
console.log(isJWT(null)); // false
console.log(isJWT('')); // false
console.log(isJWT('   ')); // false (whitespace only)

API

isJWT(token)

Validates if a string is a properly formatted JWT token.

Parameters:

  • token (any): The token to validate

Returns: boolean - True if token is valid JWT format, false otherwise

Examples

Basic Usage

const isJWT = require('is-jwt-token');

const userToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.abc123';

if (isJWT(userToken)) {
  console.log('Valid JWT token format');
  // Proceed with token verification using other libraries
} else {
  console.log('Invalid token format');
}

Express.js Middleware

const isJWT = require('is-jwt-token');

function validateJWTFormat(req, res, next) {
  const authHeader = req.headers.authorization;
  const token = authHeader?.startsWith('Bearer ') 
    ? authHeader.substring(7) 
    : null;
  
  if (!isJWT(token)) {
    return res.status(400).json({ 
      error: 'Invalid JWT token format' 
    });
  }
  
  req.token = token;
  next();
}

app.use('/api/protected', validateJWTFormat);

Input Validation

const isJWT = require('is-jwt-token');

function processToken(userInput) {
  if (!isJWT(userInput)) {
    throw new Error('Invalid JWT format');
  }
  
  // Continue with signature verification, etc.
  return verifyTokenSignature(userInput);
}

What This Package Validates

Token structure - Ensures exactly 3 parts separated by dots
Base64url encoding - Validates proper encoding of each part
JSON format - Ensures header and payload are valid JSON
Required fields - Checks header contains 'alg' property
Edge cases - Handles null, undefined, empty strings, whitespace

What This Package Does NOT Do

Signature verification - Does not verify cryptographic signatures
Token generation - Does not create JWT tokens
Expiration checking - Does not validate exp claims
Claim validation - Does not validate token claims

Note: This package only validates JWT format. For complete JWT functionality including signature verification, use libraries like jsonwebtoken.

License

MIT