From 9d636694b18629a05d2609d0ffe1c05b44ff79f4 Mon Sep 17 00:00:00 2001 From: Christian Kaisermann Date: Wed, 27 Nov 2019 16:12:04 -0300 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20formatter=20format/m?= =?UTF-8?q?anual=20options=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/includes/formatters.ts | 18 ++++++------------ src/client/index.ts | 2 +- test/client/stores/locale.test.ts | 3 +-- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/client/includes/formatters.ts b/src/client/includes/formatters.ts index abe1cb9..7040289 100644 --- a/src/client/includes/formatters.ts +++ b/src/client/includes/formatters.ts @@ -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) diff --git a/src/client/index.ts b/src/client/index.ts index 2f94c4f..861faf3 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -5,7 +5,7 @@ export function defineMessages(i: Record) { return i } -export { configure } from './configs' +export { init } from './configs' export { $locale as locale } from './stores/locale' export { $dictionary as dictionary, diff --git a/test/client/stores/locale.test.ts b/test/client/stores/locale.test.ts index 01583ae..1a44a20 100644 --- a/test/client/stores/locale.test.ts +++ b/test/client/stores/locale.test.ts @@ -1,7 +1,6 @@ import { get } from 'svelte/store' + import { lookupMessage } from '../../../src/client/includes/lookup' - - import { isFallbackLocaleOf, getFallbackOf,