- ๐ Installation
- ๐ฅ Usage
- ๐จ API
- ๐ getHash
- ๐ getBitwise
- ๐ช transformBinary
- ๐ useTable
- ๐ Table
- ๐ป Contributing
- ๐ Setting up local development
- ๐ Tests
- ๐ Lint & Prettier
- ๐ License
You can install emoji-hash-gen
using standard tools:
$> npm install emoji-hash-gen
# or
$> yarn add emoji-hash-gen
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
Description: Generates random hash from input string.
Interface:
getHash(input: string, options?: Options): string;
Description: Generates random integer, based on input string. Source
Interface:
getBitwise(str: string): number;
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;
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;
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: '๐
'
}
Please, use PRs for your proposals.
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
To run test, simply use command:
$> yarn test
#or
$> npm run test
Easy to check code style and formatting:
$> yarn lint && yarn prettier-format
emoji-hash-gen is copyright ยฉ 2020 opa_oz. It is free software and may be redistributed under the terms specified in the license.