mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-22 15:56:16 -04:00
Pull SetUnion into its own operation
This commit is contained in:
parent
f491461a57
commit
5f93c667a2
6 changed files with 350 additions and 306 deletions
|
@ -1,19 +1,63 @@
|
|||
import SetOp from "./SetOps";
|
||||
import Utils from "../Utils";
|
||||
import Operation from "../Operation";
|
||||
|
||||
/**
|
||||
*
|
||||
* Set Union operation
|
||||
*/
|
||||
class SetUnion extends SetOp {
|
||||
class SetUnion extends Operation {
|
||||
|
||||
/**
|
||||
*
|
||||
* Set Union constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
this.setOp = this.runUnion;
|
||||
|
||||
this.name = "Set Union";
|
||||
this.module = "Default";
|
||||
this.description = "Get the union of two sets";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
name: "Sample delimiter",
|
||||
type: "binaryString",
|
||||
value: Utils.escapeHtml("\\n\\n")
|
||||
},
|
||||
{
|
||||
name: "Item delimiter",
|
||||
type: "binaryString",
|
||||
value: ","
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate input length
|
||||
* @param {Object[]} sets
|
||||
* @throws {Error} if not two sets
|
||||
*/
|
||||
validateSampleNumbers(sets) {
|
||||
if (!sets || (sets.length !== 2)) {
|
||||
throw "Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the union operation
|
||||
* @param input
|
||||
* @param args
|
||||
*/
|
||||
run(input, args) {
|
||||
[this.sampleDelim, this.itemDelimiter] = args;
|
||||
const sets = input.split(this.sampleDelim);
|
||||
|
||||
try {
|
||||
this.validateSampleNumbers(sets);
|
||||
} catch (e) {
|
||||
return e;
|
||||
}
|
||||
|
||||
return Utils.escapeHtml(this.runUnion(...sets.map(s => s.split(this.itemDelimiter))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue