@uxf/localize 11.2.0 → 11.6.1
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.
- package/package.json +1 -1
- package/src/components/format-datetime.d.ts +2 -2
- package/src/components/format-money.d.ts +2 -2
- package/src/components/format-number.d.ts +2 -2
- package/src/components/format-percentage.d.ts +2 -2
- package/src/context/context.d.ts +2 -2
- package/src/format-datetime/format-datetime.d.ts +3 -3
- package/src/format-money/format-money.d.ts +3 -3
- package/src/format-number/format-number.d.ts +3 -3
- package/src/format-percentage/format-percentage.d.ts +3 -3
- package/src/index.d.ts +1 -1
- package/src/index.test.d.ts +1 -0
- package/src/index.test.js +21 -0
- package/src/types.d.ts +8 -8
package/package.json
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function createFormatDatetimeComponent<DT extends
|
|
1
|
+
import { FormatDatetimeComponent, LocalizeConfigMap } from "../types";
|
|
2
|
+
export declare function createFormatDatetimeComponent<DT extends string, Locales extends string>(localizeConfigs: LocalizeConfigMap<DT, Locales>): FormatDatetimeComponent<DT>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function createFormatMoneyComponent<
|
|
1
|
+
import { FormatMoneyComponent, LocalizeConfigMap } from "../types";
|
|
2
|
+
export declare function createFormatMoneyComponent<Locales extends string>(localizeConfigs: LocalizeConfigMap<never, Locales>): FormatMoneyComponent;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function createFormatNumberComponent<
|
|
1
|
+
import { FormatNumberComponent, LocalizeConfigMap } from "../types";
|
|
2
|
+
export declare function createFormatNumberComponent<Locales extends string>(localizeConfigs: LocalizeConfigMap<never, Locales>): FormatNumberComponent;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function createFormatPercentageComponent<
|
|
1
|
+
import { FormatPercentageComponent, LocalizeConfigMap } from "../types";
|
|
2
|
+
export declare function createFormatPercentageComponent<Locales extends string>(localizeConfigs: LocalizeConfigMap<never, Locales>): FormatPercentageComponent;
|
package/src/context/context.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
2
|
+
import { LocalizeConfigMap } from "../types";
|
|
3
3
|
export declare const _useLocalizeContext: () => string;
|
|
4
4
|
export declare const _LocalizeProvider: import("react").Provider<string>;
|
|
5
|
-
export declare const getLocaleConfigHook: <
|
|
5
|
+
export declare const getLocaleConfigHook: <DateTimes extends string, Locales extends string>(allConfigurations: LocalizeConfigMap<DateTimes, Locales>) => () => LocalizeConfigMap<DateTimes, Locales>[Locales];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function createFormatDatetime<DT extends
|
|
3
|
-
export declare function createUseFormatDatetime<DT extends
|
|
1
|
+
import { FormatDatetimeFunction, LocalizeConfigMap } from "../types";
|
|
2
|
+
export declare function createFormatDatetime<DT extends string, Locales extends string>(localizeConfigs: LocalizeConfigMap<DT, Locales>): FormatDatetimeFunction<DT, Locales>;
|
|
3
|
+
export declare function createUseFormatDatetime<DT extends string, Locales extends string>(localizeConfigs: LocalizeConfigMap<DT, Locales>): () => (value: import("../types").DateValue, format: DT) => string;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function createFormatMoney<
|
|
3
|
-
export declare function createUseFormatMoney<
|
|
1
|
+
import { FormatMoneyFunction, LocalizeConfigMap } from "../types";
|
|
2
|
+
export declare function createFormatMoney<Locales extends string>(localizeConfigs: LocalizeConfigMap<never, Locales>): FormatMoneyFunction<Locales>;
|
|
3
|
+
export declare function createUseFormatMoney<Locales extends string>(localizeConfigs: LocalizeConfigMap<never, Locales>): () => (money: import("../types").Money, options?: import("../types").FormatMoneyOptions | undefined) => string;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function createFormatNumber<
|
|
3
|
-
export declare function createUseFormatNumber<
|
|
1
|
+
import { FormatNumberFunction, LocalizeConfigMap } from "../types";
|
|
2
|
+
export declare function createFormatNumber<Locales extends string>(localizeConfigs: LocalizeConfigMap<never, Locales>): FormatNumberFunction<Locales>;
|
|
3
|
+
export declare function createUseFormatNumber<Locales extends string>(localizeConfigs: LocalizeConfigMap<never, Locales>): () => (value: number, options?: import("../types").FormatNumberOptions | undefined) => string;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function createFormatPercentage<
|
|
3
|
-
export declare function createUseFormatPercentage<
|
|
1
|
+
import { FormatPercentageFunction, LocalizeConfigMap, RoundingType } from "../types";
|
|
2
|
+
export declare function createFormatPercentage<Locales extends string>(localizeConfigs: LocalizeConfigMap<never, Locales>): FormatPercentageFunction<Locales>;
|
|
3
|
+
export declare function createUseFormatPercentage<Locales extends string>(localizeConfigs: LocalizeConfigMap<never, Locales>): () => (value: number, roundingType?: RoundingType | null | undefined, options?: import("../types").FormatPercentageOptions | undefined) => string;
|
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { CreateLocalizeReturn, DateTimes, LocalizeConfigMap } from "./types";
|
|
2
2
|
export * from "./get-currency-symbol/get-currency-symbol";
|
|
3
|
-
export declare function createLocalize<DT extends DateTimes, Locales extends string>(config: LocalizeConfigMap<DT, Locales>): CreateLocalizeReturn<DT, Locales>;
|
|
3
|
+
export declare function createLocalize<DT extends string = DateTimes, Locales extends string = string>(config: LocalizeConfigMap<DT, Locales>): CreateLocalizeReturn<DT, Locales>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const cs_1 = __importDefault(require("../locale/cs"));
|
|
7
|
+
const en_1 = __importDefault(require("../locale/en"));
|
|
8
|
+
const index_1 = require("./index");
|
|
9
|
+
const date = new Date("2023-07-21T07:58:35");
|
|
10
|
+
describe("basic createLocalize", function () {
|
|
11
|
+
it("basic usage", function () {
|
|
12
|
+
const { formatDateTime } = (0, index_1.createLocalize)({ cs: cs_1.default, en: en_1.default });
|
|
13
|
+
expect(formatDateTime("cs", date, "dateShort")).toBe("21. 7. 23");
|
|
14
|
+
});
|
|
15
|
+
it("use custom formats for dates", function () {
|
|
16
|
+
const { formatDateTime } = (0, index_1.createLocalize)({
|
|
17
|
+
cs: { ...cs_1.default, dateTime: { ...cs_1.default.dateTime, custom: "dd DD. MM." } },
|
|
18
|
+
});
|
|
19
|
+
expect(formatDateTime("cs", date, "custom")).toBe("Fr 21. 07.");
|
|
20
|
+
});
|
|
21
|
+
});
|
package/src/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FC, Provider } from "react";
|
|
2
2
|
import { CURRENCIES } from "./utils/data";
|
|
3
3
|
export type DateTimes = "timeShort" | "timeFull" | "dateShort" | "dateMedium" | "dateLong" | "dateShortNoYear" | "dateLongNoYear" | "dateTimeShort" | "dateTimeMedium" | "dateTimeLong";
|
|
4
|
-
export type LocalizeConfig<DT extends
|
|
4
|
+
export type LocalizeConfig<DT extends string> = {
|
|
5
5
|
number: {
|
|
6
6
|
thousandsSeparator: string;
|
|
7
7
|
decimalSeparator: string;
|
|
@@ -14,9 +14,9 @@ export type LocalizeConfig<DT extends DateTimes> = {
|
|
|
14
14
|
};
|
|
15
15
|
dateTime: Record<DT, string>;
|
|
16
16
|
};
|
|
17
|
-
export type LocalizeConfigMap<DT extends DateTimes, Locales extends string> = Record<Locales, LocalizeConfig<DT>>;
|
|
17
|
+
export type LocalizeConfigMap<DT extends string = DateTimes, Locales extends string = string> = Record<Locales, LocalizeConfig<DT>>;
|
|
18
18
|
export type LocalizeProviderType = Provider<string>;
|
|
19
|
-
export type UseLocaleConfigType<DT extends
|
|
19
|
+
export type UseLocaleConfigType<DT extends string> = () => LocalizeConfig<DT>;
|
|
20
20
|
export type Money = {
|
|
21
21
|
amount: string;
|
|
22
22
|
currency: Currency;
|
|
@@ -43,13 +43,13 @@ export type FormatPercentageComponent = FC<{
|
|
|
43
43
|
export type DateString = `${number}-${number}-${number}`;
|
|
44
44
|
export type DateTimeString = `${number}-${number}-${number}T${number}:${number}:${number}+${number}:${number}`;
|
|
45
45
|
export type DateValue = Date | DateString | DateTimeString;
|
|
46
|
-
export type FormatDatetimeFunction<DT extends
|
|
47
|
-
export type UseFormatDatetimeFunction<DT extends
|
|
48
|
-
export type FormatDatetimeComponent<DT extends
|
|
49
|
-
value:
|
|
46
|
+
export type FormatDatetimeFunction<DT extends string, Locales extends string> = (locale: Locales, value: DateValue, format: DT) => string;
|
|
47
|
+
export type UseFormatDatetimeFunction<DT extends string> = () => (value: DateValue, format: DT) => string;
|
|
48
|
+
export type FormatDatetimeComponent<DT extends string> = FC<{
|
|
49
|
+
value: DateValue;
|
|
50
50
|
format: DT;
|
|
51
51
|
}>;
|
|
52
|
-
export type CreateLocalizeReturn<DT extends
|
|
52
|
+
export type CreateLocalizeReturn<DT extends string, Locales extends string> = {
|
|
53
53
|
LocalizeProvider: LocalizeProviderType;
|
|
54
54
|
useLocaleConfig: UseLocaleConfigType<DT>;
|
|
55
55
|
formatNumber: FormatNumberFunction<Locales>;
|