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