Skip to content

Commit

Permalink
Fix Node.js 18 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Sep 12, 2023
1 parent cf151a7 commit 1fa0a3d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import crypto from 'node:crypto'

import { urlAlphabet } from './url-alphabet/index.js'

export { urlAlphabet }
Expand Down Expand Up @@ -76,7 +78,7 @@ export function nanoid(size = 21) {
// It is incorrect to use bytes exceeding the alphabet size.
// The following mask reduces the random byte in the 0-255 value
// range to the 0-63 value range. Therefore, adding hacks, such
// as empty string fallback or magic numbers, is unneccessary because
// as empty string fallback or magic numbers, is unnecessary because
// the bitmask trims bytes down to the alphabet size.
id += urlAlphabet[pool[i] & 63]
}
Expand Down
4 changes: 2 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ for (let type of ['node', 'browser']) {

test(`${type} / random / generates random buffers`, () => {
let numbers = {}
let bytes = random(10000)
is(bytes.length, 10000)
let bytes = random(1000)
is(bytes.length, 1000)
for (let byte of bytes) {
if (!numbers[byte]) numbers[byte] = 0
numbers[byte] += 1
Expand Down

0 comments on commit 1fa0a3d

Please sign in to comment.