Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/core/lib/Decimal.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import Utils from "../Utils.mjs";
* fromDecimal("10:20:30", "Colon");
*/
export function fromDecimal(data, delim="Auto") {
delim = Utils.charRep(delim);
const output = [];
let byteStr = data.split(delim);
if (byteStr[byteStr.length-1] === "")
byteStr = byteStr.slice(0, byteStr.length-1);
const delimRegex = delim === "Auto" ? /[^\d-]+/ : Utils.regexRep(delim);
let byteStr = data.split(delimRegex);

byteStr = byteStr.filter(str => str !== "");

const output = [];
for (let i = 0; i < byteStr.length; i++) {
output[i] = parseInt(byteStr[i], 10);
}
Expand Down
7 changes: 6 additions & 1 deletion src/core/operations/FromDecimal.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import {DELIM_OPTIONS} from "../lib/Delim.mjs";
import {fromDecimal} from "../lib/Decimal.mjs";

/**
* From Decimal delimiters, plus auto-detection.

Check warning on line 12 in src/core/operations/FromDecimal.mjs

View workflow job for this annotation

GitHub Actions / main

Trailing spaces not allowed

Check warning on line 12 in src/core/operations/FromDecimal.mjs

View workflow job for this annotation

GitHub Actions / main

Trailing spaces not allowed

Check warning on line 12 in src/core/operations/FromDecimal.mjs

View workflow job for this annotation

GitHub Actions / main

Trailing spaces not allowed

Check warning on line 12 in src/core/operations/FromDecimal.mjs

View workflow job for this annotation

GitHub Actions / main

Trailing spaces not allowed
*/
const FROM_DECIMAL_DELIM_OPTIONS = [...DELIM_OPTIONS, "Auto"];

/**
* From Decimal operation
*/
Expand All @@ -28,7 +33,7 @@
{
"name": "Delimiter",
"type": "option",
"value": DELIM_OPTIONS
"value": FROM_DECIMAL_DELIM_OPTIONS
},
{
"name": "Support signed values",
Expand Down
55 changes: 55 additions & 0 deletions tests/operations/tests/FromDecimal.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,59 @@ TestRegister.addTests([
},
],
},
{
name: "From Decimal with Auto delimiter (space)",
input: "72 101 108 108 111",
expectedOutput: "Hello",
recipeConfig: [
{
op: "From Decimal",
args: ["Auto", false]
},
],
},
{
name: "From Decimal with Auto delimiter (comma)",
input: "72,101,108,108,111",
expectedOutput: "Hello",
recipeConfig: [
{
op: "From Decimal",
args: ["Auto", false]
},
],
},
{
name: "From Decimal with Auto delimiter (mixed)",
input: "72, 101 : 108; 108\t111",
expectedOutput: "Hello",
recipeConfig: [
{
op: "From Decimal",
args: ["Auto", false]
},
],
},
{
name: "From Decimal with Auto delimiter (newline)",
input: "72\n101\n108\n108\n111",
expectedOutput: "Hello",
recipeConfig: [
{
op: "From Decimal",
args: ["Auto", false]
},
],
},
{
name: "From Decimal with Auto delimiter and signed values",
input: "-130 -140 -152 -151 115 33 0 -1",
expectedOutput: "~this!\u0000\u00ff",
recipeConfig: [
{
op: "From Decimal",
args: ["Auto", true]
},
],
},
]);