Skip to content

Commit

Permalink
add scoped name of urlAlphabet which is in export and import in one f…
Browse files Browse the repository at this point in the history
…ile (#473)

* ref: add scoped variavle name of urlAlphabet which is in export and import in one file

* ref: revert gitingnore
  • Loading branch information
WilhelmYakunin authored Apr 7, 2024
1 parent 5bb460c commit ff346fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions index.browser.js
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit ff346fc

Please sign in to comment.