Deno.js Tutorial to Generate Cryptographically Strong Random Strings Using TypeScript Full Project For Beginners

 

 

crypto-random-string

 

Generate a cryptographically strong random string

 

Deno module based on crypto-random-string. Useful for creating an identifier, slug, salt, PIN code, fixture, etc

 

 

Import Module

import { cryptoRandomString } from "https://deno.land/x/crypto_random_string@1.0.0/mod.ts"
// or
import { cryptoRandomString } from "https://github.com/piyush-bhatt/crypto-random-string/raw/main/mod.ts"

 

 

Usage

 

 

import { cryptoRandomString } from "https://deno.land/x/crypto_random_string@1.0.0/mod.ts"


console.log(cryptoRandomString({length: 10})); // '0696cb9e70'

console.log(cryptoRandomString({length: 10, type: 'base64'})); // 'dw3mgWC5uO'

console.log(cryptoRandomString({length: 10, type: 'url-safe'})); // '0pN1Y2Jz.X'

console.log(cryptoRandomString({length: 10, type: 'numeric'})); // '1639380067'

cryptoRandomString({length: 6, type: 'distinguishable'}); // 'H4HH5D'

cryptoRandomString({length: 10, type: 'ascii-printable'}); // '#I&J.GP./9'

cryptoRandomString({length: 10, type: 'alphanumeric'}); // 'ZtgC2J6aU5'

cryptoRandomString({length: 10, characters: 'abc'}); // 'abcabccbcc'

 

 

Leave a Reply