@uxf/localize 10.0.0-beta.43 → 10.0.0-beta.65
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/README.md
CHANGED
|
@@ -34,6 +34,10 @@ export const {
|
|
|
34
34
|
useFormatMoney,
|
|
35
35
|
useFormatNumber,
|
|
36
36
|
useFormatPercentage,
|
|
37
|
+
FormatDateTime,
|
|
38
|
+
FormatNumber,
|
|
39
|
+
FormatMoney,
|
|
40
|
+
FormatPercentage,
|
|
37
41
|
} = createLocale({ cs, en });
|
|
38
42
|
```
|
|
39
43
|
|
|
@@ -42,7 +46,7 @@ export const {
|
|
|
42
46
|
```ts
|
|
43
47
|
import {DateTimes, LocalizeConfig} from "@uxf/localize";
|
|
44
48
|
|
|
45
|
-
const en: LocalizeConfig = {
|
|
49
|
+
const en: LocalizeConfig<DateTimes> = {
|
|
46
50
|
number: {
|
|
47
51
|
thousandsSeparator: ",",
|
|
48
52
|
decimalSeparator: ".",
|
|
@@ -103,49 +107,57 @@ const cs: LocalizeConfig<DateTimes> = {
|
|
|
103
107
|
|
|
104
108
|
## Format number
|
|
105
109
|
```tsx
|
|
106
|
-
const { useFormatNumber } from "./localize";
|
|
110
|
+
const { useFormatNumber, FormatNumber } from "./localize";
|
|
107
111
|
|
|
108
112
|
const formatNumber = useFormatNumber();
|
|
109
113
|
|
|
110
114
|
formatNumber(1000.23); // 1 000
|
|
111
115
|
formatNumber(1000.23, { precision: 2 }); // 1 000,23
|
|
116
|
+
|
|
117
|
+
<FormatNumber value={1000.23}/>
|
|
112
118
|
```
|
|
113
119
|
|
|
114
120
|
## Format datetime
|
|
115
121
|
```tsx
|
|
116
|
-
const { useFormatDateTime } from "./localize";
|
|
122
|
+
const { useFormatDateTime, FormatDateTime } from "./localize";
|
|
117
123
|
|
|
118
124
|
const formatDateTime = useFormatDateTime();
|
|
119
125
|
|
|
120
|
-
formatDateTime(new Date('2000-01-01'), "dateShort") // 1. 1. 20
|
|
121
|
-
formatDateTime(new Date('2000-01-01'), "dateTimeMedium") // 1. 1. 2000 00:00
|
|
122
|
-
formatDateTime(new Date('2000-01-01'), "timeFull") // 00:00:00
|
|
126
|
+
formatDateTime(new Date('2000-01-01'), "dateShort"); // 1. 1. 20
|
|
127
|
+
formatDateTime(new Date('2000-01-01'), "dateTimeMedium"); // 1. 1. 2000 00:00
|
|
128
|
+
formatDateTime(new Date('2000-01-01'), "timeFull"); // 00:00:00
|
|
129
|
+
|
|
130
|
+
<FormatDateTime value={new Date('2000-01-01')} format="dateShort"/>
|
|
123
131
|
```
|
|
124
132
|
|
|
125
133
|
## Format money
|
|
126
134
|
```tsx
|
|
127
|
-
const { useFormatMoney } from "./localize";
|
|
135
|
+
const { useFormatMoney, FormatMoney } from "./localize";
|
|
128
136
|
|
|
129
137
|
const formatMoney = useFormatMoney();
|
|
130
138
|
|
|
131
|
-
formatMoney(1000, "CZK") // 1 000 Kč
|
|
132
|
-
formatMoney(1000, "USD") // 1 000 $
|
|
133
|
-
formatMoney(1000.23, "CZK", { precision: 1 }) // 1 000,2 Kč
|
|
134
|
-
formatMoney(1000.23, "CZK", { preferIsoCode: true }) // 1 000,23 CZK
|
|
135
|
-
formatMoney(1000.23, "CZK", { hideSymbol: true }) // 1 000,23
|
|
139
|
+
formatMoney({amount: 1000, currency: "CZK"}); // 1 000 Kč
|
|
140
|
+
formatMoney({amount: 1000, currency: "USD"}); // 1 000 $
|
|
141
|
+
formatMoney({amount: 1000.23, currency: "CZK"}, { precision: 1 }); // 1 000,2 Kč
|
|
142
|
+
formatMoney({amount: 1000.23, currency: "CZK"}, { preferIsoCode: true }); // 1 000,23 CZK
|
|
143
|
+
formatMoney({amount: 1000.23, currency: "CZK"}, { hideSymbol: true }); // 1 000,23
|
|
144
|
+
|
|
145
|
+
<FormatMoney money={{amount: 1000, currency: "CZK"}}/>
|
|
136
146
|
```
|
|
137
147
|
|
|
138
148
|
## Format percentage
|
|
139
149
|
|
|
140
150
|
```tsx
|
|
141
|
-
const { useFormatPercentage } from "./localize";
|
|
151
|
+
const { useFormatPercentage, FormatPercentage } from "./localize";
|
|
142
152
|
|
|
143
153
|
const formatPercentage = useFormatPercentage();
|
|
144
154
|
|
|
145
|
-
formatPercentage(0.782) // 78,2 %
|
|
146
|
-
formatPercentage(0.782, "nearest") // 78,2 %
|
|
147
|
-
formatPercentage(0.782, "up") // 78,2 %
|
|
148
|
-
formatPercentage(0.782, "down") // 78,2 %
|
|
155
|
+
formatPercentage(0.782); // 78,2 %
|
|
156
|
+
formatPercentage(0.782, "nearest"); // 78,2 %
|
|
157
|
+
formatPercentage(0.782, "up"); // 78,2 %
|
|
158
|
+
formatPercentage(0.782, "down"); // 78,2 %
|
|
159
|
+
|
|
160
|
+
<FormatPercentage value={0.782} roundingType="up" />
|
|
149
161
|
```
|
|
150
162
|
|
|
151
163
|
## Format another locale
|
package/package.json
CHANGED
|
@@ -8,9 +8,9 @@ const react_1 = __importDefault(require("react"));
|
|
|
8
8
|
const context_1 = require("../context/context");
|
|
9
9
|
const format_datetime_1 = require("../format-datetime/format-datetime");
|
|
10
10
|
function createFormatDatetimeComponent(localizeConfigs) {
|
|
11
|
-
const Component = (
|
|
11
|
+
const Component = (props) => {
|
|
12
12
|
const locale = (0, context_1._useLocalizeContext)();
|
|
13
|
-
return react_1.default.createElement(react_1.default.Fragment, null, (0, format_datetime_1.createFormatDatetime)(localizeConfigs)(locale, value, format));
|
|
13
|
+
return react_1.default.createElement(react_1.default.Fragment, null, (0, format_datetime_1.createFormatDatetime)(localizeConfigs)(locale, props.value, props.format));
|
|
14
14
|
};
|
|
15
15
|
return Component;
|
|
16
16
|
}
|
|
@@ -8,9 +8,9 @@ const react_1 = __importDefault(require("react"));
|
|
|
8
8
|
const context_1 = require("../context/context");
|
|
9
9
|
const format_money_1 = require("../format-money/format-money");
|
|
10
10
|
function createFormatMoneyComponent(localizeConfigs) {
|
|
11
|
-
const Component = (
|
|
11
|
+
const Component = (props) => {
|
|
12
12
|
const locale = (0, context_1._useLocalizeContext)();
|
|
13
|
-
return react_1.default.createElement(react_1.default.Fragment, null, (0, format_money_1.createFormatMoney)(localizeConfigs)(locale, money, options));
|
|
13
|
+
return react_1.default.createElement(react_1.default.Fragment, null, (0, format_money_1.createFormatMoney)(localizeConfigs)(locale, props.money, props.options));
|
|
14
14
|
};
|
|
15
15
|
return Component;
|
|
16
16
|
}
|
|
@@ -8,9 +8,9 @@ const react_1 = __importDefault(require("react"));
|
|
|
8
8
|
const context_1 = require("../context/context");
|
|
9
9
|
const format_number_1 = require("../format-number/format-number");
|
|
10
10
|
function createFormatNumberComponent(localizeConfigs) {
|
|
11
|
-
const Component = (
|
|
11
|
+
const Component = (props) => {
|
|
12
12
|
const locale = (0, context_1._useLocalizeContext)();
|
|
13
|
-
return react_1.default.createElement(react_1.default.Fragment, null, (0, format_number_1.createFormatNumber)(localizeConfigs)(locale, value, options));
|
|
13
|
+
return react_1.default.createElement(react_1.default.Fragment, null, (0, format_number_1.createFormatNumber)(localizeConfigs)(locale, props.value, props.options));
|
|
14
14
|
};
|
|
15
15
|
return Component;
|
|
16
16
|
}
|
|
@@ -8,9 +8,9 @@ const react_1 = __importDefault(require("react"));
|
|
|
8
8
|
const context_1 = require("../context/context");
|
|
9
9
|
const format_percentage_1 = require("../format-percentage/format-percentage");
|
|
10
10
|
function createFormatPercentageComponent(localizeConfigs) {
|
|
11
|
-
const Component = (
|
|
11
|
+
const Component = (props) => {
|
|
12
12
|
const locale = (0, context_1._useLocalizeContext)();
|
|
13
|
-
return react_1.default.createElement(react_1.default.Fragment, null, (0, format_percentage_1.createFormatPercentage)(localizeConfigs)(locale, value, roundingType, options));
|
|
13
|
+
return react_1.default.createElement(react_1.default.Fragment, null, (0, format_percentage_1.createFormatPercentage)(localizeConfigs)(locale, props.value, props.roundingType, props.options));
|
|
14
14
|
};
|
|
15
15
|
return Component;
|
|
16
16
|
}
|
package/src/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CURRENCIES } from "./utils/data";
|
|
2
|
-
import {
|
|
2
|
+
import { FC, Provider } from "react";
|
|
3
3
|
export type DateTimes = "timeShort" | "timeFull" | "dateShort" | "dateMedium" | "dateLong" | "dateShortNoYear" | "dateLongNoYear" | "dateTimeShort" | "dateTimeMedium" | "dateTimeLong";
|
|
4
4
|
export type LocalizeConfig<DT extends DateTimes> = {
|
|
5
5
|
number: {
|
|
@@ -23,16 +23,29 @@ export type Money = {
|
|
|
23
23
|
};
|
|
24
24
|
export type FormatNumberFunction<Locales extends string> = (locale: Locales, value: number, options?: FormatNumberOptions) => string;
|
|
25
25
|
export type UseFormatNumberFunction = () => (value: number, options?: FormatNumberOptions) => string;
|
|
26
|
-
export type FormatNumberComponent =
|
|
26
|
+
export type FormatNumberComponent = FC<{
|
|
27
|
+
value: number;
|
|
28
|
+
options?: FormatNumberOptions;
|
|
29
|
+
}>;
|
|
27
30
|
export type FormatMoneyFunction<Locales extends string> = (locale: Locales, money: Money, options?: FormatMoneyOptions) => string;
|
|
28
31
|
export type UseFormatMoneyFunction = () => (money: Money, options?: FormatMoneyOptions) => string;
|
|
29
|
-
export type FormatMoneyComponent =
|
|
32
|
+
export type FormatMoneyComponent = FC<{
|
|
33
|
+
money: Money;
|
|
34
|
+
options?: FormatMoneyOptions;
|
|
35
|
+
}>;
|
|
30
36
|
export type FormatPercentageFunction<Locales extends string> = (locale: Locales, value: number, roundingType?: RoundingType | null, options?: FormatPercentageOptions) => string;
|
|
31
37
|
export type UseFormatPercentageFunction = () => (value: number, roundingType?: RoundingType | null, options?: FormatPercentageOptions) => string;
|
|
32
|
-
export type FormatPercentageComponent =
|
|
38
|
+
export type FormatPercentageComponent = FC<{
|
|
39
|
+
value: number;
|
|
40
|
+
roundingType?: RoundingType | null;
|
|
41
|
+
options?: FormatPercentageOptions;
|
|
42
|
+
}>;
|
|
33
43
|
export type FormatDatetimeFunction<DT extends DateTimes, Locales extends string> = (locale: Locales, value: Date, format: DT) => string;
|
|
34
44
|
export type UseFormatDatetimeFunction<DT extends DateTimes> = () => (value: Date, format: DT) => string;
|
|
35
|
-
export type FormatDatetimeComponent<DT extends DateTimes> =
|
|
45
|
+
export type FormatDatetimeComponent<DT extends DateTimes> = FC<{
|
|
46
|
+
value: Date;
|
|
47
|
+
format: DT;
|
|
48
|
+
}>;
|
|
36
49
|
export type CreateLocalizeReturn<DT extends DateTimes, Locales extends string> = {
|
|
37
50
|
LocalizeProvider: LocalizeProviderType;
|
|
38
51
|
useLocaleConfig: UseLocaleConfigType<DT>;
|