hepburn
hepburn copied to clipboard
Provide regexes to `bulkReplace` when possible
The bulk-replace
package creates a new RegExp every time if one is not provided. Providing a regex offers a significant performance boost.
// Initial transliteration
// str = bulkReplace(str, /[ヲ-ン][゙゚]/g, katakanaHalfwidthsCombined);
// str = bulkReplace(str, /[ヲ-ン]/g, katakanaHalfwidths);
str = bulkReplace(str, /[ぁ-ゖゟ][ぁぃぅぇぉゃゅょ]/g, hiraganaDigraphs);
str = bulkReplace(str, /[ァ-ヺー][ァィゥェォャュョ]/g, katakanaDigraphs);
str = bulkReplace(str, /[ぁ-ゖゟ]/g, hiraganaMonographs);
str = bulkReplace(str, /[ァ-ヺー]/g, katakanaMonographs);
JSPerf: https://jsperf.com/katakana-monographs
Happy to accept a PR if you're able.
v1.2.1