* Coverts data of varying types to a byteArray. * Accepts hex, Base64, UTF8 and Latin1 strings. * * @param {string} str * @param {string} type - One of "Binary", "Hex", "Decimal", "Base64", "UTF8" or "Latin1" * @returns {byteArray} * * @example * // returns [2
(str, type)
| 340 | * Utils.convertToByteArray("0JfQtNGA0LDQstGB0YLQstGD0LnRgtC1", "base64"); |
| 341 | */ |
| 342 | static convertToByteArray(str, type) { |
| 343 | switch (type.toLowerCase()) { |
| 344 | case "binary": |
| 345 | return fromBinary(str); |
| 346 | case "hex": |
| 347 | return fromHex(str); |
| 348 | case "decimal": |
| 349 | return fromDecimal(str); |
| 350 | case "base64": |
| 351 | return fromBase64(str, null, "byteArray"); |
| 352 | case "utf8": |
| 353 | return Utils.strToUtf8ByteArray(str); |
| 354 | case "latin1": |
| 355 | default: |
| 356 | return Utils.strToByteArray(str); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | |
| 361 | /** |
no test coverage detected