Skip to content

Instantly share code, notes, and snippets.

@vdloc
Forked from heeju/japanese-full-to-half-method.js
Created September 22, 2020 02:30
Show Gist options
  • Save vdloc/7f159545cbd7ce1e9a050bbd43572043 to your computer and use it in GitHub Desktop.
Save vdloc/7f159545cbd7ce1e9a050bbd43572043 to your computer and use it in GitHub Desktop.
Convert full-width Japanese character to half-width ascii character
String.prototype.toHalfWidth = function() {
return this.replace(/[!-~]/g, function(r){
return String.fromCharCode(r.charCodeAt(0) - 0xFEE0);
});
};
const convertFullToHalf = str => str.replace(/[!-~]/g, r => String.fromCharCode(r.charCodeAt(0) - 0xFEE0));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment