{"_id":"random-hash","_rev":"9-c5deb3e853a9e5e92c09ec2812c26e4d","name":"random-hash","description":"Generate random hashes with a fully customizable charset and configurable length","dist-tags":{"latest":"4.0.1"},"versions":{"1.0.0":{"name":"random-hash","version":"1.0.0","description":"Spit out some random hash ids","main":"lib/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"https://github.com/PabloSichert/random-hash"},"author":{"name":"Pablo Sichert","email":"mail@pablosichert.de"},"license":"MIT","bugs":{"url":"https://github.com/PabloSichert/random-hash/issues"},"homepage":"https://github.com/PabloSichert/random-hash","gitHead":"80c1f6d8a82a1ff503bd79ae825773f93f200940","_id":"random-hash@1.0.0","_shasum":"9b256af22ed929a4301f06b22476e62829644a03","_from":".","_npmVersion":"2.5.1","_nodeVersion":"0.12.0","_npmUser":{"name":"pablosichert","email":"mail@pablosichert.de"},"maintainers":[{"name":"pablosichert","email":"mail@pablosichert.de"}],"dist":{"shasum":"9b256af22ed929a4301f06b22476e62829644a03","tarball":"https://registry.npmjs.org/random-hash/-/random-hash-1.0.0.tgz","integrity":"sha512-PNGrpRgJ1DJHt3bNW6hOy4gkHvMYMvMHSWfO1cKdIN/E+1SDnP+/kOoOQob3rJ3iPf0Dw+gzHI+HoOgAUCsGeQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD+zesot5Oh2oFaa+Ng/j3rk5XOSyH2rGBvpyAq3mUGAQIhAMh9vmYa02/wcCbqV1ARBJ5cICRKqzsD8AtJIhu7mfuY"}]}},"2.0.0":{"name":"random-hash","version":"2.0.0","description":"Spit out some random hash ids","main":"dist/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/PabloSichert/random-hash.git"},"author":{"name":"Pablo Sichert","email":"mail@pablosichert.de"},"license":"MIT","bugs":{"url":"https://github.com/PabloSichert/random-hash/issues"},"homepage":"https://github.com/PabloSichert/random-hash","gitHead":"acf667a45109d13f4707dfcee7802ef45a1f7d18","_id":"random-hash@2.0.0","_shasum":"cdd71ed231bd2475ce67042f13b447180ba2dc7b","_from":".","_npmVersion":"2.14.7","_nodeVersion":"4.2.1","_npmUser":{"name":"pablosichert","email":"mail@pablosichert.de"},"dist":{"shasum":"cdd71ed231bd2475ce67042f13b447180ba2dc7b","tarball":"https://registry.npmjs.org/random-hash/-/random-hash-2.0.0.tgz","integrity":"sha512-+MURhZ2YI+zD2OUGRCfboj4UHtdY979atzBu0D2dW81TUyb1tFacsMNcilwCE0JwCunwS+HyXyEOSux5gel01A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDpyrUI0Udk5a3twcr1SyIdHHE53esabPGKpGOuCe2IigIgKUAZa3zJpQ6fPzHdbIerRXVmrY9dBm85lfsv73sfMWw="}]},"maintainers":[{"name":"pablosichert","email":"mail@pablosichert.de"}]},"3.0.1":{"name":"random-hash","version":"3.0.1","description":"Spit out some random hash ids","main":"dist/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/PabloSichert/random-hash.git"},"author":{"name":"Pablo Sichert","email":"mail@pablosichert.de"},"license":"MIT","bugs":{"url":"https://github.com/PabloSichert/random-hash/issues"},"homepage":"https://github.com/PabloSichert/random-hash","gitHead":"7bc926ab7f97eb3552709c2786d12feb40b17a9a","_id":"random-hash@3.0.1","_shasum":"0d98fa8dfd218c82d62ee695bc7f906c25f4a09a","_from":".","_npmVersion":"2.14.9","_nodeVersion":"0.10.38","_npmUser":{"name":"pablosichert","email":"mail@pablosichert.de"},"dist":{"shasum":"0d98fa8dfd218c82d62ee695bc7f906c25f4a09a","tarball":"https://registry.npmjs.org/random-hash/-/random-hash-3.0.1.tgz","integrity":"sha512-K+nrOFHSBjylnrKMsi5wt9LeR75pVEHi1F47XOuNlZVB+I9f1h751We2sgYeqRYDWS67eWBrizMlIuvpZv5Dag==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCV+4KS5Yd63LHmPdIsO6rhQVp3vnKZKYzF3MIkq4ni9QIgHFE5SQQ3Bch16hPuC9CpVqubyrArZaP5liWZ/yPNcxU="}]},"maintainers":[{"name":"pablosichert","email":"mail@pablosichert.de"}]},"4.0.0":{"name":"random-hash","version":"4.0.0","description":"Generate random hashes with a fully customizable charset and configurable length","main":"dist/index.js","files":["dist"],"scripts":{"compile":"babel ./lib --out-dir ./dist","coverage":"nyc npm test && nyc report --reporter=text-lcov","lint":"eslint .","report-coverage":"npm run coverage | coveralls","test":"mocha --compilers js:babel-core/register","travis":"npm run lint && npm run compile && npm run test"},"repository":{"type":"git","url":"git+https://github.com/PabloSichert/random-hash.git"},"author":{"name":"Pablo Sichert","email":"mail@pablosichert.de"},"license":"MIT","bugs":{"url":"https://github.com/PabloSichert/random-hash/issues"},"homepage":"https://github.com/PabloSichert/random-hash","keywords":["random","hash","code generator","baseN"],"devDependencies":{"babel-cli":"^6.14.0","babel-core":"^6.14.0","babel-eslint":"^6.1.2","babel-plugin-transform-es2015-modules-commonjs":"^6.14.0","babel-plugin-transform-object-rest-spread":"^6.8.0","coveralls":"^2.11.14","eslint":"^3.5.0","mocha":"^3.0.2","nyc":"^8.3.0","unexpected":"^10.17.2"},"gitHead":"ab4ad05b0dba07b6e4da7707542be901409783b2","_id":"random-hash@4.0.0","_shasum":"34f56c426c22896d347b9ce27e1c374a31bd6a03","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.3.1","_npmUser":{"name":"pablosichert","email":"mail@pablosichert.de"},"dist":{"shasum":"34f56c426c22896d347b9ce27e1c374a31bd6a03","tarball":"https://registry.npmjs.org/random-hash/-/random-hash-4.0.0.tgz","integrity":"sha512-LwifDlVCP8jFeStT97bbrrDc5oiw8iDU7fcSVCJvFoaoGV8qfeg3QDBhudu3dMg4S6NDT2yk5spFNTp7DtmEvg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD2lYpxZ08ocNp8zB7Cw9o9SQ7/1+U0CUPp8NonoGOMfAIhAMd6s5hXOR8kaOW+uhbrxm3L00i+FEOCM7U+6gVsgFSq"}]},"maintainers":[{"name":"pablosichert","email":"mail@pablosichert.de"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/random-hash-4.0.0.tgz_1474878636914_0.31331441970542073"}},"4.0.1":{"name":"random-hash","version":"4.0.1","description":"Generate random hashes with a fully customizable charset and configurable length","main":"dist/index.js","files":["dist"],"scripts":{"compile":"babel ./lib --out-dir ./dist","coverage":"nyc npm test && nyc report --reporter=text-lcov","lint":"eslint .","prepublish":"rm -rf ./dist && npm run compile","preversion":"npm run lint && npm run test","report-coverage":"npm run coverage | coveralls","test":"mocha --compilers js:babel-core/register","travis":"npm run lint && npm run compile && npm run test"},"repository":{"type":"git","url":"git+https://github.com/PabloSichert/random-hash.git"},"author":{"name":"Pablo Sichert","email":"mail@pablosichert.de"},"license":"MIT","bugs":{"url":"https://github.com/PabloSichert/random-hash/issues"},"homepage":"https://github.com/PabloSichert/random-hash","keywords":["random","hash","code generator","baseN"],"devDependencies":{"babel-cli":"^6.14.0","babel-core":"^6.14.0","babel-eslint":"^7.0.0","babel-plugin-transform-es2015-modules-commonjs":"^6.14.0","babel-plugin-transform-object-rest-spread":"^6.8.0","coveralls":"^2.11.14","eslint":"^3.5.0","mocha":"^3.0.2","nyc":"^8.3.0","unexpected":"^10.17.2"},"gitHead":"ad65686c15664fb5c36647e5299e8d6e4269e935","_id":"random-hash@4.0.1","_shasum":"342d7d14501e664f0bee2d9a13eeae9c973cb755","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.6.0","_npmUser":{"name":"pablosichert","email":"mail@pablosichert.de"},"dist":{"shasum":"342d7d14501e664f0bee2d9a13eeae9c973cb755","tarball":"https://registry.npmjs.org/random-hash/-/random-hash-4.0.1.tgz","integrity":"sha512-DXtQo3p1jWF3Wj+1OKZzZrQRdOEIcMkpM9GeYAWXCYf0k36OEQSFkWOsaqVQ37ltQgJuzjP9Mzey3DUIuuI2wA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCVB5dFikemZvAZdjhZc0b+oIJKOXtS8vWgwShjPs3EuwIhAJSXWUTgQoJOOvwA5GukioJTKFGMSp0VeR2CULRa1tz9"}]},"maintainers":[{"name":"pablosichert","email":"mail@pablosichert.de"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/random-hash-4.0.1.tgz_1475011313348_0.5951956931967288"}}},"readme":"# random-hash\n[![NPM version][npm-image]][npm-url]\n[![Build status][travis-image]][travis-url]\n[![Coverage status][coveralls-image]][coveralls-url]\n[![Dependency status][david-dm-image]][david-dm-url]\n[![Dev dependency status][david-dm-dev-image]][david-dm-dev-url]\n\n## Installation\n```bash\nnpm install random-hash\n```\n\n## Usage\nGenerating hashes - optional configuration in function argument\n```js\nimport generateHash from 'random-hash';\n\ngenerateHash(); // '0yyv6Z'\n\ngenerateHash({ length: 4 }); // 'KLgF'\n\ngenerateHash({\n    charset: ['😁', '😎', '😍', '😇', '🤓', '🤔', '😴', '😝']\n}); // '😝🤓😎😇😝🤔'\n\ngenerateHash({\n    rng: randomBytes => new Array(randomBytes).fill(0)\n}); // 'aaaaaa'\n```\n\nCreating a stateful function object that stores its configuration and can be manipulated from the outside\n```js\nimport { RandomHash } from 'random-hash';\nimport { randomBytes } from 'crypto';\n\n// With options (default values)\nconst generateHash = new RandomHash({\n    length: 6,\n    charset: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_',\n    rng: randomBytes\n});\n\n// Without options\nconst generateHash = new RandomHash;\n\ngenerateHash(); // 'VE5xn-'\n\ngenerateHash({ length: 4 }); // 'E2s4'\n\ngenerateHash(); // 'O1oJkK'\n\n// Permanently setting hash length\ngenerateHash.length = 4;\n\ngenerateHash(); // 'AyHK'\n\n// Permanently setting charset\ngenerateHash.charset = ['😁', '😎', '😍', '😇', '🤓', '🤔', '😴'];\n\ngenerateHash(); // '😴😁😁😍'\n\ngenerateHash.rng = randomBytes => new Array(randomBytes).fill(0);\n\ngenerateHash(); // '😁😁😁😁'\n```\n## Algorithm for `generateHash`\n```\n|----------- a1 ----------| ... |------------------------- a(n) ------------------------|\n| b1 b2 b3 b4 b5 b6 b7 b8 | ... | b(n-7) b(n-6) b(n-5) b(n-4) b(n-3) b(n-2) b(n-1) b(n) |\n|--- c1 ---|                               ...                               |-- c(n) --|\n\na(n): binary with 8 digits\nb(n): binary from RNG\nc(n): binary with log2(charset.length) digits\n\na1 ... a(ceil(hashLength * log2(charset.length) / 8))\nb1 ... b(ceil(hashLength * log2(charset.length) / 8) * 8)\nc1 ... c(hashLength)\n```\n\n```\ncharset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_'\nlength = 4\n\n|------- a1 ------|------- b2 ------|------- c3 ------|\n| 0 1 1 0 0 0 1 1 | 0 1 0 1 0 1 0 0 | 0 0 0 0 0 0 0 1 | random bytes\n|---- c1 ----|----- c2 ----|----- c3 ----|---- c4 ----|\n|----- y ----|----- 1 -----|----- q -----|----- b ----| = 'y1qb'\n```\n\n```\nExample\ncharset = ['😁', '😎', '😍', '😇', '🤓', '🤔', '😴', '😝', '🤑', '🤒', '😭', '😈', '👻', '👽', '🤖', '💩', '🎅', '💪', '👈', '👉', '👆', '👇', '✌', '✋', '👌', '👍', '👎', '👐', '👂', '👃', '👣', '👁']\nlength = 3\n\n|------- a1 ------|------- b2 ------|\n| 0 0 0 1 1 0 1 1 | 0 0 1 0 1 1 1 0 | random bytes\n|--- c1 ---|---- c2 ---|--- c3 --|\n|--- 😇 ---|---- 👻 ----|--- ✋ ---| = '😇👻✋'\n```\n\n[npm-url]: https://npmjs.org/package/random-hash\n[npm-image]: https://badge.fury.io/js/random-hash.svg\n[travis-url]: https://travis-ci.org/PabloSichert/random-hash\n[travis-image]: http://img.shields.io/travis/PabloSichert/random-hash.svg\n[coveralls-url]:https://coveralls.io/r/PabloSichert/random-hash\n[coveralls-image]:https://coveralls.io/repos/PabloSichert/random-hash/badge.svg\n[david-dm-url]:https://david-dm.org/PabloSichert/random-hash\n[david-dm-image]:https://david-dm.org/PabloSichert/random-hash.svg\n[david-dm-dev-url]:https://david-dm.org/PabloSichert/random-hash#info=devDependencies\n[david-dm-dev-image]:https://david-dm.org/PabloSichert/random-hash/dev-status.svg\n","maintainers":[{"email":"mail@pablosichert.com","name":"pablosichert"}],"time":{"modified":"2022-06-25T11:27:15.945Z","created":"2015-02-18T02:01:01.351Z","1.0.0":"2015-02-18T02:01:01.351Z","2.0.0":"2015-10-20T05:27:58.702Z","3.0.1":"2016-01-12T14:57:34.652Z","4.0.0":"2016-09-26T08:30:38.755Z","4.0.1":"2016-09-27T21:21:55.247Z"},"homepage":"https://github.com/PabloSichert/random-hash","repository":{"type":"git","url":"git+https://github.com/PabloSichert/random-hash.git"},"author":{"name":"Pablo Sichert","email":"mail@pablosichert.de"},"bugs":{"url":"https://github.com/PabloSichert/random-hash/issues"},"license":"MIT","readmeFilename":"README.md","keywords":["random","hash","code generator","baseN"]}