crypto-random-string
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -18,2 +18,4 @@ import {MergeExclusive} from 'type-fest'; | ||
The `distinguishable` set contains only uppercase characters that are not easily confused: `CDEHKMPRTUWXY012458`. It can be useful if you need to print out a short string that you'd like users to read and type back in with minimal errors. For example, reading a code off of a screen that needs to be typed into a phone to connect two devices. | ||
@example | ||
@@ -32,5 +34,8 @@ ``` | ||
//=> '8314659141' | ||
cryptoRandomString({length: 6, type: 'distinguishable'}); | ||
//=> 'CDEHKM' | ||
``` | ||
*/ | ||
type?: 'hex' | 'base64' | 'url-safe' | 'numeric'; | ||
type?: 'hex' | 'base64' | 'url-safe' | 'numeric' | 'distinguishable'; | ||
} | ||
@@ -37,0 +42,0 @@ |
@@ -6,2 +6,3 @@ 'use strict'; | ||
const numericCharacters = '0123456789'.split(''); | ||
const distinguishableCharacters = 'CDEHKMPRTUWXY012458'.split(''); | ||
@@ -40,3 +41,4 @@ const generateForCustomCharacters = (length, characters) => { | ||
'url-safe', | ||
'numeric' | ||
'numeric', | ||
'distinguishable' | ||
]; | ||
@@ -81,2 +83,6 @@ | ||
if (type === 'distinguishable') { | ||
return generateForCustomCharacters(length, distinguishableCharacters); | ||
} | ||
if (characters.length === 0) { | ||
@@ -83,0 +89,0 @@ throw new TypeError('Expected `characters` string length to be greater than or equal to 1'); |
{ | ||
"name": "crypto-random-string", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Generate a cryptographically strong random string", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -30,2 +30,5 @@ # crypto-random-string [![Build Status](https://travis-ci.org/sindresorhus/crypto-random-string.svg?branch=master)](https://travis-ci.org/sindresorhus/crypto-random-string) | ||
cryptoRandomString({length: 6, type: 'distinguishable'}); | ||
//=> 'CDEHKM' | ||
cryptoRandomString({length: 10, characters: 'abc'}); | ||
@@ -56,3 +59,3 @@ //=> 'abaaccabac' | ||
Default: `'hex'`\ | ||
Values: `'hex' | 'base64' | 'url-safe' | 'numeric'` | ||
Values: `'hex' | 'base64' | 'url-safe' | 'numeric' | 'distinguishable'` | ||
@@ -63,2 +66,4 @@ Use only characters from a predefined set of allowed characters. | ||
The `distinguishable` set contains only uppercase characters that are not easily confused: `CDEHKMPRTUWXY012458`. It can be useful if you need to print out a short string that you'd like users to read and type back in with minimal errors. For example, reading a code off of a screen that needs to be typed into a phone to connect two devices. | ||
##### characters | ||
@@ -65,0 +70,0 @@ |
10003
133
97