@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
41 lines (39 loc) • 1.03 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
//#region src/localization/getHTMLTextDir.ts
/**
* Returns the text direction of the given locale.
*
* Example:
*
* getHTMLTextDir('en-US') // 'ltr'
* getHTMLTextDir('en') // 'ltr'
* getHTMLTextDir('fr-CA') // 'ltr'
* getHTMLTextDir('fr') // 'ltr'
*
* @param locale The locale to get the text direction for.
* @returns The text direction of the given locale.
*/
const getHTMLTextDir = (locale) => {
if (!locale) return "ltr";
try {
const localeInfo = new Intl.Locale(locale);
if ("getTextInfo" in localeInfo) return localeInfo.getTextInfo().direction;
if ("textInfo" in localeInfo) return localeInfo.textInfo.direction;
const maximized = localeInfo.maximize();
return [
"Arab",
"Hebr",
"Thaa",
"Syrc",
"Mand",
"Adlm",
"Rohg",
"Nkoo"
].includes(maximized.script ?? "") ? "rtl" : "ltr";
} catch {
return "ltr";
}
};
//#endregion
exports.getHTMLTextDir = getHTMLTextDir;
//# sourceMappingURL=getHTMLTextDir.cjs.map