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 1.1.1 to 1.2.0

async.browser.js

6

CHANGELOG.md
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/).
## 1.2
* Add `nanoid/async`.
* Fix `nanoid/non-secure` JSDoc.
* Add Chinese documentation (by Wenliang Dai).
* Speed up and reduce size of `nanoid/non-secure` (by Ori Livni).
## 1.1.1

@@ -5,0 +11,0 @@ * Improve performance and reduce size of non-secure ID generator.

8

format.js

@@ -14,7 +14,9 @@ /**

* @example
* var format = require('nanoid/format')
* const format = require('nanoid/format')
*
* function random (size) {
* var result = []
* for (var i = 0; i < size; i++) result.push(randomByte())
* const result = []
* for (let i = 0; i < size; i++) {
* result.push(randomByte())
* }
* return result

@@ -21,0 +23,0 @@ * }

@@ -16,3 +16,3 @@ var random = require('./random')

* @example
* var generate = require('nanoid/generate')
* const generate = require('nanoid/generate')
* model.id = generate('0123456789абвгдеё', 5) //=> "8ё56а"

@@ -19,0 +19,0 @@ *

@@ -15,3 +15,3 @@ var random = require('./random')

* @example
* var nanoid = require('nanoid')
* const nanoid = require('nanoid')
* model.id = nanoid() //=> "Uakgb_J5m9g~0JDMbcJqL"

@@ -18,0 +18,0 @@ *

var url = '_~getRandomVcryp0123456789bfhijklqsuvwxzABCDEFGHIJKLMNOPQSTUWXYZ'
/**
* Generate URL-friendly unique ID. This method use non-secure predictable
* random generator.
*
* By default, ID will have 21 symbols to have a collision probability similar
* to UUID v4.
*
* @param {number} [size=21] The number of symbols in ID.
*
* @return {string} Random string.
*
* @example
* const nanoid = require('nanoid/non-secure')
* model.id = nanoid() //=> "Uakgb_J5m9g~0JDMbcJqL"
*
* @name nonSecure
* @function
*/
module.exports = function (size) {

@@ -7,5 +25,5 @@ size = size || 21

while (0 < size--) {
id += url[Math.floor(Math.random() * 63)]
id += url[Math.random() * 63 | 0]
}
return id
}
{
"name": "nanoid",
"version": "1.1.1",
"version": "1.2.0",
"description": "A tiny (145 bytes), secure URL-friendly unique string ID generator",

@@ -16,4 +16,5 @@ "keywords": [

"./random.js": "./random.browser.js",
"./index.js": "./index.browser.js"
"./index.js": "./index.browser.js",
"./async.js": "./async.browser.js"
}
}

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

**Small.** 143 bytes (minified and gzipped). No dependencies.
**Small.** 145 bytes (minified and gzipped). No dependencies.
It uses [Size Limit] to control size.

@@ -77,3 +77,3 @@

2. Nano ID code is 3 times less than `uuid/v4` package:
143 bytes instead of 435.
145 bytes instead of 435.

@@ -85,9 +85,15 @@

$ ./test/benchmark
nanoid 363,539 ops/sec
nanoid/generate 352,418 ops/sec
uid.sync 332,502 ops/sec
uuid/v4 345,867 ops/sec
shortid 34,193 ops/sec
rndm 2,557,778 ops/sec
nanoid/non-secure 2,578,934 ops/sec
nanoid 354,201 ops/sec
nanoid/generate 348,467 ops/sec
uid.sync 325,347 ops/sec
uuid/v4 322,328 ops/sec
shortid 33,277 ops/sec
Async:
uid 71,998 ops/sec
nanoid/async 72,836 ops/sec
Non-secure:
rndm 2,495,324 ops/sec
nanoid/non-secure 2,746,033 ops/sec
```

@@ -104,3 +110,3 @@

```js
var nanoid = require('nanoid')
const nanoid = require('nanoid')
model.id = nanoid() //=> "Uakgb_J5m9g~0JDMbcJqLJ"

@@ -136,3 +142,3 @@ ```

```js
var nanoid = require('nanoid/non-secure')
const nanoid = require('nanoid/non-secure')
model.id = nanoid() //=> "Uakgb_J5m9g~0JDMbcJqLJ"

@@ -142,2 +148,20 @@ ```

## Async
To generate hardware random bytes, CPU will collect electromagnetic noise.
During the collection, CPU doesn’t work. So if we will use asynchronous API
for hardware random generator, your other code could be executed during
the entropy collection.
```js
const nanoid = require('nanoid/async')
nanoid.then(id => {
model.id = id
})
```
Unfortunately, you will not have any benefits in browser, since Web Crypto API
doesn’t have asynchronous API.
### Custom Alphabet or Length

@@ -149,3 +173,3 @@

```js
var generate = require('nanoid/generate')
const generate = require('nanoid/generate')
model.id = generate('1234567890abcdef', 10) //=> "4f90d13a42"

@@ -171,7 +195,9 @@ ```

```js
var format = require('nanoid/format')
const format = require('nanoid/format')
function random (size) {
var result = []
for (var i = 0; i < size; i++) result.push(randomByte())
const result = []
for (let i = 0; i < size; i++) {
result.push(randomByte())
}
return result

@@ -190,3 +216,3 @@ }

```js
var url = require('nanoid/url')
const url = require('nanoid/url')
format(random, url, 10) //=> "93ce_Ltuub"

@@ -193,0 +219,0 @@ ```

@@ -8,3 +8,3 @@ /**

* @example
* var url = require('nanoid/url')
* const url = require('nanoid/url')
* generate(url, 10) //=> "Uakgb_J5m9"

@@ -11,0 +11,0 @@ */

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