nanoid
Advanced tools
Comparing version 3.1.8 to 3.1.9
@@ -1,2 +0,3 @@ | ||
import { random } from './random/index.js' | ||
let random = bytes => | ||
Promise.resolve(crypto.getRandomValues(new Uint8Array(bytes))) | ||
@@ -3,0 +4,0 @@ let customAlphabet = (alphabet, size) => { |
@@ -0,4 +1,21 @@ | ||
import crypto from 'crypto' | ||
import { urlAlphabet } from '../url-alphabet/index.js' | ||
import { random } from './random/index.js' | ||
// `crypto.randomFill()` is a little faster than `crypto.randomBytes()`, | ||
// because it is possible to use in combination with `Buffer.allocUnsafe()`. | ||
let random = bytes => | ||
new Promise((resolve, reject) => { | ||
// `Buffer.allocUnsafe()` is faster because it doesn’t flush the memory. | ||
// Memory flushing is unnecessary since the buffer allocation itself resets | ||
// the memory with the new bytes. | ||
crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => { | ||
if (err) { | ||
reject(err) | ||
} else { | ||
resolve(buf) | ||
} | ||
}) | ||
}) | ||
let customAlphabet = (alphabet, size) => { | ||
@@ -5,0 +22,0 @@ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes |
@@ -5,3 +5,5 @@ { | ||
"module": "index.js", | ||
"react-native": "index.js", | ||
"react-native": { | ||
"./index.js": "./index.native.js" | ||
}, | ||
"browser": { | ||
@@ -8,0 +10,0 @@ "./index.js": "./index.browser.js" |
# Change Log | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
## 3.1.9 | ||
* Try to fix React Native Expo support. | ||
## 3.1.8 | ||
@@ -5,0 +8,0 @@ * Add React Native Expo support. |
{ | ||
"name": "nanoid", | ||
"version": "3.1.8", | ||
"version": "3.1.9", | ||
"description": "A tiny (108 bytes), secure URL-friendly unique string ID generator", | ||
@@ -48,10 +48,4 @@ "keywords": [ | ||
"import": "./url-alphabet/index.js" | ||
}, | ||
"./async/random/package.json": "./async/random/package.json", | ||
"./async/random": { | ||
"require": "./async/random/index.cjs", | ||
"import": "./async/random/index.js", | ||
"browser": "./async/random/index.browser.js" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
48308
694
23