2.2.1 • Published 2 years ago

random-web-token v2.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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

Installation

npm i random-web-token

install this too if typescript

npm i --save-dev @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

in Typescript

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

Parameter help for genSync() and genAsync()

first parameter is a string (indicates the allowed characters in token)

  • "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

Token validator

You can check that the received token contains only the allowed characters

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
1.9.0

2 years ago

1.8.0

2 years ago

2.2.1

2 years ago

2.1.2

2 years ago

2.2.0

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.9.9

2 years ago

1.9.8

2 years ago

1.9.5

2 years ago

1.6.0

3 years ago

1.5.9

3 years ago

1.5.8

3 years ago

1.5.7

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.6

3 years ago

1.5.0

3 years ago

1.4.9

3 years ago

1.4.1

3 years ago

1.3.9

3 years ago

1.3.6

3 years ago

1.3.8

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago