Data.from()
Description
Converts a string to an instance of Data.
The following options are supported for the encoding parameter:
- "utf8" (default) - Encode the text as UTF-8
- "hex" - Decode the text as hexadecimal representation
- "base64" - Decode the text as Base64 format
- "base64url" - Decode the text as Base64URL format
When decoding fails, null is returned to indicate the error. This is different from new Data() where a runtime error is generated to stop the script.
Syntax
Data.from(text)Data.from(text, encoding)
Parameters
from(text, encoding?)
textencoding?
A string to convert to Data.
Return Value
Instance of Data converted from the string.