Intl.Locale Exposes Week And Text Direction
Query runtime ICU regional defaults from Intl.Locale using getWeekInfo, getTextInfo, and getCalendars for week starts, weekends, and text direction.
Code
const tags = ['en-US', 'de-DE', 'ar-EG', 'ja-JP-u-ca-japanese'];
for (const tag of tags) {
const locale = new Intl.Locale(tag);
const week = locale.getWeekInfo();
const text = locale.getTextInfo();
const calendars = locale.getCalendars();
console.log(
tag.padEnd(18),
'dir:', text.direction,
'| firstDay:', week.firstDay,
'| weekend:', week.weekend.join(','),
'| cal:', calendars[0],
);
}Output
Captured from a sandboxed run of this snippet in the build pipeline.
en-US dir: ltr | firstDay: 7 | weekend: 6,7 | cal: gregory
de-DE dir: ltr | firstDay: 1 | weekend: 6,7 | cal: gregory
ar-EG dir: rtl | firstDay: 6 | weekend: 5,6 | cal: gregory
ja-JP-u-ca-japanese dir: ltr | firstDay: 7 | weekend: 6,7 | cal: japaneseCode mechanics — Intl.Locale Exposes Week And Text Direction
One loop does the cycling here: for (const tag of tags).
All sample computations reference top-level declarations: tags.
What to watch for
- The environment needs no preparation beyond having the interpreter or compiler.
Core lines
const locale = new Intl.Locale(tag);
Interactive Tools for This Topic
Dotenv File ParserParse .env file content into a JSON object, handling comments, export prefixes, single quotes, and double-quoted escape sequences.INI File ParserParse INI configuration files into nested JSON with section objects, global keys, and both semicolon and hash comment support.ISO Week CalculatorFind the ISO 8601 week number, ISO week-year, week start and end dates, and day of year for any calendar date, with strict date validation.JSON to TOML ConverterTurn a JSON object into TOML, emitting nested objects as tables and arrays of objects as array-of-tables blocks.
FAQ
- Does the code pull in any external packages?
- No external packages are involved; every call resolves to a built-in API. Its state lives in module-level bindings: `tags`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.