How to use the relative-time-format.getDefaultLocale function in relative-time-format

To help you get started, we’ve selected a few relative-time-format examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github catamphetamine / javascript-time-ago / source / JavascriptTimeAgo.js View on Github external
constructor(locales = [])
	{
		// Convert `locales` to an array.
		if (typeof locales === 'string') {
			locales = [locales]
		}

		// Choose the most appropriate locale
		// (one of the previously added ones)
		// based on the list of preferred `locales` supplied by the user.
		this.locale = chooseLocale(
			locales.concat(RelativeTimeFormat.getDefaultLocale()),
			getLocaleData
		)

		// Use `Intl.NumberFormat` for formatting numbers (when available).
		if (typeof Intl !== 'undefined' && Intl.NumberFormat) {
			this.numberFormat = new Intl.NumberFormat(this.locale)
		}

		// Cache `Intl.RelativeTimeFormat` instance.
		this.relativeTimeFormatCache = new Cache()
	}