Skip to content

Commit 7acd9a3

Browse files
authored
strictness parameter in fromHex
1 parent 542bbdc commit 7acd9a3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/core/lib/Hex.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export function toHexFast(data) {
100100
* // returns [10,20,30]
101101
* fromHex("0a:14:1e", "Colon");
102102
*/
103-
export function fromHex(data, delim="Auto", byteLen=2) {
103+
export function fromHex(data, delim="Auto", byteLen=2, strict=False) {
104104
if (byteLen < 1 || Math.round(byteLen) !== byteLen)
105105
throw new OperationError("Byte length must be a positive integer");
106106

@@ -113,7 +113,7 @@ export function fromHex(data, delim="Auto", byteLen=2) {
113113

114114
const output = [];
115115
for (let i = 0; i < data.length; i++) {
116-
if (/[^a-f\d\s]/.test(data[i]))
116+
if (/[^a-f\d\s]/.test(data[i]) && strict)
117117
throw new OperationError("Hex input must only contain hex digits");
118118
for (let j = 0; j < data[i].length; j += byteLen) {
119119
output.push(parseInt(data[i].substr(j, byteLen), 16));

0 commit comments

Comments
 (0)