crypto-random-string
Advanced tools
Comparing version 3.3.1 to 4.0.0
@@ -43,3 +43,3 @@ import {MergeExclusive} from 'type-fest'; | ||
//=> '`#Rt8$IK>B' | ||
cryptoRandomString({length: 10, type: 'alphanumeric'}); | ||
@@ -70,5 +70,3 @@ //=> 'DMuKL8YtE7' | ||
declare namespace cryptoRandomString { | ||
type Options = BaseOptions & MergeExclusive<TypeOption, CharactersOption>; | ||
} | ||
export type Options = BaseOptions & MergeExclusive<TypeOption, CharactersOption>; | ||
@@ -83,3 +81,3 @@ declare const cryptoRandomString: { | ||
``` | ||
import cryptoRandomString = require('crypto-random-string'); | ||
import cryptoRandomString from 'crypto-random-string'; | ||
@@ -90,3 +88,3 @@ cryptoRandomString({length: 10}); | ||
*/ | ||
(options: cryptoRandomString.Options): string; | ||
(options: Options): string; | ||
@@ -96,2 +94,8 @@ /** | ||
For most use-cases, there's really no good reason to use this async version. From the Node.js docs: | ||
> The `crypto.randomBytes()` method will not complete until there is sufficient entropy available. This should normally never take longer than a few milliseconds. The only time when generating the random bytes may conceivably block for a longer period of time is right after boot, when the whole system is still low on entropy. | ||
In general, anything async comes with some overhead on it's own. | ||
@returns A promise which resolves to a randomized string. | ||
@@ -101,3 +105,3 @@ | ||
``` | ||
import cryptoRandomString = require('crypto-random-string'); | ||
import cryptoRandomString from 'crypto-random-string'; | ||
@@ -108,5 +112,5 @@ await cryptoRandomString.async({length: 10}); | ||
*/ | ||
async(options: cryptoRandomString.Options): Promise<string>; | ||
} | ||
async(options: Options): Promise<string>; | ||
}; | ||
export = cryptoRandomString; | ||
export default cryptoRandomString; |
18
index.js
@@ -1,4 +0,3 @@ | ||
'use strict'; | ||
const {promisify} = require('util'); | ||
const crypto = require('crypto'); | ||
import {promisify} from 'util'; | ||
import crypto from 'crypto'; | ||
@@ -74,3 +73,3 @@ const randomBytesAsync = promisify(crypto.randomBytes); | ||
const allowedTypes = [ | ||
const allowedTypes = new Set([ | ||
undefined, | ||
@@ -84,3 +83,3 @@ 'hex', | ||
'alphanumeric' | ||
]; | ||
]); | ||
@@ -100,3 +99,3 @@ const createGenerator = (generateForCustomCharacters, generateRandomBytes) => ({length, type, characters}) => { | ||
if (!allowedTypes.includes(type)) { | ||
if (!allowedTypes.has(type)) { | ||
throw new TypeError(`Unknown type: ${type}`); | ||
@@ -148,3 +147,6 @@ } | ||
module.exports = createGenerator(generateForCustomCharacters, generateRandomBytes); | ||
module.exports.async = createGenerator(generateForCustomCharactersAsync, generateRandomBytesAsync); | ||
const cryptoRandomString = createGenerator(generateForCustomCharacters, generateRandomBytes); | ||
cryptoRandomString.async = createGenerator(generateForCustomCharactersAsync, generateRandomBytesAsync); | ||
export default cryptoRandomString; |
{ | ||
"name": "crypto-random-string", | ||
"version": "3.3.1", | ||
"version": "4.0.0", | ||
"description": "Generate a cryptographically strong random string", | ||
"license": "MIT", | ||
"repository": "sindresorhus/crypto-random-string", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=12" | ||
}, | ||
@@ -39,9 +42,9 @@ "scripts": { | ||
"dependencies": { | ||
"type-fest": "^0.8.1" | ||
"type-fest": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"ava": "^2.1.0", | ||
"tsd": "^0.11.0", | ||
"xo": "^0.25.3" | ||
"ava": "^3.15.0", | ||
"tsd": "^0.14.0", | ||
"xo": "^0.38.2" | ||
} | ||
} |
@@ -16,3 +16,3 @@ # crypto-random-string | ||
```js | ||
const cryptoRandomString = require('crypto-random-string'); | ||
import cryptoRandomString from 'crypto-random-string'; | ||
@@ -54,2 +54,8 @@ cryptoRandomString({length: 10}); | ||
For most use-cases, there's really no good reason to use this async version. From the Node.js docs: | ||
> The `crypto.randomBytes()` method will not complete until there is sufficient entropy available. This should normally never take longer than a few milliseconds. The only time when generating the random bytes may conceivably block for a longer period of time is right after boot, when the whole system is still low on entropy. | ||
In general, anything async comes with some overhead on it's own. | ||
#### options | ||
@@ -56,0 +62,0 @@ |
Sorry, the diff of this file is not supported yet
15369
196
117
Yes
+ Addedtype-fest@1.4.0(transitive)
- Removedtype-fest@0.8.1(transitive)
Updatedtype-fest@^1.0.1