-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @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 the i flag wasn't available at the time but now is, or you need it to be case-sensitive again.<br><br>e.g. <code>[mM][oO][zZ][iI][lL][lL][aA]/[0-9].[0-9] .*</code> becomes <code>Mozilla/[0-9].[0-9] .*</code>"; | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @author masq [github.cyberchef@masq.cc] | ||
* @copyright Crown Copyright 2018 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation"; | ||
|
||
/** | ||
* To Case Insensitive Regex operation | ||
*/ | ||
class ToCaseInsensitiveRegex extends Operation { | ||
|
||
/** | ||
* ToCaseInsensitiveRegex constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "To Case Insensitive Regex"; | ||
this.module = "Default"; | ||
this.description = "Converts a case-sensitive regex string into a case-insensitive regex string in case the i flag is unavailable to you.<br><br>e.g. <code>Mozilla/[0-9].[0-9] .*</code> becomes <code>[mM][oO][zZ][iI][lL][lL][aA]/[0-9].[0-9] .*</code>"; | ||
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]/ig, m => `[${m.toLowerCase()}${m.toUpperCase()}]`); | ||
} | ||
} | ||
|
||
export default ToCaseInsensitiveRegex; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* To/From Case Insensitive Regex tests. | ||
* | ||
* @author masq [github.cyberchef@masq.cc] | ||
* | ||
* @copyright Crown Copyright 2018 | ||
* @license Apache-2.0 | ||
*/ | ||
import TestRegister from "../TestRegister"; | ||
|
||
TestRegister.addTests([ | ||
{ | ||
name: "To Case Insensitive Regex: nothing", | ||
input: "", | ||
expectedOutput: "", | ||
recipeConfig: [ | ||
{ | ||
op: "To Case Insensitive Regex", | ||
args: [], | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "From Case Insensitive Regex: nothing", | ||
input: "", | ||
expectedOutput: "", | ||
recipeConfig: [ | ||
{ | ||
op: "From Case Insensitive Regex", | ||
args: [], | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "To Case Insensitive Regex: simple test", | ||
input: "S0meth!ng", | ||
expectedOutput: "[sS]0[mM][eE][tT][hH]![nN][gG]", | ||
recipeConfig: [ | ||
{ | ||
op: "To Case Insensitive Regex", | ||
args: [], | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "From Case Insensitive Regex: simple test", | ||
input: "[sS]0[mM][eE][tT][hH]![nN][Gg] [wr][On][g]?", | ||
expectedOutput: "s0meth!nG [wr][On][g]?", | ||
recipeConfig: [ | ||
{ | ||
op: "From Case Insensitive Regex", | ||
args: [], | ||
}, | ||
], | ||
}, | ||
]); |