npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

simple-random

1.0.3 • Public • Published

Simple Random

Build Status npm version npm

A simple flexible javascript library that creates random alpha-numeric strings. Very useful when creating random names for files, folders. Can also create secure random strings for temporary passwords and salts.

Works in both NodeJS and the browser.

Secure Random

if the secure option is set to true, we can create a random byte seed with a cryptography library as opposed to Math.random(). In Node we use the default crypto library. In webpack / browser versions we use the Web Cryptography API if supported.

Installation

npm install simple-random --save 

Usage

Node

var sr = require('simple-random');
var randomString = sr(); // Generates a 16 character alpha-numeric string.
// Example output: "pnxTcl2nOBqTNFQR"

WebPack

var sr=require('simple-random/browser'); 
var randomString = sr(); // Generates a 16 character alpha-numeric string.
// Example output: "pnxTcl2nOBqTNFQR"

Browser

<script src="simple-random/dist/simple_random.js"></script>
<script>
var randomString = window.simpleRandom();
 
//Secure Random
var secureRandom;
if (simpleRandom.isSecureSupported){
  secureRandom = simpleRandom({secure:true})
}
 
</script> 

Options

  • length: The length of the alpha-numeric string (default 16).
  • digits: should allow digits in random string (default true).
  • letters: should allow letters in random string (default true).
  • caseSensitive: if set to false, only lowercase letter characters will be used (default true).
  • secure: Whether or not to use the crypto library for secure random byte seed as opposed to Math.random() (default false).
  • prefix: Prefix.
  • suffix: Suffix.
  • chars: A string containing all the characters to draw from, defaults to all alpha-numeric characters (overrides digits, letters and caseSensitive flags).

install

npm i simple-random

Downloadsweekly downloads

1,860

version

1.0.3

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability