Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hashids

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hashids - npm Package Compare versions

Comparing version 0.3.3 to 1.0.0

Hashids.tmproj

34

lib/hashids.js
/*
hashids
http://www.hashids.org/node-js/
Hashids
http://hashids.org/node-js
(c) 2013 Ivan Akimov

@@ -12,3 +12,3 @@

/*jslint node: true, white: true, plusplus: true */
/*jslint node: true, white: true, plusplus: true, nomen: true */

@@ -21,3 +21,3 @@ "use strict";

this.version = "0.3.3";
this.version = "1.0.0";

@@ -113,3 +113,3 @@ /* internal settings */

Hashids.prototype.encrypt = function() {
Hashids.prototype.encode = function() {

@@ -134,7 +134,7 @@ var ret = "",

return this.encode(numbers);
return this._encode(numbers);
};
Hashids.prototype.decrypt = function(hash) {
Hashids.prototype.decode = function(hash) {

@@ -147,11 +147,11 @@ var ret = [];

return this.decode(hash, this.alphabet);
return this._decode(hash, this.alphabet);
};
Hashids.prototype.encryptHex = function(str) {
Hashids.prototype.encodeHex = function(str) {
var i, len, numbers,
str = str.toString();
var i, len, numbers;
str = str.toString();
if (!/^[0-9a-fA-F]+$/.test(str)) {

@@ -167,11 +167,11 @@ return "";

return this.encrypt.apply(this, numbers);
return this.encode.apply(this, numbers);
};
Hashids.prototype.decryptHex = function(hash) {
Hashids.prototype.decodeHex = function(hash) {
var ret = "",
i, len,
numbers = this.decrypt(hash);
numbers = this.decode(hash);

@@ -186,3 +186,3 @@ for (i = 0, len = numbers.length; i !== len; i++) {

Hashids.prototype.encode = function(numbers) {
Hashids.prototype._encode = function(numbers) {

@@ -252,3 +252,3 @@ var ret, lottery, i, len, number, buffer, last, sepsIndex, guardIndex, guard, halfLength, excess,

Hashids.prototype.decode = function(hash, alphabet) {
Hashids.prototype._decode = function(hash, alphabet) {

@@ -286,3 +286,3 @@ var ret = [],

if (this.encode(ret) !== hash) {
if (this._encode(ret) !== hash) {
ret = [];

@@ -289,0 +289,0 @@ }

{
"author": "Ivan Akimov <ivan@barreleye.com> (https://twitter.com/ivanakimov)",
"author": "Ivan Akimov <ivan@barreleye.com> (https://twitter.com/IvanAkimov)",
"name": "hashids",
"description": "A small Node.js class to generate YouTube-like hashes from one or many numbers. Use hashids when you do not want to expose your database ids to the user. ",
"version": "0.3.3",
"description": "A small Node.js class to generate YouTube-like hashids from one or many numbers. Use hashids when you do not want to expose your database ids to the user. ",
"version": "1.0.0",
"preferGlobal": true,
"homepage": "http://www.hashids.org/node-js/",
"homepage": "http://hashids.org/node-js",
"repository": {

@@ -17,3 +17,3 @@ "type": "git",

"license": "MIT",
"keywords": ["hashids", "hash", "ids", "youtube", "obfuscate", "encrypt", "decrypt", "encode"],
"keywords": ["hashids", "hashid", "hash", "ids", "youtube", "obfuscate", "encrypt", "decrypt", "encode", "decode"],
"engines": {

@@ -20,0 +20,0 @@ "node": "*"

@@ -1,2 +0,1 @@

![hashids](http://www.hashids.org.s3.amazonaws.com/public/img/hashids.png "Hashids")

@@ -9,5 +8,5 @@

A small Node.js class to generate YouTube-like hashes from one or many numbers. Use hashids when you do not want to expose your database ids to the user. Read full documentation at: [http://www.hashids.org/node-js/](http://www.hashids.org/node-js/)
A small Node.js class to generate YouTube-like hashids from one or many numbers. Use hashids when you do not want to expose your database ids to the user. Read full documentation at: [http://hashids.org/node-js](http://hashids.org/node-js)
![hashids](https://api.travis-ci.org/ivanakimov/hashids.node.js.png "Hashids")
![hashids](https://api.travis-ci.org/ivanakimov/hashids.node.js.svg "Hashids")

@@ -22,3 +21,12 @@ Installation

Updating from v0.3 to 1.0?
-------
Read the `CHANGELOG` at the bottom of this readme!
Client-side Version
-------
If you're looking for a client-side Bower version, there's a separate repo: <https://github.com/ivanakimov/hashids.js/>
Production Note

@@ -34,3 +42,3 @@ -------

"dependencies": {
"hashids": "0.3.3"
"hashids": "1.0.0"
}

@@ -42,5 +50,5 @@ ```

#### Encrypting one number
#### Encoding one number
You can pass a unique salt value so your hashes differ from everyone else's. I use "this is my salt" as an example.
You can pass a unique salt value so your ids differ from everyone else's. I use "this is my salt" as an example.

@@ -52,12 +60,12 @@ ```javascript

var hash = hashids.encrypt(12345);
var id = hashids.encode(12345);
```
`hash` is now going to be:
`id` is now going to be:
NkK9
#### Decrypting
#### Decoding
Notice during decryption, same salt value is used:
Notice during decoding, same salt value is used:

@@ -69,3 +77,3 @@ ```javascript

var numbers = hashids.decrypt("NkK9");
var numbers = hashids.decode("NkK9");
```

@@ -77,5 +85,5 @@

#### Decrypting with different salt
#### Decoding with different salt
Decryption will not work if salt is changed:
Decoding will not work if salt is changed:

@@ -87,3 +95,3 @@ ```javascript

var numbers = hashids.decrypt("NkK9");
var numbers = hashids.decode("NkK9");
```

@@ -95,3 +103,3 @@

#### Encrypting several numbers
#### Encoding several numbers

@@ -103,6 +111,6 @@ ```javascript

var hash = hashids.encrypt(683, 94108, 123, 5);
var id = hashids.encode(683, 94108, 123, 5);
```
`hash` is now going to be:
`id` is now going to be:

@@ -116,6 +124,6 @@ aBMswoO2UB3Sj

var arr = [683, 94108, 123, 5];
var hash = hashids.encrypt(arr);
var id = hashids.encode(arr);
```
#### Decrypting is done the same way
#### Decoding is done the same way

@@ -127,3 +135,3 @@ ```javascript

var numbers = hashids.decrypt("aBMswoO2UB3Sj");
var numbers = hashids.decode("aBMswoO2UB3Sj");
```

@@ -135,5 +143,5 @@

#### Encrypting and specifying minimum hash length
#### Encoding and specifying minimum id length
Here we encrypt integer 1, and set the **minimum** hash length to **8** (by default it's **0** -- meaning hashes will be the shortest possible length).
Here we encode integer 1, and set the **minimum** id length to **8** (by default it's **0** -- meaning ids will be the shortest possible length).

@@ -145,10 +153,10 @@ ```javascript

var hash = hashids.encrypt(1);
var id = hashids.encode(1);
```
`hash` is now going to be:
`id` is now going to be:
gB0NV05e
#### Decrypting
#### Decoding

@@ -160,3 +168,3 @@ ```javascript

var numbers = hashids.decrypt("gB0NV05e");
var numbers = hashids.decode("gB0NV05e");
```

@@ -168,3 +176,3 @@

#### Specifying custom hash alphabet
#### Specifying custom id alphabet

@@ -178,6 +186,6 @@ Here we set the alphabet to consist of valid hex characters: "0123456789abcdef"

var hash = hashids.encrypt(1234567);
var id = hashids.encode(1234567);
```
`hash` is now going to be:
`id` is now going to be:

@@ -196,7 +204,7 @@ b332db5

var hash = hashids.encryptHex("507f191e810c19729de860ea");
var objectId = hashids.decryptHex(hash);
var id = hashids.encodeHex("507f191e810c19729de860ea");
var objectId = hashids.decodeHex(id);
```
`hash` will be:
`id` will be:

@@ -224,6 +232,6 @@ yNyaoWeKWVINWqvaM9bw

var hash = hashids.encrypt(5, 5, 5, 5);
var id = hashids.encode(5, 5, 5, 5);
```
You don't see any repeating patterns that might show there's 4 identical numbers in the hash:
You don't see any repeating patterns that might show there's 4 identical numbers in the id:

@@ -239,10 +247,10 @@ 1Wc8cwcE

var hash = hashids.encrypt(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
var id = hashids.encode(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
```
`hash` will be :
`id` will be :
kRHnurhptKcjIDTWC3sx
#### Incrementing number hashes:
#### Incrementing number ids:

@@ -254,7 +262,7 @@ ```javascript

var hash1 = hashids.encrypt(1), /* NV */
hash2 = hashids.encrypt(2), /* 6m */
hash3 = hashids.encrypt(3), /* yD */
hash4 = hashids.encrypt(4), /* 2l */
hash5 = hashids.encrypt(5); /* rD */
var id1 = hashids.encode(1), /* NV */
id2 = hashids.encode(2), /* 6m */
id3 = hashids.encode(3), /* yD */
id4 = hashids.encode(4), /* 2l */
id5 = hashids.encode(5); /* rD */
```

@@ -274,2 +282,3 @@

Hashids uses [jasmine](http://pivotal.github.io/jasmine/) spec tests, particularly [jasmine-node](https://npmjs.org/package/jasmine-node).
To install `sudo npm install -g jasmine-node`

@@ -281,2 +290,15 @@ then just run `jasmine-node .` in the root folder.

**1.0.0**
- Several public functions are renamed to be more appropriate:
- Function `encrypt()` changed to `encode()`
- Function `decrypt()` changed to `decode()`
- Function `encryptHex()` changed to `encodeHex()`
- Function `decryptHex()` changed to `decodeHex()`
Hashids was designed to encode integers, primary ids at most. We've had several requests to encrypt sensitive data with Hashids and this is the wrong algorithm for that. So to encourage more appropriate use, `encrypt/decrypt` is being "downgraded" to `encode/decode`.
- Version tag added: `1.0`
- `README.md` updated
**0.3.3 - Current Stable**

@@ -283,0 +305,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc