UNPKG

@intlayer/core

Version:

Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.

39 lines (38 loc) 940 B
//#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 export { getHTMLTextDir }; //# sourceMappingURL=getHTMLTextDir.mjs.map