-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated doc format, introduced linting to avoid silly mistakes, bumpe…
…d REDUCE_TIME and VERSION for a smaller short id.
- Loading branch information
Showing
11 changed files
with
244 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ①②③④⑤⑥⑦⑧⑨⑩⑪⑫'); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.