(value, name, copy)
| 9 | */ |
| 10 | const errors_js_1 = require("./errors.js"); |
| 11 | function _getBytes(value, name, copy) { |
| 12 | if (value instanceof Uint8Array) { |
| 13 | if (copy) { |
| 14 | return new Uint8Array(value); |
| 15 | } |
| 16 | return value; |
| 17 | } |
| 18 | if (typeof (value) === "string" && value.match(/^0x(?:[0-9a-f][0-9a-f])*$/i)) { |
| 19 | const result = new Uint8Array((value.length - 2) / 2); |
| 20 | let offset = 2; |
| 21 | for (let i = 0; i < result.length; i++) { |
| 22 | result[i] = parseInt(value.substring(offset, offset + 2), 16); |
| 23 | offset += 2; |
| 24 | } |
| 25 | return result; |
| 26 | } |
| 27 | (0, errors_js_1.assertArgument)(false, "invalid BytesLike value", name || "value", value); |
| 28 | } |
| 29 | /** |
| 30 | * Get a typed Uint8Array for %%value%%. If already a Uint8Array |
| 31 | * the original %%value%% is returned; if a copy is required use |
no outgoing calls
no test coverage detected