From 1fa0a3d84749d9a70870033b28af2f914e7c63b1 Mon Sep 17 00:00:00 2001 From: Andrey Sitnik Date: Tue, 12 Sep 2023 21:53:09 +0200 Subject: [PATCH] Fix Node.js 18 support --- index.js | 4 +++- test/index.test.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 2494980f..03084a9c 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,5 @@ +import crypto from 'node:crypto' + import { urlAlphabet } from './url-alphabet/index.js' export { urlAlphabet } @@ -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] } diff --git a/test/index.test.js b/test/index.test.js index 76e38e94..3ba7afb4 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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