wilton/hex
Convert strings into hexadecimal encoding and back
More...
Functions | |
String | decodeBytes (String hexstr, Function|Undefined callback) |
Decode hex-string into "byte" string. | |
String | decodeUTF8 (String hexstr, Function|Undefined callback) |
Decode UTF-8 hex-string. | |
String | encodeBytes (String str, Function|Undefined callback) |
Encode "byte" string as hexadecimal. | |
String | encodeUTF8 (String str, Function|Undefined callback) |
Encode Unicode string as UTF-8 hexadecimal. | |
String | formatHexAndPlain (String hexstr, Function|Undefined callback) |
Format hex-string as a hex+plain string. | |
Boolean | isPretty (String hexstr, Function|Undefined callback) |
Check whether specified hex-string is "prettified". | |
String | prettify (String hexstr, Function|Undefined callback) |
Pretty-print hex-string. | |
String | replaceNonPrintable (String hexstr, Function|Undefined callback) |
Replace non-printable chars in hex-string. | |
String | uglify (String hexstr, Function|Undefined callback) |
Convert "prettified" hex-string into plain hex-string. |
This module provides utility function to encode arbitrary strings as hexadecimal and to parse hexadecimal data.
When converting to/from JavaScript
String
s, data can be handled as a "plain binary" ((encode|decode)Bytes
functions - each byte is converted to/from hex as is) or as Unicode data ((encode|decode)UTF8
functions).
In Unicode case, on encoding String
is converted to UTF-8
first and then UTF-8
bytes are encoded into hex. On decoding, hex bytes are treated as UTF-8
encoded and converted to UTF-16
before returing a String
.
Additonally contains utility functions to pretty-print hex-encoded data.
Usage example:
String hex::decodeBytes | ( | String | hexstr, |
Function|Undefined | callback | ||
) |
Decodes hex-string into String
treating each hex-encoded byte as a char code.
hexstr | String string in hexadecimal encoding |
callback | Function|Undefined callback to receive result or error |
String
decoded string String hex::decodeUTF8 | ( | String | hexstr, |
Function|Undefined | callback | ||
) |
Decodes hex-string using decodeBytes()
and then decodes resulting string from UTF-8
.
hexstr | String string in hexadecimal encoding |
callback | Function|Undefined callback to receive result or error |
String
decoded string String hex::encodeBytes | ( | String | str, |
Function|Undefined | callback | ||
) |
Encodes input string as hexadecimal treating each input symbol as a char code.
str | String "byte" string to encode |
callback | Function|Undefined callback to receive result or error |
String
string in hexadecimal encoding String hex::encodeUTF8 | ( | String | str, |
Function|Undefined | callback | ||
) |
Encodes input string into UTF-8
and then encodes resulting string using encodeBytes()
.
str | String string to encode |
callback | Function|Undefined callback to receive result or error |
String
string in hexadecimal encoding String hex::formatHexAndPlain | ( | String | hexstr, |
Function|Undefined | callback | ||
) |
Formats specified hex-string as a hex [plain]
string. Non-printable characters in plain string are replaced with spaces.
Intended to be used for logging.
hexstr | String string in hexadecimal encoding |
callback | Function|Undefined callback to receive result or error |
String
formatted string Boolean hex::isPretty | ( | String | hexstr, |
Function|Undefined | callback | ||
) |
Check whether specified hex-string contains spacess after each second symbol.
hexstr | String string in hexadecimal encoding |
callback | Function|Undefined callback to receive result or error |
Boolean
whether hex-string is "prettified" String hex::prettify | ( | String | hexstr, |
Function|Undefined | callback | ||
) |
Formats hex-string adding a space after each second symbol.
Does nothing if input string is already "prettified".
hexstr | String string in hexadecimal encoding |
callback | Function|Undefined callback to receive result or error |
String
"prettified" hex-string String hex::replaceNonPrintable | ( | String | hexstr, |
Function|Undefined | callback | ||
) |
Replaces non-printable ASCII chars (codes from 0
to 8
) with spaces.
hexstr | String string in hexadecimal encoding |
callback | Function|Undefined callback to receive result or error |
String
hex-string with non-printable chars replaced String hex::uglify | ( | String | hexstr, |
Function|Undefined | callback | ||
) |
"Un-prettify" hex-string effectively stripping all whitespace symbols from it.
hexstr | String string in hexadecimal encoding |
callback | Function|Undefined callback to receive result or error |
String
"un-prettified" hex-string