Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nanoid

Package Overview
Dependencies
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nanoid - npm Package Compare versions

Comparing version 3.2.0 to 3.3.0

6

async/index.browser.js
let random = async bytes => crypto.getRandomValues(new Uint8Array(bytes))
let customAlphabet = (alphabet, size) => {
let customAlphabet = (alphabet, defaultSize = 21) => {
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
let step = -~((1.6 * mask * size) / alphabet.length)
return async () => {
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
return async (size = defaultSize) => {
let id = ''

@@ -7,0 +7,0 @@ while (true) {

@@ -27,4 +27,4 @@ /**

* @param alphabet Alphabet used to generate the ID.
* @param size Size of the ID.
* @returns A promise with a random string.
* @param defaultSize Size of the ID. The default size is 21.
* @returns A function that returns a promise with a random string.
*

@@ -41,4 +41,4 @@ * ```js

alphabet: string,
size: number
): () => Promise<string>
defaultSize?: number
): (size?: number) => Promise<string>

@@ -45,0 +45,0 @@ /**

@@ -13,6 +13,6 @@ import crypto from 'crypto'

})
let customAlphabet = (alphabet, size) => {
let customAlphabet = (alphabet, defaultSize = 21) => {
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
let step = Math.ceil((1.6 * mask * size) / alphabet.length)
let tick = id =>
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
let tick = (id, size = defaultSize) =>
random(step).then(bytes => {

@@ -24,5 +24,5 @@ let i = step

}
return tick(id)
return tick(id, size)
})
return () => tick('')
return size => tick('', size)
}

@@ -29,0 +29,0 @@ let nanoid = (size = 21) =>

import { getRandomBytesAsync } from 'expo-random'
import { urlAlphabet } from '../url-alphabet/index.js'
let random = getRandomBytesAsync
let customAlphabet = (alphabet, size) => {
let customAlphabet = (alphabet, defaultSize = 21) => {
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
let step = Math.ceil((1.6 * mask * size) / alphabet.length)
let tick = id =>
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
let tick = (id, size = defaultSize) =>
random(step).then(bytes => {

@@ -14,5 +14,5 @@ let i = step

}
return tick(id)
return tick(id, size)
})
return () => tick('')
return size => tick('', size)
}

@@ -19,0 +19,0 @@ let nanoid = (size = 21) =>

@@ -29,6 +29,6 @@ import { urlAlphabet } from './url-alphabet/index.js'

let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
let customRandom = (alphabet, size, getRandom) => {
let customRandom = (alphabet, defaultSize, getRandom) => {
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
let step = -~((1.6 * mask * size) / alphabet.length)
return () => {
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
return (size = defaultSize) => {
let id = ''

@@ -45,3 +45,4 @@ while (true) {

}
let customAlphabet = (alphabet, size) => customRandom(alphabet, size, random)
let customAlphabet = (alphabet, size = 21) =>
customRandom(alphabet, size, random)
let nanoid = (size = 21) => {

@@ -48,0 +49,0 @@ let id = ''

@@ -24,3 +24,3 @@ /**

* @param alphabet Alphabet used to generate the ID.
* @param size Size of the ID.
* @param defaultSize Size of the ID. The default size is 21.
* @returns A random string generator.

@@ -34,3 +34,6 @@ *

*/
export function customAlphabet(alphabet: string, size: number): () => string
export function customAlphabet(
alphabet: string,
defaultSize?: number
): (size?: number) => string

@@ -37,0 +40,0 @@ /**

@@ -29,6 +29,6 @@ import { urlAlphabet } from './url-alphabet/index.js'

let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
let customRandom = (alphabet, size, getRandom) => {
let customRandom = (alphabet, defaultSize, getRandom) => {
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
let step = -~((1.6 * mask * size) / alphabet.length)
return () => {
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
return (size = defaultSize) => {
let id = ''

@@ -45,3 +45,4 @@ while (true) {

}
let customAlphabet = (alphabet, size) => customRandom(alphabet, size, random)
let customAlphabet = (alphabet, size = 21) =>
customRandom(alphabet, size, random)
let nanoid = (size = 21) => {

@@ -48,0 +49,0 @@ let id = ''

@@ -20,6 +20,6 @@ import crypto from 'crypto'

}
let customRandom = (alphabet, size, getRandom) => {
let customRandom = (alphabet, defaultSize, getRandom) => {
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
let step = Math.ceil((1.6 * mask * size) / alphabet.length)
return () => {
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
return (size = defaultSize) => {
let id = ''

@@ -36,3 +36,4 @@ while (true) {

}
let customAlphabet = (alphabet, size) => customRandom(alphabet, size, random)
let customAlphabet = (alphabet, size = 21) =>
customRandom(alphabet, size, random)
let nanoid = (size = 21) => {

@@ -39,0 +40,0 @@ fillPool((size -= 0))

@@ -29,6 +29,6 @@ import { urlAlphabet } from './url-alphabet/index.js'

let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
let customRandom = (alphabet, size, getRandom) => {
let customRandom = (alphabet, defaultSize, getRandom) => {
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
let step = -~((1.6 * mask * size) / alphabet.length)
return () => {
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
return (size = defaultSize) => {
let id = ''

@@ -45,3 +45,4 @@ while (true) {

}
let customAlphabet = (alphabet, size) => customRandom(alphabet, size, random)
let customAlphabet = (alphabet, size = 21) =>
customRandom(alphabet, size, random)
let nanoid = (size = 21) => {

@@ -48,0 +49,0 @@ let id = ''

@@ -16,3 +16,3 @@ /**

/**
* Generate URL-friendly unique ID based on the custom alphabet.
* Generate a unique ID based on a custom alphabet.
* This method uses the non-secure predictable random generator

@@ -22,4 +22,4 @@ * with bigger collision probability.

* @param alphabet Alphabet used to generate the ID.
* @param size Size of the ID.
* @returns A random string.
* @param defaultSize Size of the ID. The default size is 21.
* @returns A random string generator.
*

@@ -32,2 +32,5 @@ * ```js

*/
export function customAlphabet(alphabet: string, size: number): () => string
export function customAlphabet(
alphabet: string,
defaultSize?: number
): (size?: number) => string
let urlAlphabet =
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
let customAlphabet = (alphabet, size) => {
return () => {
let customAlphabet = (alphabet, defaultSize = 21) => {
return (size = defaultSize) => {
let id = ''

@@ -6,0 +6,0 @@ let i = size

{
"name": "nanoid",
"version": "3.2.0",
"version": "3.3.0",
"description": "A tiny (130 bytes), secure URL-friendly unique string ID generator",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc