-
-
Notifications
You must be signed in to change notification settings - Fork 42
Require Node.js 14.16 #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
bb59780
Require Node.js 14
Richienb 87c40d2
Fix
Richienb 2326ee0
Test
Richienb 31efb79
Fix
Richienb 12c3d20
Tweak
Richienb 4f69e0b
Add todo
Richienb 819c9ba
Import destructuring
Richienb a8edd5e
Reword todo
Richienb 0d66f3c
Update package.json
Richienb 85fe77b
Rename variable
Richienb 08db18e
Merge branch 'require-node-14' of https://github.com/Richienb/crypto-…
Richienb 7a4577d
Move to `ava`
Richienb 892a397
Update main.yml
sindresorhus 5c9649c
Update main.yml
sindresorhus 2a89372
Synchronise
Richienb 95aa399
Update test.js
Richienb b852a28
Update main.yml
sindresorhus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
// TODO: When targeting Node.js 16, remove `cryptoRandomStringAsync` and use `crypto.webcrypto.getRandomValues` to interop with the browser code. | ||
// TODO: Later, when targeting Node.js 18, only use the browser code | ||
import {promisify} from 'node:util'; | ||
import crypto from 'node:crypto'; | ||
import {randomBytes} from 'node:crypto'; | ||
import {createStringGenerator, createAsyncStringGenerator} from './core.js'; | ||
|
||
const randomBytesAsync = promisify(crypto.randomBytes); | ||
const randomBytesAsync = promisify(randomBytes); | ||
|
||
const cryptoRandomString = createStringGenerator((byteLength, type, length) => crypto.randomBytes(byteLength).toString(type).slice(0, length), crypto.randomBytes); | ||
cryptoRandomString.async = createAsyncStringGenerator(async (byteLength, type, length) => { | ||
export default createStringGenerator((byteLength, type, length) => randomBytes(byteLength).toString(type).slice(0, length), size => new Uint8Array(randomBytes(size))); | ||
export const cryptoRandomStringAsync = createAsyncStringGenerator(async (byteLength, type, length) => { | ||
const buffer = await randomBytesAsync(byteLength); | ||
return buffer.toString(type).slice(0, length); | ||
}, randomBytesAsync); | ||
|
||
export default cryptoRandomString; | ||
}, async size => new Uint8Array(await randomBytesAsync(size))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ cryptoRandomString({length: 10, characters: 'abc'}); | |
|
||
Returns a randomized string. [Hex](https://en.wikipedia.org/wiki/Hexadecimal) by default. | ||
|
||
### cryptoRandomString.async(options) | ||
### cryptoRandomStringAsync(options) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to indicate somehow that this is a named export and the other one is a default export. |
||
|
||
Returns a promise which resolves to a randomized string. [Hex](https://en.wikipedia.org/wiki/Hexadecimal) by default. | ||
|
||
|
@@ -58,6 +58,13 @@ For most use-cases, there's really no good reason to use this async version. Fro | |
|
||
In general, anything async comes with some overhead on it's own. | ||
|
||
```js | ||
import {cryptoRandomStringAsync} from 'crypto-random-string'; | ||
|
||
await cryptoRandomStringAsync({length: 10}); | ||
//=> '2cf05d94db' | ||
``` | ||
|
||
#### options | ||
|
||
Type: `object` | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.