UNPKG

1.54 kBTypeScriptView Raw
1import type { DefaultOptions } from "./_lib/defaultOptions.js";
2/**
3 * @name setDefaultOptions
4 * @category Common Helpers
5 * @summary Set default options including locale.
6 * @pure false
7 *
8 * @description
9 * Sets the defaults for
10 * `options.locale`, `options.weekStartsOn` and `options.firstWeekContainsDate`
11 * arguments for all functions.
12 *
13 * @param options - An object with options
14 *
15 * @example
16 * // Set global locale:
17 * import { es } from 'date-fns/locale'
18 * setDefaultOptions({ locale: es })
19 * const result = format(new Date(2014, 8, 2), 'PPPP')
20 * //=> 'martes, 2 de septiembre de 2014'
21 *
22 * @example
23 * // Start of the week for 2 September 2014:
24 * const result = startOfWeek(new Date(2014, 8, 2))
25 * //=> Sun Aug 31 2014 00:00:00
26 *
27 * @example
28 * // Start of the week for 2 September 2014,
29 * // when we set that week starts on Monday by default:
30 * setDefaultOptions({ weekStartsOn: 1 })
31 * const result = startOfWeek(new Date(2014, 8, 2))
32 * //=> Mon Sep 01 2014 00:00:00
33 *
34 * @example
35 * // Manually set options take priority over default options:
36 * setDefaultOptions({ weekStartsOn: 1 })
37 * const result = startOfWeek(new Date(2014, 8, 2), { weekStartsOn: 0 })
38 * //=> Sun Aug 31 2014 00:00:00
39 *
40 * @example
41 * // Remove the option by setting it to `undefined`:
42 * setDefaultOptions({ weekStartsOn: 1 })
43 * setDefaultOptions({ weekStartsOn: undefined })
44 * const result = startOfWeek(new Date(2014, 8, 2))
45 * //=> Sun Aug 31 2014 00:00:00
46 */
47export declare function setDefaultOptions(options: DefaultOptions): void;