minijwt
v1.0.1
Published
is a lightweight and fast JWT library designed to efficiently handle authentication without additional dependencies. Built with TypeScript for optimal security and scalability.
Downloads
9
Maintainers
Readme
minijwt
minijwt is a lightweight and fast JWT library designed to efficiently handle authentication without additional dependencies. Built with TypeScript for optimal security and scalability.
🚀 Installation
npm install minijwt
📖 Usage
import MiniJWT from "minijwt";
const secret = "mysecret";
const jwt = new MiniJWT(secret);
// Encode token
const token = jwt.encode({ user: "Asrul" }, 3600); // Expires in 1 hour
console.log(token);
// Decode token
const payload = jwt.decode(token);
console.log(payload);
🔧 API
new MiniJWT(secret: string)
Creates a MiniJWT instance with a secret key.
jwt.encode(payload: Record<string, any>, expiresIn?: number): string
Generates a JWT token with an optional expiration time (default: 3600 seconds).
jwt.decode(token: string): Record<string, any> | null
Returns the decoded payload if the token is valid, or null
if it is invalid or expired.
🎯 Features
- No additional dependencies for optimal performance.
- Simple and easy-to-use API.
- Full TypeScript support for type safety.
- Lightweight, making it ideal for modern applications.
🧪 Test Results
npm test
> minijwt@1.0.1 test
> jest
PASS test/index.test.ts
✓ JWT encode and decode (6 ms)
✓ JWT should return null if expired (1 ms)
✓ JWT should return null if tampered (1 ms)
Test Suites: 1 passed, 1 total
Tests: 3 passed, 3 total
Snapshots: 0 total
Time: 3.876 s, estimated 4 s
📜 License
MIT © Asrul Harahap