This commit is contained in:
0xff1ce 2025-02-12 22:37:44 +00:00 committed by GitHub
commit f01dbdfd3c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 122 additions and 1 deletions

View file

@ -326,7 +326,8 @@
"Unescape string",
"Pseudo-Random Number Generator",
"Sleep",
"File Tree"
"File Tree",
"Insert Delimiter"
]
},
{

View file

@ -0,0 +1,54 @@
/**
* @author 0xff1ce [github.com/0xff1ce]
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
/**
* InsertDelimiter operation
*/
class InsertDelimiter extends Operation {
/**
* InsertDelimiter constructor
*/
constructor() {
super();
this.name = "Insert Delimiter";
this.module = "Default";
this.description = "Inserts a given delimiter at regular intervals within the input string.";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Interval",
"type": "number",
"value": 8, // Default interval is 8
},
{
"name": "Delimiter",
"type": "string",
"value": " ", // Default delimiter is a space
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
if (!input) return "";
if (isNaN(args[0]) || args[0] <= 0) {
return "Invalid interval: must be a positive integer.";
}
return input.match(new RegExp(`.{1,${parseInt(args[0], 10)}}`, "g")).join(args[1]);
}
}
export default InsertDelimiter;

View file

@ -83,6 +83,7 @@ import "./tests/Hexdump.mjs";
import "./tests/HKDF.mjs";
import "./tests/Image.mjs";
import "./tests/IndexOfCoincidence.mjs";
import "./tests/InsertDelimiter.mjs";
import "./tests/JA3Fingerprint.mjs";
import "./tests/JA4.mjs";
import "./tests/JA3SFingerprint.mjs";

View file

@ -0,0 +1,65 @@
/**
* @author 0xff1ce [github.com/0xff1ce]
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "Insert space every 8 characters",
input: "010010000110010101101100011011000110111100100000010101110110111101110010011011000110010000100001",
expectedOutput: "01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010 01101100 01100100 00100001",
recipeConfig: [
{
"op": "Insert Delimiter",
"args": [8, " "]
},
],
},
{
name: "Insert newline every 4 characters",
input: "ABCDEFGHIJKL",
expectedOutput: "ABCD\nEFGH\nIJKL",
recipeConfig: [
{
"op": "Insert Delimiter",
"args": [4, "\n"]
},
],
},
{
name: "Insert hyphen every 3 characters",
input: "1234567890",
expectedOutput: "123-456-789-0",
recipeConfig: [
{
"op": "Insert Delimiter",
"args": [3, "-"]
},
],
},
{
name: "Use a float as delimiter",
input: "1234567890",
expectedOutput: "123-456-789-0",
recipeConfig: [
{
"op": "Insert Delimiter",
"args": [3.4, "-"]
},
],
},
{
name: "Handle empty input gracefully",
input: "",
expectedOutput: "",
recipeConfig: [
{
"op": "Insert Delimiter",
"args": [8, " "]
},
],
}
]);