package.json
9.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
{
"_args": [
[
{
"raw": "hashids",
"scope": null,
"escapedName": "hashids",
"name": "hashids",
"rawSpec": "",
"spec": "latest",
"type": "tag"
},
"/Users/fzy/project/3mang"
]
],
"_from": "hashids@latest",
"_id": "hashids@1.1.1",
"_inCache": true,
"_location": "/hashids",
"_nodeVersion": "4.3.2",
"_npmOperationalInternal": {
"host": "packages-12-west.internal.npmjs.com",
"tmp": "tmp/hashids-1.1.1.tgz_1472562886873_0.38658378180116415"
},
"_npmUser": {
"name": "ivan",
"email": "ivan@barreleye.com"
},
"_npmVersion": "2.14.12",
"_phantomChildren": {},
"_requested": {
"raw": "hashids",
"scope": null,
"escapedName": "hashids",
"name": "hashids",
"rawSpec": "",
"spec": "latest",
"type": "tag"
},
"_requiredBy": [
"#DEV:/",
"#USER"
],
"_resolved": "https://registry.npmjs.org/hashids/-/hashids-1.1.1.tgz",
"_shasum": "3c36fcc5b3ba1a96a8fa67a632eb7877c41c6d3e",
"_shrinkwrap": null,
"_spec": "hashids",
"_where": "/Users/fzy/project/3mang",
"author": {
"name": "Ivan Akimov",
"email": "ivan@barreleye.com",
"url": "https://twitter.com/IvanAkimov"
},
"bugs": {
"url": "https://github.com/ivanakimov/hashids.js/issues"
},
"dependencies": {},
"description": "Generate YouTube-like ids from numbers. Use Hashids when you do not want to expose your database ids to the user.",
"devDependencies": {
"babel-cli": "^6.10.1",
"babel-core": "^6.10.4",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-es2015-modules-umd": "^6.8.0",
"babel-preset-es2015": "^6.9.0",
"chai": "^3.5.0",
"coveralls": "^2.11.9",
"eslint": "^3.0.1",
"mocha": "^2.5.3",
"nyc": "^7.0.0",
"uglify-js": "^2.7.0"
},
"directories": {},
"dist": {
"shasum": "3c36fcc5b3ba1a96a8fa67a632eb7877c41c6d3e",
"tarball": "https://registry.npmjs.org/hashids/-/hashids-1.1.1.tgz"
},
"gitHead": "38e8975ecbbed956554ab8ed037f2d2c2549c293",
"homepage": "http://hashids.org/javascript",
"keywords": [
"hashids",
"hashid",
"hash",
"ids",
"youtube",
"bitly",
"obfuscate",
"encode",
"decode",
"encrypt",
"decrypt"
],
"license": "MIT",
"main": "dist/hashids.js",
"maintainers": [
{
"name": "ivan",
"email": "ivan@grather.com"
}
],
"name": "hashids",
"optionalDependencies": {},
"readme": "\n[](http://hashids.org/)\n\n[![Build Status][travis-image]][travis-url]\n[![Coveralls Status][coveralls-image]][coveralls-url]\n[![NPM downloads][npm-downloads-image]][npm-url]\n[![NPM version][npm-version-image]][npm-url]\n[![License][license-image]][license-url]\n[![Chat][chat-image]][chat-url]\n\n**Hashids** is small JavaScript library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user: [http://hashids.org/javascript](http://hashids.org/javascript)\n\nGetting started\n-------\n\nInstall Hashids via:\n\n- [node.js](https://nodejs.org): `npm install --save hashids`\n- [bower](http://bower.io/): `bower install hashids`\n- [jam](http://jamjs.org/): `jam install hashids`\n\n(or just use the code at `dist/hashids.js`)\n\nUse in the browser (wherever ES5 is supported; 5KB):\n\n```javascript\n<script type=\"text/javascript\" src=\"hashids.min.js\"></script>\n<script type=\"text/javascript\">\n\n var hashids = new Hashids();\n console.log(hashids.encode(1));\n\n</script>\n```\n\nUse in Node.js:\n\n```javascript\nvar Hashids = require('hashids');\nvar hashids = new Hashids();\n\nconsole.log(hashids.encode(1));\n```\n\nQuick example\n-------\n\n```javascript\nvar hashids = new Hashids();\n\nvar id = hashids.encode(1, 2, 3); // o2fXhV\nvar numbers = hashids.decode(id); // [1, 2, 3]\n```\n\nMore options\n-------\n\n**A few more ways to pass to `encode()`:**\n\n```javascript\nvar hashids = new Hashids();\n\nconsole.log(hashids.encode(1, 2, 3)); // o2fXhV\nconsole.log(hashids.encode([1, 2, 3])); // o2fXhV\nconsole.log(hashids.encode('1', '2', '3')); // o2fXhV\nconsole.log(hashids.encode(['1', '2', '3'])); // o2fXhV\n```\n\n**Make your ids unique:**\n\nPass a project name to make your ids unique:\n\n```javascript\nvar hashids = new Hashids('My Project');\nconsole.log(hashids.encode(1, 2, 3)); // Z4UrtW\n\nvar hashids = new Hashids('My Other Project');\nconsole.log(hashids.encode(1, 2, 3)); // gPUasb\n```\n\n**Use padding to make your ids longer:**\n\nNote that ids are only padded to fit **at least** a certain length. It doesn't mean that your ids will be *exactly* that length.\n\n```javascript\nvar hashids = new Hashids(); // no padding\nconsole.log(hashids.encode(1)); // jR\n\nvar hashids = new Hashids('', 10); // pad to length 10\nconsole.log(hashids.encode(1)); // VolejRejNm\n```\n\n**Pass a custom alphabet:**\n\n```javascript\nvar hashids = new Hashids('', 0, 'abcdefghijklmnopqrstuvwxyz'); // all lowercase\nconsole.log(hashids.encode(1, 2, 3)); // mdfphx\n```\n\n**Encode hex instead of numbers:**\n\nUseful if you want to encode [Mongo](https://www.mongodb.com/)'s ObjectIds. Note that *there is no limit* on how large of a hex number you can pass (it does not have to be Mongo's ObjectId).\n\n```javascript\nvar hashids = new Hashids();\n\nvar id = hashids.encodeHex('507f1f77bcf86cd799439011'); // y42LW46J9luq3Xq9XMly\nvar hex = hashids.decodeHex(id); // 507f1f77bcf86cd799439011\n```\n\nPitfalls\n-------\n\n1. When decoding, output is always an array of numbers (even if you encode only one number):\n\n\t```javascript\n\tvar hashids = new Hashids();\n\n\tvar id = hashids.encode(1);\n\tconsole.log(hashids.decode(id)); // [1]\n\t```\n\n2. Encoding negative numbers is not supported.\n3. If you pass bogus input to `encode()`, an empty string will be returned:\n\n\t```javascript\n\tvar hashids = new Hashids();\n\n\tvar id = hashids.encode('123a');\n\tconsole.log(id === ''); // true\n\t```\n\n4. Do not use this library as a security tool and do not encode sensitive data. This is **not** an encryption library.\n\nRandomness\n-------\n\nThe primary purpose of Hashids is to obfuscate ids. It's not meant or tested to be used as a security or compression tool. Having said that, this algorithm does try to make these ids random and unpredictable:\n\nNo repeating patterns showing there are 3 identical numbers in the id:\n\n```javascript\nvar hashids = new Hashids();\nconsole.log(hashids.encode(5, 5, 5)); // A6t1tQ\n```\n\nSame with incremented numbers:\n\n```javascript\nvar hashids = new Hashids();\n\nconsole.log(hashids.encode(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); // wpfLh9iwsqt0uyCEFjHM\n\nconsole.log(hashids.encode(1)); // jR\nconsole.log(hashids.encode(2)); // k5\nconsole.log(hashids.encode(3)); // l5\nconsole.log(hashids.encode(4)); // mO\nconsole.log(hashids.encode(5)); // nR\n```\n\nCurses! #$%@\n-------\n\nThis code was written with the intent of placing created ids in visible places, like the URL. Therefore, the algorithm tries to avoid generating most common English curse words by generating ids that never have the following letters next to each other:\n\n\tc, f, h, i, s, t, u\n\nSupport\n-------\n\nHave a question? Ping me [@IvanAkimov](http://twitter.com/ivanakimov) or [ivanakimov.com](http://ivanakimov.com)\n\nLicense\n-------\n\nMIT License. See the `LICENSE` file. You can use Hashids in open source projects and commercial products. Don't break the Internet. Kthxbye.\n\n[travis-url]: https://travis-ci.org/ivanakimov/hashids.js\n[travis-image]: https://travis-ci.org/ivanakimov/hashids.js.svg\n\n[coveralls-url]: https://coveralls.io/github/ivanakimov/hashids.js\n[coveralls-image]: https://coveralls.io/repos/github/ivanakimov/hashids.js/badge.svg\n\n[npm-downloads-image]: https://img.shields.io/npm/dm/hashids.svg?style=flat-square\n[npm-version-image]: https://img.shields.io/npm/v/hashids.svg\n[npm-url]: https://www.npmjs.com/package/hashids\n\n[license-url]: https://github.com/ivanakimov/hashids.js/blob/master/LICENSE\n[license-image]: https://img.shields.io/packagist/l/hashids/hashids.svg?style=flat\n\n[chat-url]: https://gitter.im/hashids/hashids?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge\n[chat-image]: https://badges.gitter.im/Join%20Chat.svg\n",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "git+https://github.com/ivanakimov/hashids.js.git"
},
"scripts": {
"all": "npm run lint && npm run coverage && npm run build && npm run clean",
"build": "npm run test && npm run build:node && npm run rename:global && npm run minify",
"build:node": "babel lib/hashids.js -o dist/hashids.js",
"clean": "rm -rf coverage .nyc_output npm-debug.log",
"coverage": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
"lint": "eslint lib tests",
"minify": "uglifyjs dist/hashids.js -o dist/hashids.min.js --source-map dist/hashids.min.map --compress --mangle",
"rename:global": "sed -i '' 's/global.hashids/global.Hashids/g' dist/hashids.js",
"test": "mocha tests --compilers js:babel-core/register"
},
"version": "1.1.1"
}