hepburn icon indicating copy to clipboard operation
hepburn copied to clipboard

Provide regexes to `bulkReplace` when possible

Open pillowfication opened this issue 3 years ago • 1 comments

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

pillowfication avatar Aug 05 '20 00:08 pillowfication

Happy to accept a PR if you're able.

lovell avatar Aug 05 '20 19:08 lovell

v1.2.1

lovell avatar Sep 08 '23 08:09 lovell