mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-22 07:46:16 -04:00
Add Head and Tail operations
This commit is contained in:
parent
07bb095e73
commit
dea214bd2e
3 changed files with 338 additions and 1 deletions
|
@ -537,6 +537,61 @@ const StrUtils = {
|
|||
return output;
|
||||
},
|
||||
|
||||
/**
|
||||
* Head lines operation.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
runHead: function(input, args) {
|
||||
let delimiter = args[0],
|
||||
number = args[1],
|
||||
allBut = args[2];
|
||||
|
||||
delimiter = Utils.charRep[delimiter];
|
||||
let splitInput = input.split(delimiter);
|
||||
|
||||
return splitInput
|
||||
.filter((line, lineIndex) => {
|
||||
lineIndex += 1;
|
||||
|
||||
if (allBut) {
|
||||
return lineIndex <= splitInput.length - number;
|
||||
} else {
|
||||
return lineIndex <= number;
|
||||
}
|
||||
})
|
||||
.join(delimiter);
|
||||
},
|
||||
|
||||
/**
|
||||
* Tail lines operation.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
runTail: function(input, args) {
|
||||
let delimiter = args[0],
|
||||
number = args[1],
|
||||
allBut = args[2];
|
||||
|
||||
delimiter = Utils.charRep[delimiter];
|
||||
let splitInput = input.split(delimiter);
|
||||
|
||||
return splitInput
|
||||
.filter((line, lineIndex) => {
|
||||
lineIndex += 1;
|
||||
|
||||
if (allBut) {
|
||||
return lineIndex >= number;
|
||||
} else {
|
||||
return lineIndex > splitInput.length - number;
|
||||
}
|
||||
})
|
||||
.join(delimiter);
|
||||
},
|
||||
};
|
||||
|
||||
export default StrUtils;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue