npm

Need private packages and team management tools?Check out npm Orgs. »

crypto-random-string

3.0.1 • Public • Published

crypto-random-string Build Status

Generate a cryptographically strong random string

Can be useful for creating an identifier, slug, salt, fixture, etc.

Install

$ npm install crypto-random-string

Usage

const cryptoRandomString = require('crypto-random-string');
 
cryptoRandomString({length: 10});
//=> '2cf05d94db'
 
cryptoRandomString({length: 10, type: 'base64'});
//=> 'YMiMbaQl6I'
 
cryptoRandomString({length: 10, type: 'url-safe'});
//=> 'YN-tqc8pOw'
 
cryptoRandomString({length: 10, characters: '1234567890'});
//=> '1791935639'

API

cryptoRandomString(options)

Returns a randomized string. Hex by default.

options

Type: object

length

Required
Type: number

Length of the returned string.

type

Type: string
Default: 'hex'
Values: 'hex' 'base64' 'url-safe'

Use only characters from a predefined set of allowed characters.

Cannot be set at the same time as the characters option.

characters

Type: string
Minimum length: 1
Maximum length: 65536

Use only characters from a custom set of allowed characters.

Cannot be set at the same time as the type option.

Related

License

MIT © Sindre Sorhus

install

npm i crypto-random-string

Downloadsweekly downloads

5,559,685

version

3.0.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability