You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

random-web-token

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

random-web-token

Token generator/validator without external dependencies

2.0.0
Source
npmnpm
Version published
Weekly downloads
137
-0.72%
Maintainers
1
Weekly downloads
 
Created
Source

Generating tokens with (a-z, a-Z, a-Z + 0-9 ...etc) or your own characters easily without external dependencies

Installation

npm install random-web-token

+ If typescript

npm install @types/random-web-token

Usage

Generating a token using genSync() or genAsync()

const token = require("random-web-token");
console.log(token.genSync("extra", 50)) // -> sHF3p8zZCTdAmJ0cyS60NK9RRPXi6NQ42zdUbigMBZYZY0504H

Usage in Typescript

import * as token from "random-web-token";
console.log(token.genSync("extra", 50)) // -> sHF3p8zZCTdAmJ0cyS60NK9RRPXi6NQ42zdUbigMBZYZY0504H

Parameter help for genSync() and genAsync() methods

first parameter is a string

  • "normal" -> (a-z)
  • "normal+" -> (A-Z)
  • "medium" -> (a-z + 0-9)
  • "medium+" -> (A-Z + 0-9)
  • "extra" -> (a-Z + 0-9)
  • "onlyNumbers" -> (0-9)

second parameter is a number, the length of token

Validator for genSync() or genAsync()

Token validation using syncValidator() or asyncValidator()

const firstToken = token.genSync("extra", 50);

console.log(token.syncValidator("extra", 50, firstToken)) // true firstToken same type,length
console.log(token.syncValidator("extra", 40, firstToken)) // false firstToken same type, but firstToken length !== 40
console.log(token.syncValidator("normal", 50, firstToken)) // false firstToken same length but not the same type.

const secondToken = token.genSync("extra", 50) + "+!/"; // returns 50 length token + 3 extra character

console.log(token.syncValidator("extra", 53, secondToken, "+!/")) // true same type/length and +3 allowed characters "+!/"
console.log(token.syncValidator("extra", 53, secondToken, "")) // false same type/length but "+!/" characters not allowed

fourth parameter is optional

If you want a token with your own characters

use withMyOwnCharacters() method

await token.withMyOwnCharacters("abc123", 10) // -> a2b1cc23ab

Keywords

random

FAQs

Package last updated on 01 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts