hashids-extended
v1.0.7
Published
Extended hashids for feel comfortable
Downloads
13
Maintainers
Readme
node-hashids-extended
Extended hashids for feel comfortable. Sometimes you would like to encode/decode only 1 number, but you have to use the first element of decoded array, or write a wrapper to handle it. No more!
Installation
npm install hashid-extended --save
Usage
Javascript
const { HashidsExtended } = require('hashids-extended');
const hash = new HashidsExtended(
'mysalt',
10,
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
);
const myHashedValue = hash.encode(1);
const myHashedArray = hash.encodeArray(2, 3, 4, 5);
const decodedValue = hash.decode(myHashedValue);
const firstValue = hash.decode(myHashedArray);
const decodedArray = hash.decodeArray(myHashedArray);
console.log(decodedValue);
console.log(firstValue);
console.log(decodedArray);
// output:
// 1
// 2
// [2,3,4,5]
Typescript
import HashidsExtended from 'hashids-extended';
const hash = new HashidsExtended(
'mysalt',
10,
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
);
const myHashedValue = hash.encode(1);
const myHashedArray = hash.encodeArray(2, 3, 4, 5);
const decodedValue = hash.decode(myHashedValue);
const firstValue = hash.decode(myHashedArray);
const decodedArray = hash.decodeArray(myHashedArray);
console.log(decodedValue);
console.log(firstValue);
console.log(decodedArray);
// output:
// 1
// 2
// [2,3,4,5]
Test
npm run test