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.1.0 to 0.1.1

3

CHANGELOG.md
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/).
## 0.1.1
* Reduce library size by 5%.
## 0.1
* Initial release.

6

format.js

@@ -31,3 +31,3 @@ /**

var id = ''
while (id.length !== size) {
while (true) {
bytes = random(step)

@@ -38,8 +38,6 @@ for (var i = 0; i < bytes.length; i++) {

id += alphabet[byte]
if (id.length === size) break
if (id.length === size) return id
}
}
}
return id
}

@@ -46,0 +44,0 @@

@@ -1,2 +0,3 @@

var generate = require('./generate')
var format = require('./format')
var random = require('./random')
var url = require('./url')

@@ -16,3 +17,3 @@

module.exports = function () {
return generate(url, 22)
return format(random, url, 22)
}
{
"name": "nanoid",
"version": "0.1.0",
"description": "Very small secure URL-friendly unique ID generator",
"version": "0.1.1",
"description": "A tiny, secure URL-friendly unique string ID generator",
"keywords": [

@@ -19,3 +19,3 @@ "uuid",

"docdash": "^0.4.0",
"eslint": "^4.4.0",
"eslint": "^4.4.1",
"eslint-config-logux": "^16.0.0",

@@ -33,6 +33,6 @@ "eslint-config-standard": "^10.2.1",

"jsdoc": "^3.5.4",
"lint-staged": "^4.0.2",
"lint-staged": "^4.0.3",
"pre-commit": "^1.2.2",
"size-limit": "^0.8.0",
"webpack-dev-server": "^2.6.1",
"size-limit": "^0.8.1",
"webpack-dev-server": "^2.7.1",
"yaspeller-ci": "^0.6.0"

@@ -61,3 +61,3 @@ },

"path": "index.js",
"limit": "260 B"
"limit": "246 B"
}

@@ -64,0 +64,0 @@ ],

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

@@ -10,13 +10,15 @@ ```js

**Safe.** It uses cryptographically-strong random APIs
and tests symbols distribution.
**Safe.** It uses cryptographically strong random APIs
and guarantees a proper distribution of symbols.
**Small.** Only 258 bytes (minified and gzipped). Zero-dependency.
**Small.** Only 246 bytes (minified and gzipped). No dependencies.
It uses [Size Limit] to control size.
**Compact.** It uses more symbols than UUID (`A-Za-z0-9_~`)
and have same uniqueness in 22 symbols instead of 36.
and has the same number of unique options in just 22 symbols instead of 36.
Generator supports Node.js and [all browsers] from IE 11.
The generator supports Node.js and [all browsers] starting from IE 11.
[all browsers]: http://caniuse.com/#feat=getrandomvalues
[Size Limit]: https://github.com/ai/size-limit

@@ -30,3 +32,3 @@ <a href="https://evilmartians.com/?utm_source=nanoid">

*Good article about random generators theory:
*See a good article about random generators theory:
[Secure random values (in Node.js)]*

@@ -36,3 +38,3 @@

Nano ID doesn’t use unsafe `Math.random()`. It use `crypto` module in Node.js
Instead of unsafe `Math.random()` Nano ID uses `crypto` module in Node.js
and Web Crypto API in browsers.

@@ -42,6 +44,8 @@

`random % alphabet` is a popular mistake in ID generator. Change to get some
symbols will be lower and it will reduce amount of guesses in bruteforcing.
`random % alphabet` is a popular mistake to make when coding an ID generator.
The spread will not be even; there will be a lower chance for some symbols
to appear compared to others—so it will reduce the number of tries
when brute-forcing.
Nano ID use [better algorithm] and test uniformity:
Nano ID uses a [better algorithm] and tests uniformity:

@@ -53,2 +57,17 @@ <img src="distribution.png" alt="Nano ID uniformity" width="340" height="135">

## Comparison with UUID
Nano ID is similar to UUID v4 (random-based). It uses same number of random bits
in ID, so it has same collision probability:
> For there to be a one in a billion chance of duplication,
> 103 trillion version 4 IDs must be generated.
There are only 2 differences between Nano ID and UUID v4:
1. Nano ID uses bigger alphabet for ID, so same random bits
are packed just in 22 symbols instead of 36.
2. Code of Nano ID has 2 times smaller size compare to `uuid/v4` package:
246 bytes instead of 435.
## Usage

@@ -58,4 +77,4 @@

Main module uses URL-friendly symbols (`A-Za-z0-9_~`) and return ID
with 22 characters (to have same uniqueness as UUID).
The main module uses URL-friendly symbols (`A-Za-z0-9_~`) and returns an ID
with 22 characters (to have the same uniqueness as UUID v4).

@@ -67,9 +86,9 @@ ```js

Symbols `-,.()` are not encoded in URL, but in the end of link they could
be detected as punctuation.
Symbols `-,.()` are not encoded in URL, but in the end of a link
they could be identified as a punctuation symbol.
### Custom Alphabet or Length
If you want to change ID alphabet or length you can use low-level `generate`
module.
If you want to change the ID alphabet or the length
you can use low-level `generate` module.

@@ -81,4 +100,4 @@ ```js

If you want to use same URL-friendly symbols and just change length,
you can get default alphabet from `url` module:
If you want to use the same URL-friendly symbols and just change the length,
you can get default alphabet from the `url` module:

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

You can replace default safe random generators by `format` module.
It could be useful if you need seed-based generator.
You can replace the default safe random generator using the `format` module.
For instance, to use seed-based generator.

@@ -108,2 +127,3 @@ ```js

`random` callback must accept array size and return array of random numbers.
`random` callback must accept the array size and return an array
with random numbers.
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