🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

string-hashids

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-hashids

Like Hashids, this is a small JavaScript library to generate YouTube-like ids from strings.

0.1.0
latest
Source
npm
Version published
Weekly downloads
3
-40%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

hashids

FAQs

Package last updated on 19 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts