Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shortid

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shortid - npm Package Compare versions

Comparing version 2.2.8 to 2.2.9

lib/generate.js

6

CHANGELOG.md
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/).
## 2.2.9
* Fix symbols probability uniformity by using Nano ID (by @shashkovdanil).
* Improve ID generation perfomance.
* Fix `shortid.isValid` with custom alphabet.
* Improve `shortid.isValid` perfomance (by @s7b5en).E
## 2.2.8
* Clean npm package from unnecessary files.

@@ -93,3 +93,8 @@ 'use strict';

function get () {
return alphabet;
}
module.exports = {
get: get,
characters: characters,

@@ -96,0 +101,0 @@ seed: setSeed,

12

lib/build.js
'use strict';
var encode = require('./encode');
var generate = require('./generate');
var alphabet = require('./alphabet');

@@ -26,3 +26,2 @@

function build(clusterWorkerId) {
var str = '';

@@ -39,9 +38,8 @@

str = str + encode(alphabet.lookup, version);
str = str + encode(alphabet.lookup, clusterWorkerId);
str = str + generate(version);
str = str + generate(clusterWorkerId);
if (counter > 0) {
str = str + encode(alphabet.lookup, counter);
str = str + generate(counter);
}
str = str + encode(alphabet.lookup, seconds);
str = str + generate(seconds);
return str;

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

'use strict';
var alphabet = require('./alphabet');
var encode = require('./encode');
var decode = require('./decode');
var build = require('./build');

@@ -64,3 +62,2 @@ var isValid = require('./is-valid');

module.exports.characters = characters;
module.exports.decode = decode;
module.exports.isValid = isValid;

@@ -9,12 +9,8 @@ 'use strict';

var characters = alphabet.characters();
var len = id.length;
for(var i = 0; i < len;i++) {
if (characters.indexOf(id[i]) === -1) {
return false;
}
}
return true;
var nonAlphabetic = new RegExp('[^' +
alphabet.get().replace(/[|\\{}()[\]^$+*?.-]/g, '\\$&') +
']');
return !nonAlphabetic.test(id);
}
module.exports = isShortId;
'use strict';
module.exports = parseInt(process.env.NODE_UNIQUE_ID || 0, 10);
var cluster = require('cluster');
var clusterId = cluster.isMaster ? 0 : cluster.worker.id;
module.exports = parseInt(process.env.NODE_UNIQUE_ID || clusterId, 10);
{
"name": "shortid",
"version": "2.2.8",
"version": "2.2.9",
"description": "Amazingly short non-sequential url-friendly unique id generator.",

@@ -8,4 +8,3 @@ "main": "index.js",

"build": "grunt build",
"test": "grunt test",
"readme": "grunt repos readme"
"test": "grunt test && size-limit"
},

@@ -33,24 +32,26 @@ "keywords": [

"browser": {
"./lib/util/cluster-worker-id.js": "./lib/util/cluster-worker-id-browser.js",
"./lib/random/random-byte.js": "./lib/random/random-byte-browser.js"
"./lib/util/cluster-worker-id.js": "./lib/util/cluster-worker-id-browser.js"
},
"devDependencies": {
"chai": "^3.3.0",
"envify": "^3.4.0",
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-browserify": "^3.6.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-jshint": "^0.11.3",
"grunt-contrib-uglify": "^0.9.2",
"grunt-mocha-test": "^0.12.7",
"chai": "^4.1.2",
"envify": "^4.1.0",
"grunt": "^1.0.3",
"grunt-browserify": "^5.3.0",
"grunt-cli": "^1.2.0",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-uglify": "^3.3.0",
"grunt-mocha-test": "^0.13.3",
"grunt-notify": "^0.4.1",
"grunt-open": "^0.2.3",
"grunt-release": "^0.13.0",
"grunt-templates-dylang": "^1.0.10",
"load-grunt-tasks": "^3.3.0",
"mocha": "^2.3.3",
"grunt-release": "^0.14.0",
"load-grunt-tasks": "^4.0.0",
"mocha": "^5.2.0",
"size-limit": "^0.18.3",
"time-grunt": "^1.2.1"
},
"license": "MIT"
"license": "MIT",
"dependencies": {
"nanoid": "^1.0.5"
}
}

@@ -15,3 +15,2 @@ ## shortid [![Build Status](http://img.shields.io/travis/dylang/shortid.svg)](https://travis-ci.org/dylang/shortid) [![shortid](http://img.shields.io/npm/dm/shortid.svg)](https://www.npmjs.org/package/shortid)

* By default 7-14 url-friendly characters: `A-Z`, `a-z`, `0-9`, `_-`
* Non-sequential so they are not predictable.
* Supports `cluster` (automatically), custom seeds, custom alphabet.

@@ -23,3 +22,3 @@ * Can generate any number of ids without duplicates, even millions per day.

* Works in Node, io.js, and web browsers.
* Includes [Mocha](http://visionmedia.github.com/mocha/) tests.
* Includes [Mocha](http://mochajs.org/) tests.

@@ -34,3 +33,3 @@

console.log(shortid.generate());
//PPBqWA9
// PPBqWA9
```

@@ -41,4 +40,4 @@

_id: {
type: String,
'default': shortid.generate
'type': String,
'default': shortid.generate
},

@@ -66,3 +65,3 @@ ```

```js
```bash
~/projects/shortid ❯ node examples/examples.js

@@ -110,3 +109,5 @@ eWRhpRV

`var shortid = require('shortid');`
```js
var shortid = require('shortid');
```

@@ -123,6 +124,6 @@ ---------------------------------------

users.insert({
_id: shortid.generate()
name: ...
email: ...
});
_id: shortid.generate(),
name: '...',
email: '...'
});
```

@@ -132,9 +133,9 @@

#### `characters(string)`
#### `shortid.characters(string)`
__Default:__ `'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'`
__Returns__ new alphabet as a `string`
__Returns__ new alphabet as a `string`
__Recommendation:__ If you don't like _ or -, you can to set new characters to use.
__Recommendation:__ If you don't like _ or -, you can to set new characters to use.

@@ -164,3 +165,3 @@ __Optional__

#### `isValid(id)`
#### `shortid.isValid(id)`

@@ -193,5 +194,5 @@ __Returns__ `boolean`

If you are running multiple server processes then you should make sure every one has a unique `worker` id. Should be an integer between 0 and 16.
If you do not do this there is very little chance of two servers generating the same id, but it is theoretically possible
if both are generated in the exact same second and are generating the same number of ids that second and a half-dozen random numbers are all exactly the same.
If you are running multiple server processes then you should make sure every one has a unique `worker` id. Should be an integer between 0 and 16.
If you do not do this there is very little chance of two servers generating the same id, but it is theoretically possible
if both are generated in the exact same second and are generating the same number of ids that second and a half-dozen random numbers are all exactly the same.

@@ -216,3 +217,3 @@ __Example__

Most developers won't need to use this, it's mainly for testing ShortId.
Most developers won't need to use this, it's mainly for testing ShortId.

@@ -262,6 +263,1 @@ If you are worried about users somehow decrypting the id then use it as a secret value for increased encryption.

Screenshots are [CC BY-SA](http://creativecommons.org/licenses/by-sa/4.0/) (Attribution-ShareAlike).
***
_Generated using [grunt-readme](https://github.com/assemble/grunt-readme) with [grunt-templates-dylang](https://github.com/dylang/grunt-templates-dylang) on Sunday, April 3, 2016._
_To make changes to this document look in `/templates/readme/`
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