(str: string)
| 14 | |
| 15 | /** @internal */ |
| 16 | export const decode = (str: string): Either.Either<Uint8Array, Encoding.DecodeException> => { |
| 17 | const bytes = new TextEncoder().encode(str) |
| 18 | if (bytes.length % 2 !== 0) { |
| 19 | return Either.left(DecodeException(str, `Length must be a multiple of 2, but is ${bytes.length}`)) |
| 20 | } |
| 21 | |
| 22 | try { |
| 23 | const length = bytes.length / 2 |
| 24 | const result = new Uint8Array(length) |
| 25 | for (let i = 0; i < length; i++) { |
| 26 | const a = fromHexChar(bytes[i * 2]) |
| 27 | const b = fromHexChar(bytes[i * 2 + 1]) |
| 28 | result[i] = (a << 4) | b |
| 29 | } |
| 30 | |
| 31 | return Either.right(result) |
| 32 | } catch (e) { |
| 33 | return Either.left(DecodeException(str, e instanceof Error ? e.message : "Invalid input")) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /** @internal */ |
| 38 | const bytesToHex = [ |
nothing calls this directly
no test coverage detected
searching dependent graphs…