CyberChef/src/core/operations/RemoveDiacritics.mjs

42 lines
1,015 B
JavaScript
Raw Normal View History

2018-10-03 05:11:22 +02:00
/**
* @author Klaxon [klaxon@veyr.com]
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import Operation from "../Operation";
/**
* Remove Diacritics operation
2018-10-03 05:11:22 +02:00
*/
class RemoveDiacritics extends Operation {
2018-10-03 05:11:22 +02:00
/**
* RemoveDiacritics constructor
2018-10-03 05:11:22 +02:00
*/
constructor() {
super();
this.name = "Remove Diacritics";
2018-10-03 05:11:22 +02:00
this.module = "Default";
this.description = "Replaces accented characters with their latin character equivalent.";
this.infoURL = "https://wikipedia.org/wiki/Diacritic";
2018-10-03 05:11:22 +02:00
this.inputType = "string";
this.outputType = "string";
this.args = [];
2018-10-03 05:11:22 +02:00
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
// reference: https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript/37511463
2018-10-11 13:52:49 +02:00
return input.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
2018-10-03 05:11:22 +02:00
}
}
export default RemoveDiacritics;