( str: string, byteLength: number = encoder.encode(str).length )
| 227 | // The odd-length message reports the UTF-8 byte length, so non-ASCII input |
| 228 | // whose UTF-8 encoding has an even length reports "Invalid input" instead. |
| 229 | const decodeFailure = ( |
| 230 | str: string, |
| 231 | byteLength: number = encoder.encode(str).length |
| 232 | ): Result.Result<never, EncodingError> => |
| 233 | Result.fail( |
| 234 | new EncodingError({ |
| 235 | module: "Hex", |
| 236 | kind: "Decode", |
| 237 | input: str, |
| 238 | message: byteLength % 2 !== 0 ? `Length must be a multiple of 2, but is ${byteLength}` : "Invalid input" |
| 239 | }) |
| 240 | ) |
| 241 | |
| 242 | /** |
| 243 | * Decodes a hexadecimal string into a UTF-8 string safely. |
no test coverage detected