configure()
configure(settings?): ActiveSettingsUpdates one or more process-wide defaults and returns a snapshot of the active configuration. Calling it with no arguments reads the current settings without changing them.
Omitted properties keep their current values. Pass null for any setting to restore the runtime and built-in defaults.
import { configure, date, datetime } from 'native-dates';
configure({
zone: 'Europe/Berlin',
locale: 'de-DE',
});
datetime('2026-11-16T17:30:00Z').zone; // 'Europe/Berlin'
date('2026-11-18').startOf('week').toString(); // '2026-11-16'
configure().weekStart; // undefined
configure({ weekStart: 'sunday' });
date('2026-11-18').startOf('week').toString(); // '2026-11-15'
configure().weekStart; // 7
// reset back to the runtime zone, runtime locale, and locale week start
configure({ zone: null, locale: null, weekStart: null });Parameters
Process-wide defaults to update. Omitted keys stay unchanged.
8 options
Default time zone for factories and now(). Pass null to reset to the runtime's local zone.
Default locale tag, tag list, or Accept-Language header for formatting, week boundaries, weekends, and plugins. Pass null or '' to reset to the runtime's locale.
First day of the week for week boundaries and weekdayNames(), from 1 for Monday through 7 for Sunday. Unset or null follows the active locale.
Custom weekday labels keyed by language, width (narrow, short, or long), and day name. Regional tags layer over their base language, and an empty value restores runtime names.
Custom Do day-of-month formatter keyed by language tag. Pass null to restore built-in English suffixes and locale day markers.
Reusable custom formats passed to format(name), where each value is a token pattern or Intl options object. Custom names take precedence over built-in presets, and null clears them.
Default numeric date order for loose calls that omit per-call dayFirst and locale. Unset or null follows the active locale.
Custom names mapped to zones with @native-dates/plugins/zones. Pass null for a key or the whole map to clear aliases.
Returns
A shallow copy of the active settings after applying updates. Unset keys return undefined.
The weekdayNames and ordinals settings change what token patterns and weekdayNames() print, without plugins:
import { configure, date, weekdayNames } from 'native-dates';
configure({
weekdayNames: { lv: { narrow: { fri: 'Pk', sun: 'Sv' } } },
ordinals: { fr: (day) => (day === 1 ? '1er' : day) },
});
date('2026-11-01').format('Do MMMM', 'fr'); // '1er novembre'
weekdayNames('narrow', 'monday', 'lv'); // ['P', 'O', 'T', 'C', 'Pk', 'S', 'Sv']
configure({ weekdayNames: null, ordinals: null });Named formats give an app its own presets on every type that formats a date or time:
import { configure, date, datetime } from 'native-dates';
configure({
formats: {
invoice: 'YYYY-MM-DD',
receipt: { weekday: 'long', month: 'long', day: 'numeric' },
},
});
date('2026-11-06').format('invoice'); // '2026-11-06'
datetime('2026-11-06T09:05', 'Europe/Berlin').format('receipt'); // 'Friday, November 6'
configure({ formats: null });Plugins extend configure() with their own options once imported. Setting a plugin option before importing its plugin throws a RangeError:
import { configure, date, now } from 'native-dates';
import '@native-dates/plugins/loose';
import '@native-dates/plugins/zones';
configure({
dayFirst: true,
zoneAliases: { hq: 'Europe/Berlin' },
});
date('07.09.2026', { loose: true })?.toString(); // '2026-09-07'
now('hq').zone; // 'Europe/Berlin'
configure({ dayFirst: null });