Created
November 8, 2016 23:45
-
-
Save sirtimid/4d0fc5bdcacc7b51ce2e0e505a4c0359 to your computer and use it in GitHub Desktop.
Detonify a string in Javascript
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
String.prototype.detonify = function () { | |
'use strict'; | |
// set string of characters with tones | |
let tones = 'ΆάΈέΉήΌόΎύΏώΊΪϊίΫϋ'.split('') | |
// set the equivalent string of characters without tones | |
let detones = 'ΑαΕεΗηΟοΥυΩωΙΙιιΥυ'.split('') | |
let str = this.toString() | |
for (let key in tones) { | |
let regex = new RegExp(tones[key], 'g') | |
str = str.replace(regex, detones[key] || tones[key]) | |
} | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment