Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { kebabCase, isPlainObject, isString, isNumber, isDate, each, clamp } from "lodash"
// Be sure to import the Polyfill
// TODO: Figure out if there is a ES2015 way to conditional load this
import "intl"
// NodeJS by default to not offer full ICU support and therefor break the unit tests
if (!areLocalesSupported([ "en", "de", "fr", "es" ]))
{
/* global IntlPolyfill */
Intl.NumberFormat = IntlPolyfill.NumberFormat
Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat
}
const formats = IntlMessageFormat.formats
const getCachedNumberFormat = createFormatCache(Intl.NumberFormat)
const getCachedDateTimeFormat = createFormatCache(Intl.DateTimeFormat)
const getCachedMessageFormat = createFormatCache(IntlMessageFormat)
const getCachedRelativeFormat = createFormatCache(IntlRelativeFormat)
// A constant defined by the standard Intl.NumberFormat
// const maximumFractionDigits = 20;
// Unfortunately through formatting issues of percent values in IE
// we have to use a small value here, because IE (as of v11) seems to
// account the percent symbol + optional space to the fraction digits.
// See also: https://github.com/sebastian-software/vue-locale/issues/1#issuecomment-215396481
const maximumFractionDigits = 18;
function install(Vue, options)
constructor ({
locale = 'en-US',
messages = {},
formats = {}
}: {
locale: string,
messages?: any,
formats?: any
}) {
this.locale = locale;
this.messages = messages;
this.formats = merge(MessageFormat.formats, defaultFormats, formats);
}
function deepMergeFormatsAndSetTimeZone(
f1: CustomFormats,
timeZone?: string
): CustomFormats {
if (!timeZone) {
return f1;
}
const mfFormats = IntlMessageFormat.formats;
return {
...mfFormats,
...f1,
date: deepMergeOptions(
setTimeZoneInOptions(mfFormats.date, timeZone),
setTimeZoneInOptions(f1.date || {}, timeZone)
),
time: deepMergeOptions(
setTimeZoneInOptions(mfFormats.time, timeZone),
setTimeZoneInOptions(f1.time || {}, timeZone)
),
};
}