Socket
Socket
Sign inDemoInstall

nanoid

Package Overview
Dependencies
Maintainers
1
Versions
100
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 2.1.10 to 2.1.11

45

async/index.browser.js

@@ -7,30 +7,25 @@ // This file replaces `async/index.js` in bundlers like webpack or Rollup,

// This alphabet uses a-z A-Z 0-9 _- symbols.
// Despite the fact the source code is quite long, its entropy
// is low and there are lots of duplicates - just what compressors
// like GZIP and Brotli likes the best.
var i
var url = '_-' + String.fromCharCode(
// ASCII codes for 0...9
i = 48, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1,
// Symbols are generated for smaller size.
// -_zyxwvutsrqponmlkjihgfedcba9876543210ZYXWVUTSRQPONMLKJIHGFEDCBA
var url = '-_'
// Loop from 36 to 0 (from z to a and 9 to 0 in Base36).
var i = 36
while (i--) {
// 36 is radix. Number.prototype.toString(36) returns number
// in Base36 representation. Base36 is like hex, but it uses 0–9 and a-z.
url += i.toString(36)
}
// Loop from 36 to 10 (from Z to A in Base36).
i = 36
while (i-- - 10) {
url += i.toString(36).toUpperCase()
}
// ASCII codes for A...Z
i += 8, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1,
// ASCII codes for a...z
i += 7, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1
)
module.exports = function (size) {
size = size || 21
var id = ''
var bytes = crypto.getRandomValues(new Uint8Array(size))
var bytes = crypto.getRandomValues(new Uint8Array(size || 21))
i = size || 21
// Compact alternative for `for (var i = 0; i < size; i++)`
while (size--) {
while (i--) {
// We can’t use bytes bigger than the alphabet. 63 is 00111111 bitmask.

@@ -40,5 +35,5 @@ // This mask reduces random byte 0-255 to 0-63 values.

// because bitmask trim bytes exact to alphabet size.
id += url[bytes[size] & 63]
id += url[bytes[i] & 63]
}
return Promise.resolve(id)
}
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/).
## 2.1.11
* Reduce size (by Anton Evzhakov).
## 2.1.10

@@ -5,0 +8,0 @@ * Reduce size by 10% (by Anton Khlynovskiy).

@@ -24,30 +24,25 @@ // This file replaces `index.js` in bundlers like webpack or Rollup,

// This alphabet uses a-z A-Z 0-9 _- symbols.
// Despite the fact the source code is quite long, its entropy
// is low and there are lots of duplicates - just what compressors
// like GZIP and Brotli likes the best.
var i
var url = '_-' + String.fromCharCode(
// ASCII codes for 0...9
i = 48, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1,
// Symbols are generated for smaller size.
// -_zyxwvutsrqponmlkjihgfedcba9876543210ZYXWVUTSRQPONMLKJIHGFEDCBA
var url = '-_'
// Loop from 36 to 0 (from z to a and 9 to 0 in Base36).
var i = 36
while (i--) {
// 36 is radix. Number.prototype.toString(36) returns number
// in Base36 representation. Base36 is like hex, but it uses 0–9 and a-z.
url += i.toString(36)
}
// Loop from 36 to 10 (from Z to A in Base36).
i = 36
while (i-- - 10) {
url += i.toString(36).toUpperCase()
}
// ASCII codes for A...Z
i += 8, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1,
// ASCII codes for a...z
i += 7, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1
)
module.exports = function (size) {
size = size || 21
var id = ''
var bytes = crypto.getRandomValues(new Uint8Array(size))
var bytes = crypto.getRandomValues(new Uint8Array(size || 21))
i = size || 21
// Compact alternative for `for (var i = 0; i < size; i++)`
while (size--) {
while (i--) {
// We can’t use bytes bigger than the alphabet. 63 is 00111111 bitmask.

@@ -57,5 +52,5 @@ // This mask reduces random byte 0-255 to 0-63 values.

// because bitmask trim bytes exact to alphabet size.
id += url[bytes[size] & 63]
id += url[bytes[i] & 63]
}
return id
}
// This alphabet uses a-z A-Z 0-9 _- symbols.
// Despite the fact the source code is quite long, its entropy
// is low and there are lots of duplicates - just what compressors
// like GZIP and Brotli likes the best.
var i
var url = '_-' + String.fromCharCode(
// ASCII codes for 0...9
i = 48, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1,
// Symbols are generated for smaller size.
// -_zyxwvutsrqponmlkjihgfedcba9876543210ZYXWVUTSRQPONMLKJIHGFEDCBA
var url = '-_'
// Loop from 36 to 0 (from z to a and 9 to 0 in Base36).
var i = 36
while (i--) {
// 36 is radix. Number.prototype.toString(36) returns number
// in Base36 representation. Base36 is like hex, but it uses 0–9 and a-z.
url += i.toString(36)
}
// Loop from 36 to 10 (from Z to A in Base36).
i = 36
while (i-- - 10) {
url += i.toString(36).toUpperCase()
}
// ASCII codes for A...Z
i += 8, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1,
// ASCII codes for a...z
i += 7, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1
)
/**

@@ -40,6 +34,6 @@ * Generate URL-friendly unique ID. This method use non-secure predictable

module.exports = function (size) {
size = size || 21
var id = ''
i = size || 21
// Compact alternative for `for (var i = 0; i < size; i++)`
while (size--) {
while (i--) {
// `| 0` is compact and faster alternative for `Math.floor()`

@@ -46,0 +40,0 @@ id += url[Math.random() * 64 | 0]

{
"name": "nanoid",
"version": "2.1.10",
"description": "A tiny (127 bytes), secure URL-friendly unique string ID generator",
"version": "2.1.11",
"description": "A tiny (119 bytes), secure URL-friendly unique string ID generator",
"keywords": [

@@ -6,0 +6,0 @@ "uuid",

@@ -8,3 +8,3 @@ # Nano ID

* **Small.** 127 bytes (minified and gzipped). No dependencies.
* **Small.** 119 bytes (minified and gzipped). No dependencies.
[Size Limit] controls the size.

@@ -67,3 +67,3 @@ * **Safe.** It uses cryptographically strong random APIs.

2. Nano ID code is 4 times less than `uuid/v4` package:
127 bytes instead of 435.
119 bytes instead of 435.
3. Because of memory allocation tricks, Nano ID is 16% faster than UUID.

@@ -70,0 +70,0 @@

@@ -6,4 +6,2 @@ // This alphabet uses a-z A-Z 0-9 _- symbols.

var i
/**

@@ -19,18 +17,13 @@ * URL safe symbols.

*/
module.exports = '_-' + String.fromCharCode(
// ASCII codes for 0...9
i = 48, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1,
// ASCII codes for A...Z
i += 8, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1,
// ASCII codes for a...z
i += 7, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1, i += 1,
i += 1, i += 1
)
// This alphabet uses a-z A-Z 0-9 _- symbols.
// Symbols are generated for smaller size.
// -_zyxwvutsrqponmlkjihgfedcba9876543210ZYXWVUTSRQPONMLKJIHGFEDCBA
module.exports = '-_'
var i = 36
while (i--) {
// 36 is radix. Number.prototype.toString(36) returns number
// in Base36 representation. Base36 is like hex, but it uses 0–9 and a-z.
module.exports += i.toString(36)
i > 9 && (module.exports += i.toString(36).toUpperCase())
}
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