1.0.1 • Published 6 years ago
charz v1.0.1
Charz :key:
Hash, encode and decode like a pro.
Table of Contents :pushpin:
Simple code :pushpin:
// the simple way.
var hashed = SHA256.from('charz!').create();
// the advanced way
var hashed = SHA256
.from('charz!')
.withKey('myKey')
.x2()
.create();
Installation :pushpin:
npm install charz
Features :pushpin:
- ability to hash any type of data to SHA256 or MD5
- ability to hash objects and arrays
- ability to select return specific item from hashed array
- ability to generate hash x2
- ability to generate hash with custom key
- ability to generate hash repeated to any number of times
- ability to control hashing process to upper or lower case
- ability to convert string into bytesArray
- ability to convert bytesArray back into string
- ability to convert string into Binary code
- ability to convert Binary code back into string
- compatible with es5 and es6
Examples :pushpin:
es5
SHA256
var charz = require("charz").charz,
SHA256 = new charz.SHA256();
// generate normal SHA256 hash from 'charz!'
var hash = SHA256
.from('charz!')
.create();
// generate SHA256 hash from 'charz!' with key 'myKey'
var hash = SHA256
.from('charz!')
.withKey('myKey')
.create();
// generate SHA256 hash from 'charz!' x2
var hash = SHA256
.from('charz!')
.x2()
.create();
// generate SHA256 hash from 'charz!' toUpper x2
// the result here is not the same as the above one
// as default is lower case.
var hash = SHA256
.from('charz!')
.toUpper()
.x2()
.create();
// generate SHA256 hash from 'charz!' x5
var hash = SHA256
.from('charz!')
.repeat(5)
.create();
// return array of 3 hashed items
// each item in array hashed separately.
var hash = SHA256
.from(['charz!', 'charz again!', 'and again!'])
.create();
// return SHA256 of 'charz again!'
var hash = SHA256
.from(['charz!', 'charz again!', 'and again!'])
.select(1)
.create();
es6
MD5
import { charz } from 'charz';
const MD5 = new charz.MD5();
// generate normal MD5 hash from 'charz!'
const hash = MD5
.from('charz!')
.create();
// generate MD5 hash from 'charz!' with key 'myKey'
const hash = MD5
.from('charz!')
.withKey('myKey')
.create();
// generate MD5 hash from 'charz!' x2
const hash = MD5
.from('charz!')
.x2()
.create();
// generate MD5 hash from 'charz!' toUpper x2
// the result here is not the same as the above one
// as default is lower case.
const hash = MD5
.from('charz!')
.toUpper()
.x2()
.create();
// generate MD5 hash from 'charz!' x5
const hash = MD5
.from('charz!')
.repeat(5)
.create();
// return array of 3 hashed items
// each item in array hashed separately.
const hash = MD5
.from(['charz!', 'charz again!', 'and again!'])
.create();
// return MD5 of 'charz again!'
const hash = MD5
.from(['charz!', 'charz again!', 'and again!'])
.select(1)
.create();
as you can see the same functionality shared between SHA256 and MD5
For list of available code see the Wiki
Testing :pushpin:
To test this library just do these simple steps
git clone https://github.com/AhmedMKamal/charz.git
In the directory of the repo run
npm install && npm run test
files structure
.
├── src
│ ├── Bases
│ │ └── Binary
│ │ └── index.ts
│ ├── Hash
│ │ ├── MD5
│ │ │ └── index.ts
│ │ └── SHA256
│ │ └── index.ts
│ ├── Unicode
│ │ └── UTF-8
│ │ └── index.ts
│ └── charz.ts
├── package.json
├── tsconfig.json
├── tslint.json
├── charz.test.ts
└── ...
Contributing :pushpin:
To contribute this repo
you can Fork this repo!
or run
git clone https://github.com/AhmedMKamal/charz.git
open your IDE
start coding
Credits
Thanks :heart: to cotag - ts-md5 since ts-md5 is built in this library so you can use all of their function
One last thing this library built for everyone and anyone, if you see something will make it better just do it.