mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
add join delimiter
This commit is contained in:
parent
4e6efead61
commit
6197523735
1 changed files with 12 additions and 4 deletions
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
|
import {JOIN_DELIM_OPTIONS} from "../lib/Delim.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ngram operation
|
* ngram operation
|
||||||
|
@ -29,6 +30,11 @@ class Ngram extends Operation {
|
||||||
type: "number",
|
type: "number",
|
||||||
value: 3
|
value: 3
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Join delimiter",
|
||||||
|
"type": "editableOptionShort",
|
||||||
|
"value": JOIN_DELIM_OPTIONS
|
||||||
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,13 +44,15 @@ class Ngram extends Operation {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const n = args[0];
|
const nGramSize = args[0],
|
||||||
|
joinDelim = args[1];
|
||||||
|
|
||||||
const ngrams = [];
|
const ngrams = [];
|
||||||
for (let i = 0; i <= input.length - n; i++) {
|
for (let i = 0; i <= input.length - nGramSize; i++) {
|
||||||
ngrams.push(input.slice(i, i + n));
|
ngrams.push(input.slice(i, i + nGramSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ngrams.join("\n");
|
return ngrams.join(joinDelim);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue