getLocaleDirection
getLocaleDirection(locale) returns text direction for a locale tag:
'rtl'for right-to-left locales'ltr'for left-to-right locales
This function uses `Intl.Locale`.
ts
1import { getLocaleDirection } from '@beforesemicolon/intl'2 3getLocaleDirection('en-US') // "ltr"4getLocaleDirection('ar') // "rtl"5getLocaleDirection('fa') // "rtl"6getLocaleDirection('zh-Hant') // "ltr"Signature
ts
1function getLocaleDirection(locale: string): 'ltr' | 'rtl'Practical notes
- invalid locale values return
'ltr'instead of throwing - this is useful for pre-setting
dirbefore runtime loading completes - call this whenever you need a deterministic fallback while a runtime settles
ts
1document.documentElement.dir = getLocaleDirection(selectedLocale)