JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 14
  • Score
    100M100P100Q40164F
  • License MIT

Package Exports

  • 6bithash
  • 6bithash/dist/index.js
  • 6bithash/dist/index.mjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (6bithash) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

6bithash

Hash function package for hashing id's ( in positive integer ) to an alphanumeric short string using a 6 bit map ( User can also prvide thier own Custom 6 bit map )

I built this to solve the problem of getting short hash for numbers ( i was making a link shortner )

This is Made Using TypeScript and Node.js

How to use

Install with npm

npm install 6bithash

Install with pnpm

pnpm add 6bithash

Then, you can import the hash function as :

import { generateHash } from '6bithash';

or

const { generateHash } = require('6bithash');

Providing a custom hash function

The custom hash function must have key as 6bit integers and value as you want as a string.

Example:

import { generateHash } from '6bithash';
myMap = {
    "000000" : "u",
    ...
    ...
    "111111" : "o",
}
const Number = 1001;
const result = generateHash(Number,{myMap});

Note

  • The minimum number of characters in a string hash depends on the how big the number is.
  • Pass a larger number as a Argument to get a hash with more characters.
  • If you are using TypeScript the result type is string.

Example:

Javascript :

const result = generateHash(959492);
console.log(result); // result = dQqe

TypeScript :

const result:string = generateHash(959492);
console.log(result); // result = dQqe

File Structure

6bithash
├── dist
│ └── index.d.mts
│ └── index.d.ts
│ └── index.js
│ └── index.mjs
├── src
│ └── customMap.ts
│ └── index.ts
│ └── types.ts
├── tests
│ └── index.test.ts
├── .gitignore
├── License
├── pnpm-lock.yaml
├── package.json
├── jest.config.json
├── Readme.md
└── tsconfig.json
└── tsup.config.json

License

This project is licensed under the MIT License - see the LICENSE file for details.