diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-05-19 15:45:37 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-05-19 16:27:54 +0200 |
commit | 8da140fd5548cfab0a2e945091ec78416b1a0d14 (patch) | |
tree | f62000eb23addab8b505fb8bf94ce8dcd6e54926 /README.md | |
parent | 9a724238c27dec032fe2ea75c4975718b0857f98 (diff) |
lib: introduce hexenc() and hexdec()
Add two new functions to deal with encoding and decoding of hexadecimal
digit strings:
- hexenc() - convert the given input value into a lower case hex digit
string, implicitely converting the input argument to a string value
if needed
- hexdec() - decode the given input hex digit string into a byte string,
skipping whitespace or optionally specified characters in the input
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -1473,3 +1473,32 @@ does not implement this clock type. clock(); // [ 1647954926, 798269464 ] clock(true); // [ 474751, 527959975 ] ``` + +#### 6.70. `hexdec(hexstring[, skipchars])` + +The `hexdec()` function decodes the given hexadecimal digit string into +a byte string, optionally skipping specified characters. + +If the characters to skip are not specified, a default of `" \t\n"` is +used. + +Returns null if the input string contains invalid characters or an uneven +amount of hex digits. + +Returns the decoded byte string on success. + +```javascript +hexdec("48656c6c6f20776f726c64210a"); // "Hello world!\n" +hexdec("44:55:66:77:33:44", ":"); // "DUfw3D" +``` + +#### 6.71. `hexenc(val)` + +The `hexenc()` function encodes the given byte string into a hexadecimal +digit string, converting the input value to a string if needed. + +Returns the encoded hexadecimal digit string. + +```javascript +hexenc("Hello world!\n"); // "48656c6c6f20776f726c64210a" +``` |