Socket
Socket
Sign inDemoInstall

nanoid

Package Overview
Dependencies
0
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.2 to 1.0.0

3

CHANGELOG.md
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/).
## 1.0
* Use 21 symbols by default (by David Klebanoff).
## 0.2.2

@@ -5,0 +8,0 @@ * Reduce `nanoid/generate` size (by Anton Khlynovskiy).

2

format.js

@@ -7,3 +7,3 @@ /**

*
* @param {generator} random The random bytess generator.
* @param {random} random The random bytess generator.
* @param {string} alphabet Symbols to be used in new random string.

@@ -10,0 +10,0 @@ * @param {size} size The number of symbols in new random string.

@@ -8,6 +8,6 @@ var random = require('./random')

*
* By default, ID will have 22 symbols to have same collisions probability
* as UUID v4.
* By default, ID will have 21 symbols to have a collision probability similar
* to UUID v4.
*
* @param {number} [size=22] The number of symbols in ID.
* @param {number} [size=21] The number of symbols in ID.
*

@@ -18,3 +18,3 @@ * @return {string} Random string.

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

@@ -24,3 +24,3 @@ * @name nanoid

module.exports = function (size) {
size = size || 22
size = size || 21
var id = ''

@@ -27,0 +27,0 @@ var bytes = random(size)

{
"name": "nanoid",
"version": "0.2.2",
"version": "1.0.0",
"description": "A tiny (179 bytes), secure URL-friendly unique string ID generator",

@@ -19,12 +19,12 @@ "keywords": [

"benchmark": "^2.1.4",
"chalk": "^2.1.0",
"chalk": "^2.2.0",
"docdash": "^0.4.0",
"eslint": "^4.8.0",
"eslint": "^4.9.0",
"eslint-config-logux": "^16.2.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-es5": "^1.1.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jest": "^21.2.0",
"eslint-plugin-node": "^5.2.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-security": "^1.4.0",

@@ -35,3 +35,3 @@ "eslint-plugin-standard": "^3.0.1",

"jsdoc": "^3.5.5",
"lint-staged": "^4.2.3",
"lint-staged": "^4.3.0",
"microtime": "^2.1.6",

@@ -43,3 +43,3 @@ "pre-commit": "^1.2.2",

"uuid": "^3.1.0",
"webpack-dev-server": "^2.9.1",
"webpack-dev-server": "^2.9.3",
"yaspeller-ci": "^0.7.0"

@@ -46,0 +46,0 @@ },

# Nano ID
A tiny, secure URL-friendly unique string ID generator for JavaScript.
A tiny, secure, URL-friendly, unique string ID generator for JavaScript.

@@ -16,4 +16,4 @@ ```js

**Compact.** It uses more symbols than UUID (`A-Za-z0-9_~`)
and has the same number of unique options in just 22 symbols instead of 36.
**Compact.** It uses a larger alphabet than UUID (`A-Za-z0-9_~`)
and has a similar number of unique IDs in just 21 symbols instead of 36.

@@ -37,4 +37,4 @@ The generator supports Node.js and [all browsers] starting from IE 11.

Instead of unsafe `Math.random()` Nano ID uses `crypto` module in Node.js
and Web Crypto API in browsers.
Instead of using the unsafe `Math.random()`, Nano ID uses the `crypto` module
in Node.js and the Web Crypto API in browsers.

@@ -48,3 +48,3 @@ ### Uniformity

Nano ID uses a [better algorithm] and tests uniformity:
Nano ID uses a [better algorithm] and is tested for uniformity:

@@ -58,4 +58,5 @@ <img src="distribution.png" alt="Nano ID uniformity" width="340" height="135">

Nano ID is similar to UUID v4 (random-based). It uses the same number
of random bits in ID, so it has the same collision probability:
Nano ID is quite comparable to UUID v4 (random-based).
It has a similar number of random bits in the ID
(126 in Nano ID and 122 in UUID), so it has a similar collision probability:

@@ -65,7 +66,7 @@ > For there to be a one in a billion chance of duplication,

There are only 2 differences between Nano ID and UUID v4:
There are two main differences between Nano ID and UUID v4:
1. Nano ID uses a bigger alphabet for ID, so the same random bits
are packed in just 22 symbols instead of 36.
2. Nano ID code is 2 times smaller in size than `uuid/v4` package:
1. Nano ID uses a bigger alphabet, so a similar number of random bits
are packed in just 21 symbols instead of 36.
2. Nano ID code is less than half the size of the `uuid/v4` package:
179 bytes instead of 435.

@@ -89,3 +90,3 @@

The main module uses URL-friendly symbols (`A-Za-z0-9_~`) and returns an ID
with 22 characters (to have the same collisions probability as UUID v4).
with 21 characters (to have a collision probability similar to UUID v4).

@@ -97,7 +98,7 @@ ```js

Symbols `-,.()` are not encoded in URL, but in the end of a link
Symbols `-,.()` are not encoded in the URL. If used at the end of a link
they could be identified as a punctuation symbol.
If you want to reduce ID length (and increase collisions probability),
you can pass length as argument:
you can pass the length as an argument:

@@ -110,4 +111,4 @@ ```js

If you want to change the ID alphabet or the length
you can use low-level `generate` module.
If you want to change the ID's alphabet or length
you can use the low-level `generate` module.

@@ -119,8 +120,10 @@ ```js

Alphabet must contain less than 256 symbols.
Alphabet must contain 256 symbols or less.
Otherwise, the generator will not be secure.
### Custom Random Bytes Generator
You can replace the default safe random generator using the `format` module.
For instance, to use seed-based generator.
For instance, to use a seed-based generator.

@@ -143,3 +146,3 @@ ```js

If you want to use the same URL-friendly symbols with `format`,
you can get default alphabet from the `url` module:
you can get the default alphabet from the `url` module:

@@ -151,2 +154,3 @@ ```js

## Other Programming Languages

@@ -153,0 +157,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc