hexyjs
A simple library with some hexadecimal utilities.
Install
$ npm install hexyjs
Basic Usage
const hexyjs = ; /* String to Hexadecimal */ hexyjs; // => 436176652053746f7279 /* Hexadecimal to String */ hexyjs; // => Cave Story hexyjs; // invalid hex string // => false /* Validate a Hexadecimal string */ hexyjs; // => true hexyjs; // => true hexyjs; // => false
API
hexToStr(hex: string): string | false
Decode a hexadecimal string
isHex(hex: string, stric?: boolean): boolean
Validate a hexadecimal string.
- strict: If enabled, this will return false if the string length is not divisible by 2 (invalid hexadecimal string length). If you disabled it, you can validate strings with any length. Check the following example. (default: true)
hexyjs; // strict enabled // => false hexyjs; // strict disabled // => true
strToHex(str: string, options?: strToHexOptions): string
Encode a string to a hexadecimal string. You can use this function with options to change the output.
- grouped: Enable/disable grouped output. (default: false)
- uppercase: Enable/disable the uppercase output. (default: false)
strToHexOptions uppercase?: boolean grouped?: boolean
hexyjs; // => 436176652053746F7279 hexyjs; // => 43 61 76 65 20 53 74 6f 72 79