Last active
October 15, 2024 03:22
-
-
Save kawanet/5553478 to your computer and use it in GitHub Desktop.
カタカナをひらがなに変換する JavaScript 関数、
ひらがなをカタカナに変換する 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
/** カタカナをひらがなに変換する関数 | |
* @param {String} src - カタカナ | |
* @returns {String} - ひらがな | |
*/ | |
function katakanaToHiragana(src) { | |
return src.replace(/[\u30a1-\u30f6]/g, function(match) { | |
var chr = match.charCodeAt(0) - 0x60; | |
return String.fromCharCode(chr); | |
}); | |
} | |
/** ひらがなをカタカナに変換する関数 | |
* @param {String} src - ひらがな | |
* @returns {String} - カタカナ | |
*/ | |
function hiraganaToKatagana(src) { | |
return src.replace(/[\u3041-\u3096]/g, function(match) { | |
var chr = match.charCodeAt(0) + 0x60; | |
return String.fromCharCode(chr); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ないす!!