CyberChef/src/core/operations/GenerateLoremIpsum.mjs

71 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-12-28 15:44:59 +01:00
/**
* @author klaxon [klaxon@veyr.com]
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import { GenerateParagraphs, GenerateSentences, GenerateWords, GenerateBytes } from "../lib/LoremIpsum.mjs";
2018-12-28 15:44:59 +01:00
/**
2019-01-09 17:36:34 +01:00
* Generate Lorem Ipsum operation
2018-12-28 15:44:59 +01:00
*/
2019-01-09 17:36:34 +01:00
class GenerateLoremIpsum extends Operation {
2018-12-28 15:44:59 +01:00
/**
2019-01-09 17:36:34 +01:00
* GenerateLoremIpsum constructor
2018-12-28 15:44:59 +01:00
*/
constructor() {
super();
2019-01-09 17:36:34 +01:00
this.name = "Generate Lorem Ipsum";
2018-12-28 15:44:59 +01:00
this.module = "Default";
this.description = "Generate varying length lorem ipsum placeholder text.";
this.infoURL = "https://wikipedia.org/wiki/Lorem_ipsum";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Length",
"type": "number",
"value": "3"
},
{
"name": "Length in",
"type": "option",
"value": ["Paragraphs", "Sentences", "Words", "Bytes"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const [length, lengthType] = args;
2019-08-27 19:13:33 +02:00
if (length < 1) {
2018-12-28 15:44:59 +01:00
throw new OperationError("Length must be greater than 0");
}
switch (lengthType) {
case "Paragraphs":
return GenerateParagraphs(length);
case "Sentences":
return GenerateSentences(length);
case "Words":
return GenerateWords(length);
case "Bytes":
return GenerateBytes(length);
default:
2019-01-09 17:36:34 +01:00
throw new OperationError("Invalid length type");
2018-12-28 15:44:59 +01:00
}
}
}
2019-01-09 17:36:34 +01:00
export default GenerateLoremIpsum;