fix: handle Auto delimiter in fromDecimal (#2217)

This commit is contained in:
OndraDol 2026-04-04 21:08:54 +02:00
parent 167cc398ce
commit 2bef6e132c
2 changed files with 8 additions and 2 deletions

View File

@ -24,9 +24,9 @@ import Utils from "../Utils.mjs";
* fromDecimal("10:20:30", "Colon");
*/
export function fromDecimal(data, delim="Auto") {
delim = Utils.charRep(delim);
const delimRegex = delim === "Auto" ? /[^\d-]+/ : Utils.charRep(delim);
const output = [];
let byteStr = data.split(delim);
let byteStr = data.split(delimRegex);
if (byteStr[byteStr.length-1] === "")
byteStr = byteStr.slice(0, byteStr.length-1);

View File

@ -532,6 +532,12 @@ Top Drawer`, {
assert.strictEqual(chef.fromDecimal("72 101 108 108 111").toString(), "Hello");
}),
it("From decimal with Auto delimiter", () => {
assert.strictEqual(chef.fromDecimal("72,101,108,108,111").toString(), "Hello");
assert.strictEqual(chef.fromDecimal("72:101:108:108:111").toString(), "Hello");
assert.strictEqual(chef.fromDecimal("72;101;108;108;111").toString(), "Hello");
}),
it("From hex", () => {
assert.strictEqual(chef.fromHex("52 69 6e 67 20 41 6e 79 20 42 65 6c 6c 73 3f").toString(), "Ring Any Bells?");
}),