mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 15:26:16 -04:00
ESM: Ported StrUtils and NetBIOS operations.
This commit is contained in:
parent
a98d37e61c
commit
037e2f3771
15 changed files with 907 additions and 6 deletions
68
src/core/operations/Head.mjs
Normal file
68
src/core/operations/Head.mjs
Normal file
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import Utils from "../Utils";
|
||||
import {INPUT_DELIM_OPTIONS} from "../lib/Delim";
|
||||
|
||||
/**
|
||||
* Head operation
|
||||
*/
|
||||
class Head extends Operation {
|
||||
|
||||
/**
|
||||
* Head constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Head";
|
||||
this.module = "Default";
|
||||
this.description = "Like the UNIX head utility.<br>Gets the first n lines.<br>You can select all but the last n lines by entering a negative value for n.<br>The delimiter can be changed so that instead of lines, fields (i.e. commas) are selected instead.";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Delimiter",
|
||||
"type": "option",
|
||||
"value": INPUT_DELIM_OPTIONS
|
||||
},
|
||||
{
|
||||
"name": "Number",
|
||||
"type": "number",
|
||||
"value": 10
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
let delimiter = args[0];
|
||||
const number = args[1];
|
||||
|
||||
delimiter = Utils.charRep(delimiter);
|
||||
const splitInput = input.split(delimiter);
|
||||
|
||||
return splitInput
|
||||
.filter((line, lineIndex) => {
|
||||
lineIndex += 1;
|
||||
|
||||
if (number < 0) {
|
||||
return lineIndex <= splitInput.length + number;
|
||||
} else {
|
||||
return lineIndex <= number;
|
||||
}
|
||||
})
|
||||
.join(delimiter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Head;
|
Loading…
Add table
Add a link
Reference in a new issue