crypto-random-string
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -23,10 +23,13 @@ import {MergeExclusive} from 'type-fest'; | ||
cryptoRandomString({length: 10, type:'base64'}); | ||
cryptoRandomString({length: 10, type: 'base64'}); | ||
//=> 'mhsX7xmIv/' | ||
cryptoRandomString({length: 10, type:'url-safe'}); | ||
cryptoRandomString({length: 10, type: 'url-safe'}); | ||
//=> 'VEjfNW3Yej' | ||
cryptoRandomString({length: 10, type: 'numeric'}); | ||
//=> '8314659141' | ||
``` | ||
*/ | ||
type?: 'hex' | 'base64' | 'url-safe'; | ||
type?: 'hex' | 'base64' | 'url-safe' | 'numeric'; | ||
} | ||
@@ -45,3 +48,3 @@ | ||
``` | ||
cryptoRandomString({length: 10, characters:'0123456789'}); | ||
cryptoRandomString({length: 10, characters: '0123456789'}); | ||
//=> '8796225811' | ||
@@ -48,0 +51,0 @@ ``` |
@@ -5,2 +5,3 @@ 'use strict'; | ||
const urlSafeCharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~'.split(''); | ||
const numericCharacters = '0123456789'.split(''); | ||
@@ -38,3 +39,4 @@ const generateForCustomCharacters = (length, characters) => { | ||
'base64', | ||
'url-safe' | ||
'url-safe', | ||
'numeric' | ||
]; | ||
@@ -75,2 +77,6 @@ | ||
if (type === 'numeric') { | ||
return generateForCustomCharacters(length, numericCharacters); | ||
} | ||
if (characters.length === 0) { | ||
@@ -77,0 +83,0 @@ throw new TypeError('Expected `characters` string length to be greater than or equal to 1'); |
{ | ||
"name": "crypto-random-string", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Generate a cryptographically strong random string", | ||
@@ -30,15 +30,18 @@ "license": "MIT", | ||
"salt", | ||
"pin", | ||
"crypto", | ||
"strong", | ||
"secure", | ||
"hex" | ||
"hex", | ||
"secret", | ||
"protect" | ||
], | ||
"dependencies": { | ||
"type-fest": "^0.5.2" | ||
"type-fest": "^0.8.1" | ||
}, | ||
"devDependencies": { | ||
"ava": "^2.1.0", | ||
"tsd": "^0.7.3", | ||
"xo": "^0.24.0" | ||
"tsd": "^0.11.0", | ||
"xo": "^0.25.3" | ||
} | ||
} |
@@ -5,5 +5,4 @@ # crypto-random-string [![Build Status](https://travis-ci.org/sindresorhus/crypto-random-string.svg?branch=master)](https://travis-ci.org/sindresorhus/crypto-random-string) | ||
Can be useful for creating an identifier, slug, salt, fixture, etc. | ||
Can be useful for creating an identifier, slug, salt, PIN code, fixture, etc. | ||
## Install | ||
@@ -15,3 +14,2 @@ | ||
## Usage | ||
@@ -31,7 +29,9 @@ | ||
cryptoRandomString({length: 10, characters: '1234567890'}); | ||
//=> '1791935639' | ||
cryptoRandomString({length: 10, type: 'numeric'}); | ||
//=> '8314659141' | ||
cryptoRandomString({length: 10, characters: 'abc'}); | ||
//=> 'abaaccabac' | ||
``` | ||
## API | ||
@@ -49,3 +49,3 @@ | ||
*Required*<br> | ||
*Required*\ | ||
Type: `number` | ||
@@ -57,5 +57,5 @@ | ||
Type: `string`<br> | ||
Default: `'hex'`<br> | ||
Values: `'hex'` `'base64'` `'url-safe'` | ||
Type: `string`\ | ||
Default: `'hex'`\ | ||
Values: `'hex' | 'base64' | 'url-safe' | 'numeric'` | ||
@@ -68,4 +68,4 @@ Use only characters from a predefined set of allowed characters. | ||
Type: `string`<br> | ||
Minimum length: `1`<br> | ||
Type: `string`\ | ||
Minimum length: `1`\ | ||
Maximum length: `65536` | ||
@@ -77,3 +77,2 @@ | ||
## Related | ||
@@ -89,5 +88,12 @@ | ||
--- | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) | ||
<div align="center"> | ||
<b> | ||
<a href="https://tidelift.com/subscription/pkg/npm-crypto-random-string?utm_source=npm-crypto-random-string&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a> | ||
</b> | ||
<br> | ||
<sub> | ||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. | ||
</sub> | ||
</div> |
8927
124
92
+ Addedtype-fest@0.8.1(transitive)
- Removedtype-fest@0.5.2(transitive)
Updatedtype-fest@^0.8.1