From bb6dd015588626c7e008dff7bfcc9b34f3820877 Mon Sep 17 00:00:00 2001 From: Christian Kaisermann Date: Thu, 23 Jan 2020 10:32:56 -0300 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20oops,=20fix=20actual=20?= =?UTF-8?q?build-time=20types=20being=20git=20ignored?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- src/runtime/stores/dictionary.ts | 2 +- src/runtime/types/index.ts | 63 ++++++++++++++++++++++++++++++ test/runtime/stores/format.test.ts | 2 +- 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 src/runtime/types/index.ts diff --git a/.gitignore b/.gitignore index be0303b..0bdff84 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ node_modules *.log dist/ coverage/ -types/ \ No newline at end of file +/types/ \ No newline at end of file diff --git a/src/runtime/stores/dictionary.ts b/src/runtime/stores/dictionary.ts index 000c108..a4c5127 100644 --- a/src/runtime/stores/dictionary.ts +++ b/src/runtime/stores/dictionary.ts @@ -1,6 +1,6 @@ import { writable, derived } from 'svelte/store' -import { LocaleDictionary, DeepDictionary, Dictionary } from '../types/index' +import { LocaleDictionary, DeepDictionary, Dictionary } from '../types' import { flatObj } from '../includes/utils' import { getFallbackOf } from './locale' diff --git a/src/runtime/types/index.ts b/src/runtime/types/index.ts new file mode 100644 index 0000000..90dcdb4 --- /dev/null +++ b/src/runtime/types/index.ts @@ -0,0 +1,63 @@ +import { Formats } from 'intl-messageformat' + +export interface DeepDictionary { + [key: string]: DeepDictionary | string | string[] +} +export type LocaleDictionary = Record +export type Dictionary = Record + +export interface MessageObject { + id?: string + locale?: string + format?: string + default?: string + values?: Record +} + +export type MessageFormatter = ( + id: string | MessageObject, + options?: MessageObject +) => string + +export type TimeFormatter = ( + d: Date | number, + options?: IntlFormatterOptions +) => string + +export type DateFormatter = ( + d: Date | number, + options?: IntlFormatterOptions +) => string + +export type NumberFormatter = ( + d: number, + options?: IntlFormatterOptions +) => string + +type IntlFormatterOptions = T & { + format?: string + locale?: string +} + +export interface MemoizedIntlFormatter { + (options?: IntlFormatterOptions): T +} + +export interface MessagesLoader { + (): Promise +} + +export interface GetClientLocaleOptions { + navigator?: boolean + hash?: string + search?: string + pathname?: RegExp + hostname?: RegExp +} + +export interface ConfigureOptions { + fallbackLocale: string + initialLocale?: string | GetClientLocaleOptions + formats?: Partial + loadingDelay?: number +} diff --git a/test/runtime/stores/format.test.ts b/test/runtime/stores/format.test.ts index 7d2831b..b80fdbe 100644 --- a/test/runtime/stores/format.test.ts +++ b/test/runtime/stores/format.test.ts @@ -1,4 +1,4 @@ -import { Formatter } from '../../../src/runtime/types/index' +import { Formatter } from '../../../src/runtime/types' import { $format } from '../../../src/runtime/stores/format' import { init } from '../../../src/runtime/configs' import { addMessages } from '../../../src/runtime/stores/dictionary'