refactor: 💡 formatter format/manual options logic

This commit is contained in:
Christian Kaisermann 2019-11-27 16:12:04 -03:00
parent 850fd09f32
commit 9d636694b1
3 changed files with 8 additions and 15 deletions

View File

@ -42,12 +42,9 @@ export const getDateFormatter: MemoizedIntlFormatter<
throw new Error('[svelte-i18n] A "locale" must be set to format dates')
}
const hasInlineArgs = Object.keys(options).length > 0
if (!hasInlineArgs) {
options =
typeof format === 'string'
? getIntlFormatterOptions('date', format)
: getIntlFormatterOptions('date', 'short')
if (format) options = getIntlFormatterOptions('date', format)
else if (Object.keys(options).length === 0) {
options = getIntlFormatterOptions('date', 'short')
}
return new Intl.DateTimeFormat(locale, options)
@ -64,12 +61,9 @@ export const getTimeFormatter: MemoizedIntlFormatter<
)
}
const hasInlineArgs = Object.keys(options).length > 0
if (!hasInlineArgs) {
options =
typeof format === 'string'
? getIntlFormatterOptions('time', format)
: getIntlFormatterOptions('time', 'short')
if (format) options = getIntlFormatterOptions('time', format)
else if (Object.keys(options).length === 0) {
options = getIntlFormatterOptions('time', 'short')
}
return new Intl.DateTimeFormat(locale, options)

View File

@ -5,7 +5,7 @@ export function defineMessages(i: Record<string, MessageObject>) {
return i
}
export { configure } from './configs'
export { init } from './configs'
export { $locale as locale } from './stores/locale'
export {
$dictionary as dictionary,

View File

@ -1,7 +1,6 @@
import { get } from 'svelte/store'
import { lookupMessage } from '../../../src/client/includes/lookup'
import {
isFallbackLocaleOf,
getFallbackOf,