1.0.7 • Published 3 years ago

hashids-extended v1.0.7

Weekly downloads
82
License
ISC
Repository
github
Last release
3 years ago

Build status Coverage Status GitHub

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
1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.0

6 years ago