summaryrefslogtreecommitdiff
path: root/ext/js/language/text-preprocessors.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/language/text-preprocessors.js')
-rwxr-xr-xext/js/language/text-preprocessors.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/ext/js/language/text-preprocessors.js b/ext/js/language/text-preprocessors.js
index 12b3d1b6..e33fccda 100755
--- a/ext/js/language/text-preprocessors.js
+++ b/ext/js/language/text-preprocessors.js
@@ -33,3 +33,17 @@ export const capitalizeFirstLetter = {
options: basicTextPreprocessorOptions,
process: (str, setting) => (setting ? str.charAt(0).toUpperCase() + str.slice(1) : str)
};
+
+/**
+ * WARNING: This should NOT be used with languages that use Han characters,
+ * as it can result in undesirable normalization:
+ * - '\u9038'.normalize('NFD') => '\u9038' (逸)
+ * - '\ufa67'.normalize('NFD') => '\u9038' (逸 => 逸)
+ * @type {import('language').TextPreprocessor<boolean>}
+ */
+export const removeAlphabeticDiacritics = {
+ name: 'Remove Alphabetic Diacritics',
+ description: 'ἄήé -> αηe',
+ options: basicTextPreprocessorOptions,
+ process: (str, setting) => (setting ? str.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : str)
+};