string-hashids

0.1.0 • Public • Published

Why?

You may have used hashids and I bet you love how the library encodes numeric values into awesome and short ids.

This library was born from my efforts to achieve the same very short ids using strings/text, not supported by hashids.

After a lot of tinkering, I figured that it was possible to use the CRC-32 algorithm as an intermediary. This generates a short numeric hash from the string which is then converted to a hashid! In between we perform some "padding" for negative CRC-32 hashes as hashids only supports positive integers.

Simple and effective!

Of course ids these are not intended to be cryptographically safe!

To Use

Install: yarn add string-hashids

Then:

    let sHash = require("string-hashids");

    let str = 'After a lot of tinkering, I figured that it was possible to use the CRC-32 algorithm as an intermediary. This generates a short numeric hash from the string which is then converted to a hashid! In between we perform some "padding" for negative CRC-32 hashes as hashids only supports positive integers.';

    let hash = sHash.encode(str, "my salt");

    console.log(hash); //ERfnG8y6O

API

encode(your_string, [your_salt])

Note:

  • The string and salt values are automatically stringified using toString()
  • Salt is an optional value.

Package Sidebar

Install

npm i string-hashids

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

5.01 kB

Total Files

4

Last publish

Collaborators

  • nguru