2018-10-03 13:11:22 +10:00
/ * *
* @ author Klaxon [ klaxon @ veyr . com ]
* @ copyright Crown Copyright 2018
* @ license Apache - 2.0
* /
2019-07-09 12:23:59 +01:00
import Operation from "../Operation.mjs" ;
2018-10-03 13:11:22 +10:00
/ * *
2018-11-07 15:07:54 +00:00
* Remove Diacritics operation
2018-10-03 13:11:22 +10:00
* /
2018-11-07 15:07:54 +00:00
class RemoveDiacritics extends Operation {
2018-10-03 13:11:22 +10:00
/ * *
2018-11-07 15:07:54 +00:00
* RemoveDiacritics constructor
2018-10-03 13:11:22 +10:00
* /
constructor ( ) {
super ( ) ;
2018-11-07 15:07:54 +00:00
this . name = "Remove Diacritics" ;
2018-10-03 13:11:22 +10:00
this . module = "Default" ;
2020-08-19 10:55:29 +01:00
this . description = "Replaces accented characters with their latin character equivalent. Accented characters are made up of Unicode combining characters, so unicode text formatting such as strikethroughs and underlines will also be removed." ;
2018-11-07 15:07:54 +00:00
this . infoURL = "https://wikipedia.org/wiki/Diacritic" ;
2018-10-03 13:11:22 +10:00
this . inputType = "string" ;
this . outputType = "string" ;
2018-11-07 15:07:54 +00:00
this . args = [ ] ;
2018-10-03 13:11:22 +10:00
}
/ * *
* @ param { string } input
* @ param { Object [ ] } args
* @ returns { string }
* /
run ( input , args ) {
2018-11-07 15:07:54 +00:00
// reference: https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript/37511463
2018-10-11 21:52:49 +10:00
return input . normalize ( "NFD" ) . replace ( /[\u0300-\u036f]/g , "" ) ;
2018-10-03 13:11:22 +10:00
}
}
2018-11-07 15:07:54 +00:00
export default RemoveDiacritics ;