UNPKG

@enact/i18n

Version:

Internationalization support for Enact using iLib

106 lines (99 loc) 2.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toCapitalized = exports.isRtlText = void 0; Object.defineProperty(exports, "toLowerCase", { enumerable: true, get: function get() { return _case.toLowerCase; } }); Object.defineProperty(exports, "toUpperCase", { enumerable: true, get: function get() { return _case.toUpperCase; } }); exports.toWordCase = void 0; require("../src/glue"); var _case = require("../src/case"); /** * A collection of locale-aware text utility function. * * @module i18n/util * @exports isRtlText * @exports toCapitalized * @exports toLowerCase * @exports toUpperCase * @exports toWordCase */ /* * This regex pattern is used by the {@link i18n/utils.isRtlText|isRtlText()} function. * * Arabic: \u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFE * Hebrew: \u0590-\u05FF\uFB1D-\uFB4F * * @private */ var rtlPattern = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFE\u0590-\u05FF\uFB1D-\uFB4F]/; /** * Takes content `str` and determines whether or not it is {@link /docs/developer-guide/glossary/#rtl|RTL}. * * @function * @memberof i18n/util * @param {String} str - A string to check the {@link /docs/developer-guide/glossary/#rtl|RTL}-ness of. * @returns {Boolean} `true` if `str` should be RTL; `false` if not. * @public */ var isRtlText = exports.isRtlText = function isRtlText(str) { if (typeof str === 'string') { return rtlPattern.test(str); } return false; }; /** * Capitalizes the first letter of a given string (locale aware). * * @function * @memberof i18n/util * @param {String} str - The string to capitalize. * @returns {String} The capitalized string. * @public */ var toCapitalized = exports.toCapitalized = function toCapitalized(str) { return (0, _case.toUpperCase)(str.slice(0, 1)) + str.slice(1); }; /** * Capitalizes every word in a string. Words are separated by spaces, not necessarily * word-breaks (locale aware). * * @function * @memberof i18n/util * @param {String} str - The string to capitalize. * @returns {String} The word-cased string. * @public */ var toWordCase = exports.toWordCase = function toWordCase(str) { return str.split(' ').map(toCapitalized).join(' '); }; /** * Locale-safely convert a string to lower case. * * @name toLowerCase * @function * @memberof i18n/util * @param {String} inString String to convert to lower case * @returns {String} Lower-cased string * @public */ /** * Locale-safely convert a string to upper case. * * @name toUpperCase * @function * @memberof i18n/util * @param {String} inString String to convert to upper case * @returns {String} Upper-cased string * @public */