diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /app/assets/javascripts/lib/utils/text_utility.js | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) | |
download | gitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'app/assets/javascripts/lib/utils/text_utility.js')
-rw-r--r-- | app/assets/javascripts/lib/utils/text_utility.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/app/assets/javascripts/lib/utils/text_utility.js b/app/assets/javascripts/lib/utils/text_utility.js index e2953ce330c..8ac6a44cba9 100644 --- a/app/assets/javascripts/lib/utils/text_utility.js +++ b/app/assets/javascripts/lib/utils/text_utility.js @@ -275,6 +275,81 @@ export const convertToSentenceCase = string => { */ export const convertToTitleCase = string => string.replace(/\b[a-z]/g, s => s.toUpperCase()); +const unicodeConversion = [ + [/[ÀÁÂÃÅĀĂĄ]/g, 'A'], + [/[Æ]/g, 'AE'], + [/[ÇĆĈĊČ]/g, 'C'], + [/[ÈÉÊËĒĔĖĘĚ]/g, 'E'], + [/[ÌÍÎÏĨĪĬĮİ]/g, 'I'], + [/[Ððĥħ]/g, 'h'], + [/[ÑŃŅŇʼn]/g, 'N'], + [/[ÒÓÔÕØŌŎŐ]/g, 'O'], + [/[ÙÚÛŨŪŬŮŰŲ]/g, 'U'], + [/[ÝŶŸ]/g, 'Y'], + [/[Þñþńņň]/g, 'n'], + [/[ߌŜŞŠ]/g, 'S'], + [/[àáâãåāăąĸ]/g, 'a'], + [/[æ]/g, 'ae'], + [/[çćĉċč]/g, 'c'], + [/[èéêëēĕėęě]/g, 'e'], + [/[ìíîïĩīĭį]/g, 'i'], + [/[òóôõøōŏő]/g, 'o'], + [/[ùúûũūŭůűų]/g, 'u'], + [/[ýÿŷ]/g, 'y'], + [/[ĎĐ]/g, 'D'], + [/[ďđ]/g, 'd'], + [/[ĜĞĠĢ]/g, 'G'], + [/[ĝğġģŊŋſ]/g, 'g'], + [/[ĤĦ]/g, 'H'], + [/[ıśŝşš]/g, 's'], + [/[IJ]/g, 'IJ'], + [/[ij]/g, 'ij'], + [/[Ĵ]/g, 'J'], + [/[ĵ]/g, 'j'], + [/[Ķ]/g, 'K'], + [/[ķ]/g, 'k'], + [/[ĹĻĽĿŁ]/g, 'L'], + [/[ĺļľŀł]/g, 'l'], + [/[Œ]/g, 'OE'], + [/[œ]/g, 'oe'], + [/[ŔŖŘ]/g, 'R'], + [/[ŕŗř]/g, 'r'], + [/[ŢŤŦ]/g, 'T'], + [/[ţťŧ]/g, 't'], + [/[Ŵ]/g, 'W'], + [/[ŵ]/g, 'w'], + [/[ŹŻŽ]/g, 'Z'], + [/[źżž]/g, 'z'], + [/ö/g, 'oe'], + [/ü/g, 'ue'], + [/ä/g, 'ae'], + // eslint-disable-next-line @gitlab/require-i18n-strings + [/Ö/g, 'Oe'], + // eslint-disable-next-line @gitlab/require-i18n-strings + [/Ü/g, 'Ue'], + // eslint-disable-next-line @gitlab/require-i18n-strings + [/Ä/g, 'Ae'], +]; + +/** + * Converts each non-ascii character in a string to + * it's ascii equivalent (if defined). + * + * e.g. "Dĭd söméònê äšk fœŕ Ůnĭċődę?" => "Did someone aesk foer Unicode?" + * + * @param {String} string + * @returns {String} + */ +export const convertUnicodeToAscii = string => { + let convertedString = string; + + unicodeConversion.forEach(([regex, replacer]) => { + convertedString = convertedString.replace(regex, replacer); + }); + + return convertedString; +}; + /** * Splits camelCase or PascalCase words * e.g. HelloWorld => Hello World |