1.0.1 โ€ข Published 6 months ago

minijwt v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

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

1.0.1

6 months ago

1.0.0

6 months ago