Skip to content

Instantly share code, notes, and snippets.

@sirtimid
Created November 8, 2016 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirtimid/4d0fc5bdcacc7b51ce2e0e505a4c0359 to your computer and use it in GitHub Desktop.
Save sirtimid/4d0fc5bdcacc7b51ce2e0e505a4c0359 to your computer and use it in GitHub Desktop.
Detonify a string in Javascript
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