Git Product home page Git Product logo

emoji-hash's Introduction


EmojiHash

Lightweight, zero-dependency library for hash-generation in emoji style ๐ŸŒ

Version npm License: MIT PRs Welcome Minsize CodeQL Node.js CI codecov Coverage

Table of Contents

Installation

You can install emoji-hash-gen using standard tools:

$> npm install emoji-hash-gen
# or
$> yarn add emoji-hash-gen

Usage

import { getHash } from 'emoji-hash-gen';

getHash('Hello, world'); // "๐Ÿฅณ๐Ÿคซ๐Ÿฆ"
getHash('https://github.com/opa-oz/emoji-hash'); // "๐Ÿ’ฅ3๏ธโƒฃ๐Ÿ••๐Ÿ• ๐Ÿ”‡๐Ÿˆบ"
getHash('@gahara'); // "โœจ๐ŸŽธ๐Ÿญโ”๐Ÿ••"

// You can restrct an amount of emojies in the hash
const longText = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book';
getHash(longText, { length: 5 }) // "๐Ÿ’ฅ๐Ÿ”ป๐Ÿˆฒ๐Ÿˆต๐Ÿ˜บ"

Hash-function is fully deterministic - you will get the same result with the same set of input data:

import { getHash } from 'emoji-hash-gen';

getHash('@gahara') === getHash('@gahara'); // true
getHash('@gahara') === getHash('gahara'); // false

API

getHash

Description: Generates random hash from input string.

Interface:

getHash(input: string, options?: Options): string;

getBitwise

Description: Generates random integer, based on input string. Source

Interface:

getBitwise(str: string): number;

transformBinary

Description: A function used by getHash. Requires integer as input and generates an emoji-hash based on it

Interface:

transformBinary(input: number, options?: Options): string;

useTable

Description: Original library uses pre-generated table [number]: emoji, which used for hash-generation. useTable provides possibility to override the default table.

Interface:

useTable(newTable: EmojiTable): void;

Table

Description: Default table contains 62 literals, generated from:

Symbols Count
a-z 26
A-Z 26
0-9 10

Re-generate:

$> yarn generate-table

Current table:

// 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
{  
  0: '๐Ÿ’ฅ',  
  1: 'โ”',  
  2: 'โ›”๏ธ',  
  3: '๐Ÿ‘น',  
  4: '๐Ÿ‘Œ',  
  5: '๐Ÿž',  
  6: '๐Ÿ›„',  
  7: '๐Ÿ‘พ',  
  8: '๐Ÿˆถ',  
  9: '๐Ÿˆฒ',  
  10: '๐Ÿ—',  
  11: '๐Ÿ”',  
  12: '๐Ÿ‘',  
  13: '๐Ÿ–',  
  14: '๐ŸŒ',  
  15: '๐Ÿ˜œ',  
  16: '๐Ÿ˜',  
  17: '๐Ÿญ',  
  18: '๐Ÿ”‡',  
  19: 'โœจ',  
  20: '๐Ÿ“Œ',  
  21: '๐Ÿ‘†',  
  22: '๐ŸŽฌ',  
  23: '๐Ÿ‘ต',  
  24: '๐Ÿ”ป',  
  25: '๐Ÿˆต',  
  26: '๐Ÿ˜',  
  27: '๐ŸŒ‚',  
  28: '๐Ÿ’ญ',  
  29: '๐ŸŽธ',  
  30: '๐Ÿ˜บ',  
  31: '๐ŸšŽ',  
  32: '๐Ÿš›',  
  33: '๐Ÿฅ',  
  34: '๐Ÿˆบ',  
  35: '๐Ÿ‚',  
  36: '๐Ÿšด',  
  37: 'โœ”๏ธ',  
  38: '๐Ÿˆน',  
  39: '๐Ÿ“—',  
  40: '๐Ÿ• ',  
  41: '๐Ÿ‘ฏ',  
  42: '3๏ธโƒฃ',  
  43: '๐Ÿ’ถ',  
  44: '๐Ÿซ',  
  45: '๐Ÿ‡ฏ๐Ÿ‡ต',  
  46: '๐Ÿ‘ฎ',  
  47: '๐Ÿฏ',  
  48: '๐Ÿ‘',  
  49: '๐Ÿ“',  
  50: '๐Ÿ”…',  
  51: '๐Ÿฏ',  
  52: '๐Ÿ••',  
  53: '๐Ÿ˜',  
  54: '๐Ÿฌ',  
  55: '๐Ÿ”',  
  56: '๐Ÿšบ',  
  57: '๐Ÿ—พ',  
  58: '๐ŸŽฏ',  
  59: '4๏ธโƒฃ',  
  60: '๐Ÿ•˜',  
  61: '๐ŸŽ…'  
}

Contributing

Please, use PRs for your proposals.

Setting up local development

For start, just clone repo and install dependencies via npm/yarn:

$> git clone https://github.com/opa-oz/emoji-hash.git
$> yarn install
# or
$> npm install

Tests

To run test, simply use command:

$> yarn test
#or
$> npm run test

Lint & Prettier

Easy to check code style and formatting:

$> yarn lint && yarn prettier-format

License

emoji-hash-gen is copyright ยฉ 2020 opa_oz. It is free software and may be redistributed under the terms specified in the license.


ko-fi

emoji-hash's People

Contributors

opa-oz avatar dependabot[bot] avatar opaoz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.