From ff346fc6f7862520b778a1acdeb3fd31caeb1c85 Mon Sep 17 00:00:00 2001 From: Vitalij Yakunin Date: Sun, 7 Apr 2024 19:34:57 +0300 Subject: [PATCH] add scoped name of urlAlphabet which is in export and import in one file (#473) * ref: add scoped variavle name of urlAlphabet which is in export and import in one file * ref: revert gitingnore --- index.browser.js | 4 ++-- index.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/index.browser.js b/index.browser.js index dd50f146..8b51358c 100644 --- a/index.browser.js +++ b/index.browser.js @@ -1,7 +1,7 @@ // This file replaces `index.js` in bundlers like webpack or Rollup, // according to `browser` config in `package.json`. -import { urlAlphabet } from './url-alphabet/index.js' +import { urlAlphabet as scopedUrlAlphabet } from './url-alphabet/index.js' export { urlAlphabet } from './url-alphabet/index.js' @@ -56,7 +56,7 @@ export let nanoid = (size = 21) => { // Using the bitwise AND operator to "cap" the value of // the random byte from 255 to 63, in that way we can make sure // that the value will be a valid index for the "chars" string. - id += urlAlphabet[bytes[size] & 63] + id += scopedUrlAlphabet[bytes[size] & 63] } return id } diff --git a/index.js b/index.js index 161cf860..a1ce01c6 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,8 @@ import { webcrypto as crypto } from 'node:crypto' -import { urlAlphabet } from './url-alphabet/index.js' +import { urlAlphabet as scopedUrlAlphabet } from './url-alphabet/index.js' -export { urlAlphabet } +export { urlAlphabet } from './url-alphabet/index.js' // It is best to make fewer, larger requests to the crypto module to // avoid system call overhead. So, random numbers are generated in a @@ -80,7 +80,7 @@ export function nanoid(size = 21) { // range to the 0-63 value range. Therefore, adding hacks, such // as empty string fallback or magic numbers, is unnecessary because // the bitmask trims bytes down to the alphabet size. - id += urlAlphabet[pool[i] & 63] + id += scopedUrlAlphabet[pool[i] & 63] } return id }