* Coverts data of varying types to a byte string. * Accepts hex, Base64, UTF8 and Latin1 strings. * * @param {string} str * @param {string} type - One of "Binary", "Hex", "Decimal", "Base64", "UTF8" or "Latin1" * @returns {string} * * @example * // returns "Ð
(str, type)
| 377 | * Utils.convertToByteString("0JfQtNGA0LDQstGB0YLQstGD0LnRgtC1", "base64"); |
| 378 | */ |
| 379 | static convertToByteString(str, type) { |
| 380 | switch (type.toLowerCase()) { |
| 381 | case "binary": |
| 382 | return Utils.byteArrayToChars(fromBinary(str)); |
| 383 | case "hex": |
| 384 | return Utils.byteArrayToChars(fromHex(str)); |
| 385 | case "decimal": |
| 386 | return Utils.byteArrayToChars(fromDecimal(str)); |
| 387 | case "base64": |
| 388 | return Utils.byteArrayToChars(fromBase64(str, null, "byteArray")); |
| 389 | case "utf8": |
| 390 | return utf8.encode(str); |
| 391 | case "latin1": |
| 392 | default: |
| 393 | return str; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | |
| 398 | /** |
no test coverage detected