Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ai/nanoid
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.1.4
Choose a base ref
...
head repository: ai/nanoid
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2.1.5
Choose a head ref
  • 8 commits
  • 7 files changed
  • 2 contributors

Commits on Oct 20, 2019

  1. Normalize docs

    ai committed Oct 20, 2019
    Copy the full SHA
    661782f View commit details

Commits on Oct 22, 2019

  1. shrink more 4 bytes

    MaxGraey committed Oct 22, 2019
    Copy the full SHA
    5051e85 View commit details
  2. update size limits

    MaxGraey committed Oct 22, 2019
    Copy the full SHA
    62aa443 View commit details
  3. Merge pull request #152 from MaxGraey/minor-improcments

    Shave 3 bytes in generate & async/generate again
    ai authored Oct 22, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d0b1ea7 View commit details
  4. Copy the full SHA
    84abeb5 View commit details

Commits on Oct 23, 2019

  1. Update dependencies

    ai committed Oct 23, 2019
    Copy the full SHA
    6bc5e34 View commit details
  2. Remove Node.js 13 from CI

    ai committed Oct 23, 2019
    Copy the full SHA
    3db8be6 View commit details
  3. Release 2.1.5 version

    ai committed Oct 23, 2019
    Copy the full SHA
    4afb142 View commit details
Showing with 101 additions and 100 deletions.
  1. +1 −1 .travis.yml
  2. +4 −0 CHANGELOG.md
  3. +5 −2 README.md
  4. +7 −7 async/format.js
  5. +6 −7 format.js
  6. +4 −4 package.json
  7. +74 −79 yarn.lock
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
cache: yarn
node_js:
- node
- "12"
- "10"
- "8"
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/).

## 2.1.5
* Reduce size (by Max Graey).
* Fix IE support.

## 2.1.4
* Reduce `generate` size (by Vsevolod Rodionov).
* Reduce `format` and `format` size (by Victor).
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ A tiny, secure, URL-friendly, unique string ID generator for JavaScript.
So ID size was reduced from 36 to 21 symbols.

```js
var nanoid = require('nanoid')
const nanoid = require('nanoid')
model.id = nanoid() //=> "V1StGXR8_Z5jdHi6B-myT"
```

@@ -161,6 +161,9 @@ nanoid(10) //=> "IRFa-VaY2b"
Don’t forget to check the safety of your ID length
in our [ID collision probability] calculator.

You can also use [custom alphabet](#custom-alphabet-or-length)
or [random generator](#custom-random-bytes-generator).

[ID collision probability]: https://zelark.github.io/nano-id-cc/


@@ -248,7 +251,7 @@ probability.

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


14 changes: 7 additions & 7 deletions async/format.js
Original file line number Diff line number Diff line change
@@ -29,17 +29,17 @@
* @function
*/
module.exports = function (random, alphabet, size) {
var mask = (2 << 31 - Math.clz32((alphabet.length - 1) | 1)) - 1
var mask = (2 << Math.log(alphabet.length - 1) / Math.LN2) - 1
var step = Math.ceil(1.6 * mask * size / alphabet.length)
size = +size

function tick (id) {
return random(step).then(function (bytes) {
for (var i = step; i--;) {
var byte = bytes[i] & mask
if (alphabet[byte]) {
id += alphabet[byte]
if (id.length === size) return id
var i = step
while (i--) {
var alpha = alphabet[bytes[i] & mask]
if (alpha) {
id += alpha
if (id.length === +size) return id
}
}
return tick(id)
13 changes: 6 additions & 7 deletions format.js
Original file line number Diff line number Diff line change
@@ -27,19 +27,18 @@
* @function
*/
module.exports = function (random, alphabet, size) {
var mask = (2 << 31 - Math.clz32((alphabet.length - 1) | 1)) - 1
var mask = (2 << Math.log(alphabet.length - 1) / Math.LN2) - 1
var step = Math.ceil(1.6 * mask * size / alphabet.length)
var id = ''
size = +size

while (true) {
var bytes = random(step)
for (var i = step; i--;) {
var byte = bytes[i] & mask
var alpha = alphabet[byte]
var i = step
var bytes = random(i)
while (i--) {
var alpha = alphabet[bytes[i] & mask]
if (alpha) {
id += alpha
if (id.length === size) return id
if (id.length === +size) return id
}
}
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nanoid",
"version": "2.1.4",
"version": "2.1.5",
"description": "A tiny (139 bytes), secure URL-friendly unique string ID generator",
"keywords": [
"uuid",
@@ -41,7 +41,7 @@
"eslint-config-standard": "^14.1.0",
"eslint-plugin-es5": "^1.4.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^22.19.0",
"eslint-plugin-jest": "^22.20.0",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-prefer-let": "^1.0.1",
"eslint-plugin-promise": "^4.2.1",
@@ -70,7 +70,7 @@
},
{
"path": "generate.js",
"limit": "174 B"
"limit": "173 B"
},
{
"path": "url.js",
@@ -90,7 +90,7 @@
},
{
"path": "async/generate.js",
"limit": "199 B"
"limit": "198 B"
}
],
"eslintConfig": {
Loading