Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide regexes to bulkReplace when possible #22

Closed
pillowfication opened this issue Aug 5, 2020 · 2 comments · Fixed by #27
Closed

Provide regexes to bulkReplace when possible #22

pillowfication opened this issue Aug 5, 2020 · 2 comments · Fixed by #27

Comments

@pillowfication
Copy link
Contributor

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

@lovell
Copy link
Owner

lovell commented Aug 5, 2020

Happy to accept a PR if you're able.

@lovell
Copy link
Owner

lovell commented Sep 8, 2023

v1.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants