@primate/core 0.8.2 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,17 +1,30 @@
|
|
|
1
|
+
import type Catalog from "#i18n/Catalog";
|
|
1
2
|
import type Catalogs from "#i18n/Catalogs";
|
|
3
|
+
import type { DotPaths, EntriesOf, ParamsFromEntries, PathValue } from "#i18n/types";
|
|
2
4
|
type RestoreRequest = {
|
|
3
5
|
cookies?: Record<string, string | undefined>;
|
|
4
6
|
};
|
|
7
|
+
export type Schema<C extends Catalogs> = C[keyof C] extends Catalog ? C[keyof C] : never;
|
|
8
|
+
export type Key<C extends Catalogs> = DotPaths<Schema<C>> & string;
|
|
9
|
+
type Resolved<C extends Catalogs, K extends string> = [
|
|
10
|
+
K
|
|
11
|
+
] extends [Key<C>] ? PathValue<Schema<C>, K> : never;
|
|
12
|
+
type Message<C extends Catalogs, K extends Key<C>> = Extract<Resolved<C, K>, string>;
|
|
13
|
+
type Params<C extends Catalogs, K extends Key<C>> = ParamsFromEntries<EntriesOf<Message<C, K>>>;
|
|
14
|
+
export type Args<C extends Catalogs, K extends string> = K extends Key<C> ? ([EntriesOf<Message<C, K>>] extends [never] ? [key: K] : [key: K, params: Params<C, K>]) : [`[i18n] Missing locale key "${K & string}".`];
|
|
15
|
+
export type Result<C extends Catalogs, K extends string> = K extends Key<C> ? (Resolved<C, K> extends string ? string : Resolved<C, K>) : string;
|
|
16
|
+
export type TFn<C extends Catalogs> = <K extends string>(...args: Args<C, K>) => Result<C, K>;
|
|
5
17
|
export default interface API<C extends Catalogs> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
18
|
+
defaultLocale: keyof C & string;
|
|
19
|
+
locales: readonly (keyof C & string)[];
|
|
20
|
+
catalogs: C;
|
|
21
|
+
currency: string;
|
|
22
|
+
locale: {
|
|
11
23
|
get(): keyof C & string;
|
|
12
24
|
set(locale: keyof C & string): void;
|
|
13
25
|
};
|
|
14
26
|
restore(request?: RestoreRequest): void;
|
|
27
|
+
with(locale: keyof C & string): TFn<C>;
|
|
15
28
|
}
|
|
16
29
|
export {};
|
|
17
30
|
//# sourceMappingURL=API.d.ts.map
|