Skip to content

Commit

Permalink
updated doc format, introduced linting to avoid silly mistakes, bumpe…
Browse files Browse the repository at this point in the history
…d REDUCE_TIME and VERSION for a smaller short id.
  • Loading branch information
dylang committed Oct 26, 2014
1 parent 5d2cec8 commit 56d981f
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 82 deletions.
13 changes: 13 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,
"undef": true,
"boss": true,
"eqnull": true,
"node": true
}
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
language: node_js
node_js:
- 0.8
- 0.10
- 0.11
- 0.11
127 changes: 68 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# ShortId [![Build Status](https://secure.travis-ci.org/dylang/shortid.png)](http://travis-ci.org/dylang/shortid)
## shortid [![shortid](http://img.shields.io/npm/v/shortid.svg?style=flat-square)](https://www.npmjs.org/package/shortid) [![shortid](http://img.shields.io/npm/dm/shortid.svg?style=flat-square)](https://www.npmjs.org/package/shortid) [![Build Status](http://img.shields.io/travis/dylang/shortid.svg?style=flat-square)](https://github.com/dylang/shortid)

> Amazingly short non-sequential url-friendly unique id generator.






[![NPM](https://nodei.co/npm/shortid.png?downloads=true)](https://nodei.co/npm/shortid/)

ShortId creates amazingly short non-sequential url-friendly unique ids. Perfect for url shorteners, MongoDB and Reddis ids, and any other id users might see.

Expand All @@ -13,19 +20,9 @@ ShortId creates amazingly short non-sequential url-friendly unique ids. Perfect
* Popular replacement for Mongo ID/Mongoose ID.
* Includes [Mocha](http://visionmedia.github.com/mocha/) tests.

- - -

## Install

```shell
$ npm install shortid --save
```

`shortid` has no dependencies.

- - -

## Usage
### Usage

```js
var shortId = require('shortid');
Expand All @@ -44,9 +41,9 @@ _id: {
},
```

- - -

## Example

### Example

```js
~/projects/shortid ❯ node examples/examples.js
Expand All @@ -62,11 +59,36 @@ a4vhAoFG
hwX6aOr7
```

- - -

## API
#### Real World Examples

`shortId` was created for Node Knockout 2011 winner for Most Fun [Doodle Or Die](http://doodleordie.com).
Millions of doodles have been saved with `shortId` filenames. Every log message gets a `shortId` to make it easy
for us to look up later.

Here are some other projects that use shortId:

* [bevy](https://npmjs.org/package/bevy) - A simple server to manage multiple Node services.
* [capre](https://npmjs.org/package/capre) - Cross-Server Data Replication.
* [cordova-build](https://www.npmjs.org/package/cordova-build) - an alternative to phonegap build that runs on your servers/agents.
* [couchdb-tools](https://www.npmjs.org/package/couchdb-tools) - A library of handy functions for use when working with CouchDB documents.
* [CleverStack/clever-email](https://github.com/CleverStack/clever-email) - E-mail system for CleverStack.
* [CloudTypes](https://github.com/ticup/CloudTypes) - JavaScript end2end implementation of the Cloud Types model for Eventual Consistency programming.
* [dnode-tarantula](https://github.com/jutaz/dnode-tarantula) - an asynchronous rpc and event system for node.js based on dnode-protocol and TCP sockets.
* [mongoose-url-shortener](https://www.npmjs.org/package/mongoose-url-shortener) - A simple URL Shortening library for NodeJS using Promises/A+ results.
* [mozilla/smokejumper](https://github.com/mozilla/smokejumper) - The Smoke Jumper project is an effort to bring dead simple, secure, P2P file sharing to Firefox.
* [shortness](https://npmjs.org/package/shortness) - Node based URL shortener that uses SQLite.
* [file-db](https://npmjs.org/package/file-db) - Document database that uses directories and files to store its data, supporting nested key-value objects in named collections.
* [resume-generator](https://www.npmjs.org/package/resume-generator) - Resume Generator.
* [riffmint](https://npmjs.org/package/riffmint) - Collaboration in musical space.
* [rap1ds/dippa](https://github.com/rap1ds/dippa) - Dippa Editor – A web-based LaTeX editor




### API

### `generate()`
#### `generate()`

Returns an amazingly short non-sequential unique id.

Expand All @@ -84,7 +106,7 @@ users.insert({

---------------------------------------

### `seed(float)`
#### `seed(float)`

__Default:__ `1`

Expand All @@ -104,7 +126,7 @@ shortId.seed(1000);

---------------------------------------

### `characters(string)`
#### `characters(string)`

__Default:__ `'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'`

Expand All @@ -128,54 +150,41 @@ shortId.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX
shortId.characters('ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ①②③④⑤⑥⑦⑧⑨⑩⑪⑫');
```

- - -

### Some projects using `shortId`

`shortId` was created for Node Knockout 2011 winner for Most Fun [Doodle Or Die](http://doodleordie.com).
Millions of doodles have been saved with `shortId` filenames. Every log message gets a `shortId` to make it easy
for us to look up later.

Here are some other projects that use shortId:

* [bevy](https://npmjs.org/package/bevy) - A simple server to manage multiple Node services.
* [capre](https://npmjs.org/package/capre) - Cross-Server Data Replication.
* [cordova-build](https://www.npmjs.org/package/cordova-build) - an alternative to phonegap build that runs on your servers/agents.
* [couchdb-tools](https://www.npmjs.org/package/couchdb-tools) - A library of handy functions for use when working with CouchDB documents.
* [CleverStack/clever-email](https://github.com/CleverStack/clever-email) - E-mail system for CleverStack.
* [CloudTypes](https://github.com/ticup/CloudTypes) - JavaScript end2end implementation of the Cloud Types model for Eventual Consistency programming.
* [dnode-tarantula](https://github.com/jutaz/dnode-tarantula) - an asynchronous rpc and event system for node.js based on dnode-protocol and TCP sockets.
* [mongoose-url-shortener](https://www.npmjs.org/package/mongoose-url-shortener) - A simple URL Shortening library for NodeJS using Promises/A+ results.
* [mozilla/smokejumper](https://github.com/mozilla/smokejumper) - The Smoke Jumper project is an effort to bring dead simple, secure, P2P file sharing to Firefox.
* [shortness](https://npmjs.org/package/shortness) - Node based URL shortener that uses SQLite.
* [file-db](https://npmjs.org/package/file-db) - Document database that uses directories and files to store its data, supporting nested key-value objects in named collections.
* [resume-generator](https://www.npmjs.org/package/resume-generator) - Resume Generator.
* [riffmint](https://npmjs.org/package/riffmint) - Collaboration in musical space.
* [rap1ds/dippa](https://github.com/rap1ds/dippa) - Dippa Editor – A web-based LaTeX editor

### About the Author [![@dylang](https://img.shields.io/badge/github-dylang-green.svg?style=flat-square)](https://github.com/dylang) [![@dylang](https://img.shields.io/badge/twitter-dylang-blue.svg?style=flat-square)](https://twitter.com/dylang)

Hi! Thanks for checking {{shortid}}! My name is **Dylan Greene**. When not overwhelmed with my two young kids I enjoy contributing
to the open source community. I'm also a tech lead at [Opower](http://opower.com).

Here's some of my other Node projects:

| Name | Description | npm Downloads |
|---|---|--:|--:|
| [`grunt‑notify`](https://github.com/dylang/grunt-notify) | Automatic desktop notifications for Grunt errors and warnings using Growl for OS X or Windows, Mountain Lion and Mavericks Notification Center, and Notify-Send. | [![grunt-notify](https://img.shields.io/npm/dm/grunt-notify.svg?style=flat-square)](https://www.npmjs.org/package/grunt-notify) |
| [`grunt‑prompt`](https://github.com/dylang/grunt-prompt) | Interactive prompt for your Grunt config using console checkboxes, text input with filtering, password fields. | [![grunt-prompt](https://img.shields.io/npm/dm/grunt-prompt.svg?style=flat-square)](https://www.npmjs.org/package/grunt-prompt) |
| [`rss`](https://github.com/dylang/node-rss) | RSS feed generator. Add RSS feeds to any project. Supports enclosures and GeoRSS. | [![rss](https://img.shields.io/npm/dm/rss.svg?style=flat-square)](https://www.npmjs.org/package/rss) |
| [`xml`](https://github.com/dylang/node-xml) | Fast and simple xml generator. Supports attributes, CDATA, etc. Includes tests and examples. | [![xml](https://img.shields.io/npm/dm/xml.svg?style=flat-square)](https://www.npmjs.org/package/xml) |
| [`changelog`](https://github.com/dylang/changelog) | Command line tool (and Node module) that generates a changelog in color output, markdown, or json for modules in npmjs.org's registry as well as any public github.com repo. | [![changelog](https://img.shields.io/npm/dm/changelog.svg?style=flat-square)](https://www.npmjs.org/package/changelog) |
| [`npm‑check`](https://github.com/dylang/npm-check) | Check for outdated, incorrect, and unused dependencies. | [![npm-check](https://img.shields.io/npm/dm/npm-check.svg?style=flat-square)](https://www.npmjs.org/package/npm-check) |
| [`grunt‑attention`](https://github.com/dylang/grunt-attention) | Display attention-grabbing messages in the terminal | [![grunt-attention](https://img.shields.io/npm/dm/grunt-attention.svg?style=flat-square)](https://www.npmjs.org/package/grunt-attention) |
| [`observatory`](https://github.com/dylang/observatory) | Beautiful UI for showing tasks running on the command line. | [![observatory](https://img.shields.io/npm/dm/observatory.svg?style=flat-square)](https://www.npmjs.org/package/observatory) |
| [`anthology`](https://github.com/dylang/anthology) | Module information and stats for any @npmjs user | [![anthology](https://img.shields.io/npm/dm/anthology.svg?style=flat-square)](https://www.npmjs.org/package/anthology) |
| [`grunt‑cat`](https://github.com/dylang/grunt-cat) | Echo a file to the terminal. Works with text, figlets, ascii art, and full-color ansi. | [![grunt-cat](https://img.shields.io/npm/dm/grunt-cat.svg?style=flat-square)](https://www.npmjs.org/package/grunt-cat) |

- - -
_This list was generated using [anthology](https://github.com/dylang/anthology)._

## License

(The MIT License)
### License
Copyright (c) 2014 Dylan Greene, contributors.

Copyright (c) 2011-2014 Dylan Greene <dylang@gmail.com>
Released under the [MIT license](https://tldrlegal.com/license/mit-license).

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Screenshots are [CC BY-SA](http://creativecommons.org/licenses/by-sa/4.0/) (Attribution-ShareAlike).

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
***
_Generated using [grunt-readme](https://github.com/assemble/grunt-readme) with [grunt-templates-dylang](https://github.com/dylang/grunt-templates-dylang) on Sunday, October 26, 2014._

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
33 changes: 17 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"name": "shortid",
"version": "2.0.1",
"description": "Amazingly short non-sequential url-friendly unique id generator.",
"main": "shortid.js",
"scripts": {
"test": "grunt test"
},
"keywords": [
"short",
"tiny",
Expand All @@ -14,30 +18,27 @@
"tinyid"
],
"homepage": "https://github.com/dylang/shortid",
"author": {
"name": "Dylan Greene",
"email": "dylang@gmail.com"
},
"author": {
"name": "Dylan Greene",
"email": "dylang@gmail.com"
},
"repository": {
"type": "git",
"url": "https://github.com/dylang/shortid"
},
"dependencies": {},
"devDependencies": {
"chai": "~1.9.1",
"mocha": "~1.20.1"
"grunt": "^0.4.5",
"grunt-contrib-jshint": "^0.10.0",
"grunt-mocha-test": "^0.12.2",
"grunt-release": "^0.7.0",
"grunt-templates-dylang": "^1.0.1",
"load-grunt-tasks": "^1.0.0",
"mocha": "~2.0.1",
"time-grunt": "^1.0.0"
},
"main": "shortid.js",
"engines": {
"node": ">=0.8.x"
},
"scripts": {
"test": "./node_modules/.bin/mocha --reporter spec"
},
"licenses": [
{
"type": "MIT",
"url": "https://raw.github.com/dylang/shortid/master/LICENSE"
}
]
"license": "MIT"
}
4 changes: 2 additions & 2 deletions shortid.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ var alphabet = require('./lib/alphabet'),
// Ignore all milliseconds before a certain time to reduce the size of the date entropy without sacrificing uniqueness.
// This number should be updated every year or so to keep the generated id short.
// To regenerate `new Date() - 0` and bump the version. Always bump the version!
var REDUCE_TIME = 1403265799803;
var REDUCE_TIME = 1414337829912;

// don't change unless we change the algos or REDUCE_TIME
// must be an integer and less than 16
var version = 2;
var version = 3;

// if you are using cluster or multiple servers use this to make each instance
// has a unique value for worker
Expand Down
64 changes: 64 additions & 0 deletions templates/readme/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## API

### `generate()`

Returns an amazingly short non-sequential unique id.

__Alias:__ `shortId()`

__Example__

```js
users.insert({
_id: shortId.generate()
name: ...
email: ...
});
```

---------------------------------------

### `seed(float)`

__Default:__ `1`

__Optional__

Choose a unique value that will seed the random number generator so users won't be able to figure out the pattern of the unique ids. Call it just once in your application before using `shortId` and always use the same value in your application.

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

If you are worried about users somehow decrypting the id then use it as a secret value for increased encryption.

__Example__

```js
shortId.seed(1000);
```

---------------------------------------

### `characters(string)`

__Default:__ `'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'`

__Optional__

Change the characters used.

You must provide a string of all 64 unique characters. Order is not important.

The default characters provided were selected because they are url safe.

__Example__

```js
// use $ and @ instead of - an _
shortId.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$@');
```

```js
// any 64 unicode charcters work
shortId.characters('ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ①②③④⑤⑥⑦⑧⑨⑩⑪⑫');
```

40 changes: 40 additions & 0 deletions templates/readme/examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Example

```js
~/projects/shortid ❯ node examples/examples.js
eWRhpRV
23TplPdS
46Juzcyx
dBvJIh-H
2WEKaVNO
7oet_d9Z
dogPzIz8
nYrnfYEv
a4vhAoFG
hwX6aOr7
```


### Real World Examples

`shortId` was created for Node Knockout 2011 winner for Most Fun [Doodle Or Die](http://doodleordie.com).
Millions of doodles have been saved with `shortId` filenames. Every log message gets a `shortId` to make it easy
for us to look up later.

Here are some other projects that use shortId:

* [bevy](https://npmjs.org/package/bevy) - A simple server to manage multiple Node services.
* [capre](https://npmjs.org/package/capre) - Cross-Server Data Replication.
* [cordova-build](https://www.npmjs.org/package/cordova-build) - an alternative to phonegap build that runs on your servers/agents.
* [couchdb-tools](https://www.npmjs.org/package/couchdb-tools) - A library of handy functions for use when working with CouchDB documents.
* [CleverStack/clever-email](https://github.com/CleverStack/clever-email) - E-mail system for CleverStack.
* [CloudTypes](https://github.com/ticup/CloudTypes) - JavaScript end2end implementation of the Cloud Types model for Eventual Consistency programming.
* [dnode-tarantula](https://github.com/jutaz/dnode-tarantula) - an asynchronous rpc and event system for node.js based on dnode-protocol and TCP sockets.
* [mongoose-url-shortener](https://www.npmjs.org/package/mongoose-url-shortener) - A simple URL Shortening library for NodeJS using Promises/A+ results.
* [mozilla/smokejumper](https://github.com/mozilla/smokejumper) - The Smoke Jumper project is an effort to bring dead simple, secure, P2P file sharing to Firefox.
* [shortness](https://npmjs.org/package/shortness) - Node based URL shortener that uses SQLite.
* [file-db](https://npmjs.org/package/file-db) - Document database that uses directories and files to store its data, supporting nested key-value objects in named collections.
* [resume-generator](https://www.npmjs.org/package/resume-generator) - Resume Generator.
* [riffmint](https://npmjs.org/package/riffmint) - Collaboration in musical space.
* [rap1ds/dippa](https://github.com/rap1ds/dippa) - Dippa Editor – A web-based LaTeX editor

10 changes: 10 additions & 0 deletions templates/readme/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ShortId creates amazingly short non-sequential url-friendly unique ids. Perfect for url shorteners, MongoDB and Reddis ids, and any other id users might see.

* 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.
* Can generate any number of ids without duplicates, even millions per day.
* Perfect for games, especially if you are concerned about cheating so you don't want an easily guessable id.
* Apps can be restarted any number of times without any chance of repeating an id.
* Popular replacement for Mongo ID/Mongoose ID.
* Includes [Mocha](http://visionmedia.github.com/mocha/) tests.
Loading

0 comments on commit 56d981f

Please sign in to comment.