arnaucube
arnaucube/comunicationLeapPublic Self-hosted repository
comunicationLeap/node_modules/shortid/README.md
node_modules/shortid/README.mdRaw
  1## 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)
  2
  3> Amazingly short non-sequential url-friendly unique id generator.
  4
  5
  6
  7
  8
  9
 10
 11
 12ShortId creates amazingly short non-sequential url-friendly unique ids.  Perfect for url shorteners, MongoDB and Reddis ids, and any other id users might see.
 13
 14 * By default 7-14 url-friendly characters: `A-Z`, `a-z`, `0-9`, `_-`
 15 * Non-sequential so they are not predictable.
 16 * Supports `cluster` (automatically), custom seeds, custom alphabet.
 17 * Can generate any number of ids without duplicates, even millions per day.
 18 * Perfect for games, especially if you are concerned about cheating so you don't want an easily guessable id.
 19 * Apps can be restarted any number of times without any chance of repeating an id.
 20 * Popular replacement for Mongo ID/Mongoose ID.
 21 * Works in Node, io.js, and web browsers.
 22 * Includes [Mocha](http://visionmedia.github.com/mocha/) tests.
 23
 24
 25
 26### Usage
 27
 28```js
 29var shortid = require('shortid');
 30
 31console.log(shortid.generate());
 32//PPBqWA9
 33```
 34
 35Mongoose Unique Id
 36```js
 37_id: {
 38    type: String,
 39    unique: true,
 40    'default': shortid.generate
 41},
 42```
 43
 44
 45
 46### Browser Compatibility
 47
 48The best way to use `shortid` in the browser is via [browserify](http://browserify.org/) or [webpack](http://webpack.github.io/).
 49
 50These tools will automatically only include the files necessary for browser compatibility.
 51
 52All tests will run in the browser as well:
 53
 54```bash
 55## build the bundle, then open Mocha in a browser to see the tests run.
 56$ grunt build open
 57```
 58
 59
 60
 61### Example
 62
 63```js
 64~/projects/shortid ❯ node examples/examples.js
 65eWRhpRV
 6623TplPdS
 6746Juzcyx
 68dBvJIh-H
 692WEKaVNO
 707oet_d9Z
 71dogPzIz8
 72nYrnfYEv
 73a4vhAoFG
 74hwX6aOr7
 75```
 76
 77
 78#### Real World Examples
 79
 80`shortId` was created for Node Knockout 2011 winner for Most Fun [Doodle Or Die](http://doodleordie.com).
 81Millions of doodles have been saved with `shortId` filenames. Every log message gets a `shortId` to make it easy
 82for us to look up later.
 83
 84Here are some other projects that use shortId:
 85
 86* [bevy](https://npmjs.org/package/bevy) - A simple server to manage multiple Node services.
 87* [capre](https://npmjs.org/package/capre) - Cross-Server Data Replication.
 88* [cordova-build](https://www.npmjs.org/package/cordova-build) - an alternative to phonegap build that runs on your servers/agents.
 89* [couchdb-tools](https://www.npmjs.org/package/couchdb-tools) - A library of handy functions for use when working with CouchDB documents.
 90* [CleverStack/clever-email](https://github.com/CleverStack/clever-email) - E-mail system for CleverStack.
 91* [CloudTypes](https://github.com/ticup/CloudTypes) - JavaScript end2end implementation of the Cloud Types model for Eventual Consistency programming.
 92* [dnode-tarantula](https://github.com/jutaz/dnode-tarantula) - an asynchronous rpc and event system for node.js based on dnode-protocol and TCP sockets.
 93* [mongoose-url-shortener](https://www.npmjs.org/package/mongoose-url-shortener) - A simple URL Shortening library for NodeJS using Promises/A+ results.
 94* [mozilla/smokejumper](https://github.com/mozilla/smokejumper) - The Smoke Jumper project is an effort to bring dead simple, secure, P2P file sharing to Firefox.
 95* [shortness](https://npmjs.org/package/shortness) - Node based URL shortener that uses SQLite.
 96* [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.
 97* [resume-generator](https://www.npmjs.org/package/resume-generator) - Resume Generator.
 98* [riffmint](https://npmjs.org/package/riffmint) - Collaboration in musical space.
 99* [rap1ds/dippa](https://github.com/rap1ds/dippa) - Dippa Editor – A web-based LaTeX editor
100
101
102
103
104### API
105
106`var shortid = require('shortid');`
107
108---------------------------------------
109
110#### `shortid.generate()`
111
112__Returns__ `string` non-sequential unique id.
113
114__Example__
115
116```js
117users.insert({
118    _id: shortid.generate()
119    name: ...
120    email: ...
121    });
122```
123
124---------------------------------------
125
126#### `characters(string)`
127
128__Default:__ `'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'`
129
130__Returns__ new alphabet as a `string` 
131
132__Recommendation:__ If you don't like _ or -, you can to set new characters to use. 
133
134__Optional__
135
136Change the characters used.
137
138You must provide a string of all 64 unique characters. Order is not important.
139
140The default characters provided were selected because they are url safe.
141
142__Example__
143
144```js
145// use $ and @ instead of - and _
146shortid.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$@');
147```
148
149```js
150// any 64 unicode characters work, but I wouldn't recommend this.
151shortid.characters('ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ①②③④⑤⑥⑦⑧⑨⑩⑪⑫');
152```
153
154
155---------------------------------------
156
157#### `isValid(id)`
158
159__Returns__ `boolean`
160
161Check to see if an id is a valid `shortid`. Note: This only means the id _could_ have been generated by `shortid`, it doesn't guarantee it.
162
163__Example__
164
165```js
166shortid.isValid('41XTDbE');
167// true
168```
169
170```js
171shortid.isValid('i have spaces');
172// false
173```
174
175---------------------------------------
176
177#### `shortid.worker(integer)`
178
179__Default:__ `process.env.NODE_UNIQUE_ID || 0`
180
181__Recommendation:__ You typically won't want to change this.
182
183__Optional__
184
185If 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. 
186If you do not do this there is very little chance of two servers generating the same id, but it is theatrically possible 
187if 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. 
188
189__Example__
190
191```js
192shortId.seed(1000);
193```
194
195---------------------------------------
196
197#### `shortid.seed(float)`
198
199__Default:__ `1`
200
201__Recommendation:__ You typically won't want to change this.
202
203__Optional__
204
205Choose 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.
206
207Most developers won't need to use this, it's mainly for testing ShortId. 
208
209If you are worried about users somehow decrypting the id then use it as a secret value for increased encryption.
210
211__Example__
212
213```js
214shortId.seed(1000);
215```
216
217
218
219
220
221
222### About the Author
223
224Hi! Thanks for checking out this project! My name is **Dylan Greene**. When not overwhelmed with my two young kids I enjoy contributing
225to the open source community. I'm also a tech lead at [Opower](http://opower.com). [![@dylang](https://img.shields.io/badge/github-dylang-green.svg)](https://github.com/dylang) [![@dylang](https://img.shields.io/badge/twitter-dylang-blue.svg)](https://twitter.com/dylang)
226
227Here's some of my other Node projects:
228
229| Name | Description | npm Downloads |
230|---|---|---|
231| [`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) |
232| [`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) |
233| [`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) |
234| [`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) |
235| [`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) |
236| [`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) |
237| [`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) |
238| [`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) |
239| [`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) |
240| [`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) |
241
242_This list was generated using [anthology](https://github.com/dylang/anthology)._
243
244
245### License
246Copyright (c) 2015 Dylan Greene, contributors.
247
248Released under the [MIT license](https://tldrlegal.com/license/mit-license).
249
250Screenshots are [CC BY-SA](http://creativecommons.org/licenses/by-sa/4.0/) (Attribution-ShareAlike).
251
252***
253_Generated using [grunt-readme](https://github.com/assemble/grunt-readme) with [grunt-templates-dylang](https://github.com/dylang/grunt-templates-dylang) on Sunday, April 5, 2015._
254_To make changes to this document look in `/templates/readme/`
255