40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
|
/**
|
||
|
* @author masq [github.cyberchef@masq.cc]
|
||
|
* @copyright Crown Copyright 2018
|
||
|
* @license Apache-2.0
|
||
|
*/
|
||
|
|
||
|
import Operation from "../Operation";
|
||
|
|
||
|
/**
|
||
|
* From Case Insensitive Regex operation
|
||
|
*/
|
||
|
class FromCaseInsensitiveRegex extends Operation {
|
||
|
|
||
|
/**
|
||
|
* FromCaseInsensitiveRegex constructor
|
||
|
*/
|
||
|
constructor() {
|
||
|
super();
|
||
|
|
||
|
this.name = "From Case Insensitive Regex";
|
||
|
this.module = "Default";
|
||
|
this.description = "Converts a case-insensitive regex string to a case sensitive regex string (no guarantee on it being the proper original casing) in case /i wasn't available at the time but now is, or you need it to be case-sensitive again.";
|
||
|
this.infoURL = "https://wikipedia.org/wiki/Regular_expression";
|
||
|
this.inputType = "string";
|
||
|
this.outputType = "string";
|
||
|
this.args = [];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param {string} input
|
||
|
* @param {Object[]} args
|
||
|
* @returns {string}
|
||
|
*/
|
||
|
run(input, args) {
|
||
|
return input.replace(/\[[a-z]{2}\]/ig, m => m[1].toUpperCase() === m[2].toUpperCase() ? m[1] : m);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default FromCaseInsensitiveRegex;
|