{"_id":"rand-token","_rev":"72265","name":"rand-token","description":"Generate random tokens","dist-tags":{"latest":"1.0.1"},"maintainers":[{"name":"sehrope","email":"sehrope@jackdb.com"}],"time":{"modified":"2021-06-03T10:23:42.000Z","created":"2014-01-03T23:09:13.504Z","1.0.1":"2020-03-23T14:49:04.661Z","0.4.0":"2017-11-06T03:09:38.829Z","0.3.0":"2016-12-10T14:25:19.222Z","0.2.1":"2014-03-21T19:59:22.330Z","0.2.0":"2014-03-12T17:43:02.720Z","0.0.2":"2014-01-21T15:14:53.704Z","0.0.1":"2014-01-03T23:09:13.504Z"},"users":{"tengisb":true,"zeusdeux":true,"morrelinko":true,"stdarg":true,"parkerproject":true,"arielabreu":true,"adamlu":true,"makay":true,"octetstream":true,"evdokimovm":true,"dburdese":true,"julianomontini":true,"chrisx":true,"jalik":true,"bajohn20":true,"morogasper":true},"author":{"name":"Sehrope Sarkuni","email":"sehrope@jackdb.com"},"repository":{"type":"git","url":"git://github.com/sehrope/node-rand-token.git"},"versions":{"1.0.1":{"name":"rand-token","version":"1.0.1","description":"Generate random tokens","main":"index.js","types":"index.d.ts","scripts":{"test":"make test"},"repository":{"type":"git","url":"git://github.com/sehrope/node-rand-token.git"},"keywords":["random","uid","token","psuedorandom","urandom","crypto","alpha-numeric"],"author":{"name":"Sehrope Sarkuni","email":"sehrope@jackdb.com"},"license":"MIT","dependencies":{},"devDependencies":{"jshint":"^2.11.0","mocha":"^7.1.1","tsd":"^0.11.0"},"engines":{"node":">= 10"},"gitHead":"2d19612befc0cbbf83302aa191c0fbca5af203c1","bugs":{"url":"https://github.com/sehrope/node-rand-token/issues"},"homepage":"https://github.com/sehrope/node-rand-token#readme","_id":"rand-token@1.0.1","_nodeVersion":"12.16.1","_npmVersion":"6.13.4","dist":{"shasum":"a47fdfd94894cc349d74234403c4b24624733c58","size":5112,"noattachment":false,"key":"/rand-token/-/rand-token-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/rand-token/download/rand-token-1.0.1.tgz"},"maintainers":[{"name":"sehrope","email":"sehrope@jackdb.com"}],"_npmUser":{"name":"sehrope","email":"sehrope@jackdb.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rand-token_1.0.1_1584974944559_0.3310657415394942"},"_hasShrinkwrap":false,"publish_time":1584974944661,"_cnpm_publish_time":1584974944661},"0.4.0":{"name":"rand-token","version":"0.4.0","description":"Generate random tokens","main":"index.js","scripts":{"test":"make test"},"repository":{"type":"git","url":"git://github.com/sehrope/node-rand-token.git"},"keywords":["random","uid","token","psuedorandom","urandom","crypto","alpha-numeric"],"author":{"name":"Sehrope Sarkuni","email":"sehrope@jackdb.com"},"license":"MIT","dependencies":{},"devDependencies":{"lodash":"~2.4.1","jshint":"1.1.0","mocha":"~3"},"engines":{"node":">= 0.8.0"},"gitHead":"4991b3b0123832566cf727ab361ea8171fb1b90b","bugs":{"url":"https://github.com/sehrope/node-rand-token/issues"},"homepage":"https://github.com/sehrope/node-rand-token#readme","_id":"rand-token@0.4.0","_npmVersion":"5.5.1","_nodeVersion":"8.9.0","_npmUser":{"name":"sehrope","email":"sehrope@jackdb.com"},"dist":{"shasum":"1a565b6ad12d92dd4b30c4c4e5945e8aa24a5b3b","size":5176,"noattachment":false,"key":"/rand-token/-/rand-token-0.4.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/rand-token/download/rand-token-0.4.0.tgz"},"maintainers":[{"name":"sehrope","email":"sehrope@jackdb.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rand-token-0.4.0.tgz_1509937777785_0.16602747328579426"},"directories":{},"publish_time":1509937778829,"_hasShrinkwrap":false,"_cnpm_publish_time":1509937778829},"0.3.0":{"name":"rand-token","version":"0.3.0","description":"Generate random tokens","main":"index.js","scripts":{"test":"make test"},"repository":{"type":"git","url":"git://github.com/sehrope/node-rand-token.git"},"keywords":["random","uid","token","psuedorandom","urandom","crypto","alpha-numeric"],"author":{"name":"Sehrope Sarkuni","email":"sehrope@jackdb.com"},"license":"MIT","dependencies":{},"devDependencies":{"lodash":"~2.4.1","jshint":"1.1.0","mocha":"~3"},"engines":{"node":">= 0.8.0"},"gitHead":"438d62d910790d262b13ec019a957083f833877e","bugs":{"url":"https://github.com/sehrope/node-rand-token/issues"},"homepage":"https://github.com/sehrope/node-rand-token#readme","_id":"rand-token@0.3.0","_shasum":"32c0e672200867766a13601a21cef98ac67478c7","_from":".","_npmVersion":"3.10.9","_nodeVersion":"6.9.2","_npmUser":{"name":"sehrope","email":"sehrope@jackdb.com"},"maintainers":[{"name":"sehrope","email":"sehrope@jackdb.com"}],"dist":{"shasum":"32c0e672200867766a13601a21cef98ac67478c7","size":5355,"noattachment":false,"key":"/rand-token/-/rand-token-0.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/rand-token/download/rand-token-0.3.0.tgz"},"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/rand-token-0.3.0.tgz_1481379917052_0.46870445646345615"},"directories":{},"publish_time":1481379919222,"_cnpm_publish_time":1481379919222,"_hasShrinkwrap":false},"0.2.1":{"name":"rand-token","version":"0.2.1","description":"Generate random tokens","main":"index.js","scripts":{"test":"make test"},"repository":{"type":"git","url":"git://github.com/sehrope/node-rand-token"},"keywords":["random","uid","token","psuedorandom","urandom","crypto","alpha-numeric"],"author":{"name":"Sehrope Sarkuni","email":"sehrope@jackdb.com"},"license":"MIT","dependencies":{},"devDependencies":{"lodash":"~2.4.1","jshint":"1.1.0","mocha":"~1.16.2"},"engines":{"node":">= 0.8.0"},"bugs":{"url":"https://github.com/sehrope/node-rand-token/issues"},"homepage":"https://github.com/sehrope/node-rand-token","_id":"rand-token@0.2.1","dist":{"shasum":"dc67c8123306c91227b2dc3f5bea73d301376226","size":5233,"noattachment":false,"key":"/rand-token/-/rand-token-0.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/rand-token/download/rand-token-0.2.1.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"sehrope","email":"sehrope@jackdb.com"},"maintainers":[{"name":"sehrope","email":"sehrope@jackdb.com"}],"directories":{},"publish_time":1395431962330,"_cnpm_publish_time":1395431962330,"_hasShrinkwrap":false},"0.2.0":{"name":"rand-token","version":"0.2.0","description":"Generate random tokens","main":"index.js","scripts":{"test":"make test"},"repository":{"type":"git","url":"git://github.com/sehrope/node-rand-token"},"keywords":["random","uid","token","psuedorandom","urandom","crypto","alpha-numeric"],"author":{"name":"Sehrope Sarkuni","email":"sehrope@jackdb.com"},"license":"MIT","dependencies":{},"devDependencies":{"lodash":"~2.4.1","jshint":"1.1.0","mocha":"~1.16.2"},"engines":{"node":">= 0.8.0"},"bugs":{"url":"https://github.com/sehrope/node-rand-token/issues"},"homepage":"https://github.com/sehrope/node-rand-token","_id":"rand-token@0.2.0","dist":{"shasum":"4f3af796f57bbe2a84825d5e9f7fc5cb1b6e0969","size":5228,"noattachment":false,"key":"/rand-token/-/rand-token-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/rand-token/download/rand-token-0.2.0.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"sehrope","email":"sehrope@jackdb.com"},"maintainers":[{"name":"sehrope","email":"sehrope@jackdb.com"}],"directories":{},"publish_time":1394646182720,"_cnpm_publish_time":1394646182720,"_hasShrinkwrap":false},"0.0.2":{"name":"rand-token","version":"0.0.2","description":"Generate random tokens","main":"index.js","scripts":{"test":"make test"},"repository":{"type":"git","url":"git://github.com/sehrope/node-rand-token"},"keywords":["random","token","psuedorandom","urandom","crypto","alpha-numeric"],"author":{"name":"Sehrope Sarkuni","email":"sehrope@jackdb.com"},"license":"MIT","dependencies":{"lodash":"~2.4.1"},"devDependencies":{"jshint":"1.1.0","mocha":"~1.16.2"},"engines":{"node":">= 0.8.0"},"_id":"rand-token@0.0.2","dist":{"shasum":"f6b1cc5495ceda445bc59a7a770156d2b338b9fd","size":4331,"noattachment":false,"key":"/rand-token/-/rand-token-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/rand-token/download/rand-token-0.0.2.tgz"},"maintainers":[{"name":"sehrope","email":"sehrope@jackdb.com"}],"directories":{},"publish_time":1390317293704,"_cnpm_publish_time":1390317293704,"_hasShrinkwrap":false},"0.0.1":{"name":"rand-token","version":"0.0.1","description":"Generate random tokens","main":"index.js","scripts":{"test":"make test"},"repository":{"type":"git","url":"git://github.com/sehrope/node-rand-token"},"keywords":["random","token","psuedorandom","urandom","crypto","alpha-numeric"],"author":{"name":"Sehrope Sarkuni","email":"sehrope@jackdb.com"},"license":"MIT","dependencies":{"lodash":"~2.4.1"},"devDependencies":{"jshint":"1.1.0","mocha":"~1.16.2"},"engines":{"node":">= 0.8.0"},"_id":"rand-token@0.0.1","dist":{"shasum":"459784867e42779076719fff5afd07bae39f284c","size":4150,"noattachment":false,"key":"/rand-token/-/rand-token-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/rand-token/download/rand-token-0.0.1.tgz"},"maintainers":[{"name":"sehrope","email":"sehrope@jackdb.com"}],"directories":{},"publish_time":1388790553504,"_cnpm_publish_time":1388790553504,"_hasShrinkwrap":false}},"readme":"# node-rand-token\n\nGenerate random tokens from your choice of randomness.\n\n[![NPM](https://nodei.co/npm/rand-token.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/rand-token/)\n\n[![Build Status](https://travis-ci.org/sehrope/node-rand-token.svg?branch=master)](https://travis-ci.org/sehrope/node-rand-token)\n\n\n# Installation\n\nAdd it to your node.js project via:\n\n    npm install rand-token --save\n\n# Usage\n\n    // Create a token generator with the default settings:\n    var randtoken = require('rand-token');\n\n    // Generate a 16 character alpha-numeric token:\n    var token = randtoken.generate(16);\n\n    // Use it as a replacement for uid:\n    var uid = require('rand-token').uid;\n    var token = uid(16);\n\n    // Generate mostly sequential tokens:\n    var suid = require('rand-token').suid;\n    var token = suid(16);\n\n# TypeScript usage\n\nThis module includes type definition:\n\n```typescript\nimport { uid, suid } from 'rand-token';\n\nconst token = uid(12);\nconst otherToken = suid(16)\n```\n\n# Defaults\n\nThe default set of allowed characters is all alpha-numeric characters. Specifically, lower case a through z, upper case A through Z, and the number 0 through 9. This gives you `(26 + 26 + 10)` = `62` possibilities per character.\n\nUsing 8 character random tokens will give you a possible token space of 62^8 = 2.18 x 10^14 ~= 2^47\n\nUsing 12 character random tokens will give you a possible token space of 62^12 = 3.22 x 10^21 ~= 2^71\n\nUsing 16 character random tokens will give you a possible token space of 62^16 = 4.76 x 10^28 ~= 2^95\n\n# Functions\n\n## uid(size)\nUses the default generator to generate a token of `size` characters.\n\n## suid(size, [epoch], [prefixLength])\nUses the default generator to generate *mostly* sequential ids that can be compared with the usual string less-than/greater-than operators. By mostly, it means that a second execution of this function within the same millisecond may generate an id that is less than the second. The same holds true for ids generated from separate node processes. There's no coordination whatsover. This is meant to be used for situations where being able to sort tokens would be convenient, but not strictly required.\n\nThe generated tokens are of `size` characters prefixed with the time since the given epoch in base62 padded to `prefixLength` characters. The `epoch` parameter should be the unix time offset in milliseconds. The default `epoch` is 2000-01-01T00:00:00+00:00 and the default `prefixLength` is 8 characters.\n\n__NOTE:__ The prefix length is in addition to the `size` parameter. Calling this function as `suid(16)` will return a 24-character token back (8 + 16).\n\n## generate(size, [chars])\n\nGenerates a token of `size` characters using either the specified `chars` or the default for the generator. \n\nIf `chars` is specified it will be treated as an array of characters to use. Each character in the list has an equal chance of being used so if a character is repeated twice, it will appear twice as often in the randomly generated tokens.\n\n__Note__: Unlike the `generator(...)` function this function does not treat any string values of `chars` to be special and all values will be simply treated as an array of possible characters.\n\n## generator([options])\n\nCreates a custom token generator.\n\nAvailable options:\n\n* `source` - source of random bytes\n    This should be either a string or a synchronous function with the signature `(size: number): Buffer`.\n\n    The following string values are also accepted:\n\n    * `default` - This is a synonym for using the default of `crypto.pseudoRandomBytes`. You do not need to specify `default` and can simply create the generator without this option specified to get the same effect.\n\n    * `crypto` - This is a synonym for [`crypto.randomBytes`](http://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback). Note that this may throw an error during use if there is not enough entropy.\n\n    * `math` - This is a synonym for using the Math.random() function.\n\n* `chars` - string representing the list of allowed characters to use for `generate(size)` calls.\n\n    The following string values have special meaning:\n\n    * `default` - default set of token characters which is numbers, lower case letters, and upper case letters (i.e. `0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`)\n    * `a-z` || `alpha` - lower case characters (i.e. `abcdefghijklmnopqrstuvwxyz`)\n    * `A-Z` || `ALPHA` - upper case characters (i.e. `ABCDEFGHIJKLMNOPQRSTUVWXYZ`)\n    * `0-9` || `numeric` - numbers only (i.e. `0123456789`)\n    * `base32` - use characters from the base32 alphabet, specifically `A-Z` and `2-7`\n\n    Any other string value will be treated as an array of characters to use. \n\n    Each character in the list has an equal chance of being used. For example if a character is repeated twice, it will appear twice as often in randomly generated tokens. `chars` may be at most 255 characters long.\n\n# Examples\n\nTo replace usage of uid with the default generator (alpha-numeric):\n\n    // Create a token generator with the default settings:\n    var uid = require('rand-token').uid;\n\n    // Generate a 16 character alpha-numeric token:\n    var token = uid(16)\n\nTo generate *mostly* sequential ids:\n    \n    // Create a token generator with the default settings:\n    var suid = require('rand-token').suid;\n\n    // Generate a 24 (16 + 8) character alpha-numeric token:\n    var token = suid(16)\n\nTo generate only lower case letters (a-z):\n\n    // Create a token generator with the default settings:    \n    var randtoken = require('rand-token').generator({\n      chars: 'a-z'\n    });\n\n    // Generate a 16 character token:\n    var token = randtoken.generate(16);\n\nAlternatively, you can create a generator with the default options and pass the characters to use as the second parameter to `generate`:\n\n    // Create a token generator with the default settings:    \n    var randtoken = require('rand-token').generator();\n\n    // Generate a 16 character token:\n    var token = randtoken.generate(16, \"abcdefghijklnmopqrstuvwxyz\");\n\nTo generate only upper case letters with `crypto.randomBytes` as the random source:\n\n    var crypto = require('crypto');\n    // Create the generator:\n    var randtoken = require('rand-token').generator({\n      chars: 'A-Z',\n      source: crypto.randomBytes \n    });\n\n    // Generate a 16 character token:\n    var token = randtoken.generate(16);\n\n\n# Dependencies\n\nNone.\n\n# License\n\nThis plugin is released under the MIT license. See the file [LICENSE](LICENSE).\n","_attachments":{},"homepage":"https://github.com/sehrope/node-rand-token#readme","bugs":{"url":"https://github.com/sehrope/node-rand-token/issues"},"license":"MIT"}