@uxf/localize 10.0.0-beta.21
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 +66 -0
- package/index.d.ts +2 -0
- package/index.js +17 -0
- package/locale/cs.d.ts +3 -0
- package/locale/cs.js +25 -0
- package/locale/de.d.ts +3 -0
- package/locale/de.js +25 -0
- package/locale/en.d.ts +3 -0
- package/locale/en.js +25 -0
- package/locale/es.d.ts +3 -0
- package/locale/es.js +25 -0
- package/locale/fr.d.ts +3 -0
- package/locale/fr.js +25 -0
- package/locale/pl.d.ts +3 -0
- package/locale/pl.js +25 -0
- package/locale/sk.d.ts +3 -0
- package/locale/sk.js +25 -0
- package/package.json +22 -0
- package/src/context/context.d.ts +5 -0
- package/src/context/context.js +13 -0
- package/src/format-datetime/format-datetime.d.ts +3 -0
- package/src/format-datetime/format-datetime.js +19 -0
- package/src/format-datetime/format-datetime.test.d.ts +1 -0
- package/src/format-datetime/format-datetime.test.js +30 -0
- package/src/format-money/format-money.d.ts +3 -0
- package/src/format-money/format-money.js +28 -0
- package/src/format-money/format-money.test.d.ts +1 -0
- package/src/format-money/format-money.test.js +31 -0
- package/src/format-number/format-number.d.ts +3 -0
- package/src/format-number/format-number.js +22 -0
- package/src/format-number/format-number.test.d.ts +1 -0
- package/src/format-number/format-number.test.js +19 -0
- package/src/format-percentage/format-percentage.d.ts +3 -0
- package/src/format-percentage/format-percentage.js +23 -0
- package/src/format-percentage/format-percentage.test.d.ts +1 -0
- package/src/format-percentage/format-percentage.test.js +25 -0
- package/src/get-currency-symbol/get-currency-symbol.d.ts +2 -0
- package/src/get-currency-symbol/get-currency-symbol.js +6 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +38 -0
- package/src/types.d.ts +52 -0
- package/src/types.js +2 -0
- package/src/utils/curry.d.ts +4 -0
- package/src/utils/curry.js +11 -0
- package/src/utils/data.d.ts +299 -0
- package/src/utils/data.js +104 -0
- package/src/utils/map-options.d.ts +3 -0
- package/src/utils/map-options.js +12 -0
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @uxf/localize
|
|
2
|
+
[](https://www.npmjs.com/package/@uxf/localize)
|
|
3
|
+
[](https://www.npmjs.com/package/@uxf/localize)
|
|
4
|
+
[](https://www.npmjs.com/package/@uxf/localize)
|
|
5
|
+
[](https://www.npmjs.com/package/@uxf/localize)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
yarn add @uxf/localize
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @uxf/localize
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Basic usage
|
|
18
|
+
|
|
19
|
+
### Initialize and configure package
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { createLocalize } from "@uxf/localize";
|
|
23
|
+
import cs from "@uxf/localize/locale/cs";
|
|
24
|
+
import en from "@uxf/localize/locale/en";
|
|
25
|
+
|
|
26
|
+
export const {
|
|
27
|
+
LocalizeProvider,
|
|
28
|
+
formatDateTime,
|
|
29
|
+
formatMoney,
|
|
30
|
+
formatNumber,
|
|
31
|
+
formatPercentage,
|
|
32
|
+
useFormatDateTime,
|
|
33
|
+
useFormatMoney,
|
|
34
|
+
useFormatNumber,
|
|
35
|
+
useFormatPercentage,
|
|
36
|
+
} = createLocale({ cs, en });
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Implement context provider
|
|
40
|
+
|
|
41
|
+
use LocalizeProvider in **_app.tsx**
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
<LocalizeProvider locale="en">{props.children}</LocalizeProvider>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Format for default locale
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { useFormatMoney } from "...";
|
|
51
|
+
|
|
52
|
+
const formatMoney = useFormatMoney();
|
|
53
|
+
|
|
54
|
+
formatMoney(5800, "EUR"); // €5.800
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Format for another locale
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { formatMoney } from "...";
|
|
61
|
+
|
|
62
|
+
formatMoney("cs", 5800, "EUR"); // 5 800 €
|
|
63
|
+
formatMoney("cs", 5800, "EUR", { preferIsoCode: true }); // 5 800 EUR
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
This approach is consistent for all the methods, so you can format numbers, money, percentage and date times.
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./src"), exports);
|
package/locale/cs.d.ts
ADDED
package/locale/cs.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const locale = {
|
|
4
|
+
number: {
|
|
5
|
+
thousandsSeparator: "\xa0",
|
|
6
|
+
decimalSeparator: ",",
|
|
7
|
+
},
|
|
8
|
+
currency: {
|
|
9
|
+
thousandsSeparator: "\xa0",
|
|
10
|
+
decimalSeparator: ",",
|
|
11
|
+
pattern: "#\xa0!",
|
|
12
|
+
negativePattern: "-#\xa0!",
|
|
13
|
+
},
|
|
14
|
+
dateTime: {
|
|
15
|
+
timeShort: "H:mm",
|
|
16
|
+
timeFull: "H:mm:ss",
|
|
17
|
+
dateShort: "D. M. YY",
|
|
18
|
+
dateMedium: "D. M. YYYY",
|
|
19
|
+
dateLong: "D. MMMM YYYY",
|
|
20
|
+
dateTimeShort: "D. M. YY, H:mm",
|
|
21
|
+
dateTimeMedium: "D. M. YYYY, H:mm",
|
|
22
|
+
dateTimeLong: "D. MMMM YYYY, H:mm:ss",
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
exports.default = locale;
|
package/locale/de.d.ts
ADDED
package/locale/de.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const locale = {
|
|
4
|
+
number: {
|
|
5
|
+
thousandsSeparator: ".",
|
|
6
|
+
decimalSeparator: ",",
|
|
7
|
+
},
|
|
8
|
+
currency: {
|
|
9
|
+
thousandsSeparator: ".",
|
|
10
|
+
decimalSeparator: ",",
|
|
11
|
+
pattern: "! #",
|
|
12
|
+
negativePattern: "-! #",
|
|
13
|
+
},
|
|
14
|
+
dateTime: {
|
|
15
|
+
timeShort: "H:mm",
|
|
16
|
+
timeFull: "H:mm:ss",
|
|
17
|
+
dateShort: "D. M. YY",
|
|
18
|
+
dateMedium: "D. M. YYYY",
|
|
19
|
+
dateLong: "D. MMMM YYYY",
|
|
20
|
+
dateTimeShort: "D. M. YY, H:mm",
|
|
21
|
+
dateTimeMedium: "D. M. YYYY, H:mm",
|
|
22
|
+
dateTimeLong: "D. MMMM YYYY, H:mm:ss",
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
exports.default = locale;
|
package/locale/en.d.ts
ADDED
package/locale/en.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const locale = {
|
|
4
|
+
number: {
|
|
5
|
+
thousandsSeparator: ",",
|
|
6
|
+
decimalSeparator: ".",
|
|
7
|
+
},
|
|
8
|
+
currency: {
|
|
9
|
+
thousandsSeparator: ",",
|
|
10
|
+
decimalSeparator: ".",
|
|
11
|
+
pattern: "!#",
|
|
12
|
+
negativePattern: "-!#",
|
|
13
|
+
},
|
|
14
|
+
dateTime: {
|
|
15
|
+
timeShort: "H:mm A",
|
|
16
|
+
timeFull: "H:mm:ss A",
|
|
17
|
+
dateShort: "M/D/YY",
|
|
18
|
+
dateMedium: "M/D/YYYY",
|
|
19
|
+
dateLong: "MMMM D. YYYY",
|
|
20
|
+
dateTimeShort: "M/D/YY H:mm A",
|
|
21
|
+
dateTimeMedium: "M/D/YYYY H:mm A",
|
|
22
|
+
dateTimeLong: "MMMM D. YYYY H:mm:ss A",
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
exports.default = locale;
|
package/locale/es.d.ts
ADDED
package/locale/es.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const locale = {
|
|
4
|
+
number: {
|
|
5
|
+
thousandsSeparator: ".",
|
|
6
|
+
decimalSeparator: ",",
|
|
7
|
+
},
|
|
8
|
+
currency: {
|
|
9
|
+
thousandsSeparator: ".",
|
|
10
|
+
decimalSeparator: ",",
|
|
11
|
+
pattern: "! #",
|
|
12
|
+
negativePattern: "-! #",
|
|
13
|
+
},
|
|
14
|
+
dateTime: {
|
|
15
|
+
timeShort: "H:mm",
|
|
16
|
+
timeFull: "H:mm:ss",
|
|
17
|
+
dateShort: "DD/MM/YY",
|
|
18
|
+
dateMedium: "D MMM YYYY",
|
|
19
|
+
dateLong: "D MMMM YYYY",
|
|
20
|
+
dateTimeShort: "DD/MM/YY, H:mm",
|
|
21
|
+
dateTimeMedium: "D MMM YYYY, H:mm",
|
|
22
|
+
dateTimeLong: "D MMMM YYYY, H:mm:ss",
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
exports.default = locale;
|
package/locale/fr.d.ts
ADDED
package/locale/fr.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const locale = {
|
|
4
|
+
number: {
|
|
5
|
+
thousandsSeparator: " ",
|
|
6
|
+
decimalSeparator: ",",
|
|
7
|
+
},
|
|
8
|
+
currency: {
|
|
9
|
+
thousandsSeparator: " ",
|
|
10
|
+
decimalSeparator: ",",
|
|
11
|
+
pattern: "! #",
|
|
12
|
+
negativePattern: "-! #",
|
|
13
|
+
},
|
|
14
|
+
dateTime: {
|
|
15
|
+
timeShort: "HH:mm",
|
|
16
|
+
timeFull: "HH:mm:ss",
|
|
17
|
+
dateShort: "DD/MM/YY",
|
|
18
|
+
dateMedium: "D MMM YYYY",
|
|
19
|
+
dateLong: "D MMMM YYYY",
|
|
20
|
+
dateTimeShort: "DD/MM/YY, HH:mm",
|
|
21
|
+
dateTimeMedium: "D MMM YYYY, HH:mm",
|
|
22
|
+
dateTimeLong: "D MMMM YYYY, HH:mm:ss",
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
exports.default = locale;
|
package/locale/pl.d.ts
ADDED
package/locale/pl.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const locale = {
|
|
4
|
+
number: {
|
|
5
|
+
thousandsSeparator: " ",
|
|
6
|
+
decimalSeparator: ",",
|
|
7
|
+
},
|
|
8
|
+
currency: {
|
|
9
|
+
thousandsSeparator: " ",
|
|
10
|
+
decimalSeparator: ",",
|
|
11
|
+
pattern: "# !",
|
|
12
|
+
negativePattern: "-# !",
|
|
13
|
+
},
|
|
14
|
+
dateTime: {
|
|
15
|
+
timeShort: "HH:mm",
|
|
16
|
+
timeFull: "HH:mm:ss",
|
|
17
|
+
dateShort: "D.MM.YY",
|
|
18
|
+
dateMedium: "D.MM.YYYY",
|
|
19
|
+
dateLong: "D. MMMM YYYY",
|
|
20
|
+
dateTimeShort: "D.MM.YY, HH:mm",
|
|
21
|
+
dateTimeMedium: "D.MM.YYYY, HH:mm",
|
|
22
|
+
dateTimeLong: "D. MMMM YYYY, HH:mm:ss",
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
exports.default = locale;
|
package/locale/sk.d.ts
ADDED
package/locale/sk.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const locale = {
|
|
4
|
+
number: {
|
|
5
|
+
thousandsSeparator: " ",
|
|
6
|
+
decimalSeparator: ",",
|
|
7
|
+
},
|
|
8
|
+
currency: {
|
|
9
|
+
thousandsSeparator: " ",
|
|
10
|
+
decimalSeparator: ",",
|
|
11
|
+
pattern: "!#",
|
|
12
|
+
negativePattern: "-!#",
|
|
13
|
+
},
|
|
14
|
+
dateTime: {
|
|
15
|
+
timeShort: "H:mm",
|
|
16
|
+
timeFull: "H:mm:ss",
|
|
17
|
+
dateShort: "D. M. YY",
|
|
18
|
+
dateMedium: "D. M. YYYY",
|
|
19
|
+
dateLong: "D. MMMM YYYY",
|
|
20
|
+
dateTimeShort: "D. M. YY, H:mm",
|
|
21
|
+
dateTimeMedium: "D. M. YYYY, H:mm",
|
|
22
|
+
dateTimeLong: "D. MMMM YYYY, H:mm:ss",
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
exports.default = locale;
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uxf/localize",
|
|
3
|
+
"version": "10.0.0-beta.21",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc -P tsconfig.json",
|
|
8
|
+
"typecheck": "tsc --noEmit --skipLibCheck"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git"
|
|
15
|
+
},
|
|
16
|
+
"author": "",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"currency.js": "^2.0.4",
|
|
20
|
+
"dayjs": "^1.11.9"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CreateLocalizeProps, DateTimes } from "../types";
|
|
3
|
+
export declare const _useLocalizeContext: () => string;
|
|
4
|
+
export declare const _LocalizeProvider: import("react").Provider<string>;
|
|
5
|
+
export declare const getLocaleConfigHook: <DT extends string = DateTimes>(allConfigurations: CreateLocalizeProps<DT>) => () => import("../types").LocalizeConfig<DT>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLocaleConfigHook = exports._LocalizeProvider = exports._useLocalizeContext = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const localizeContext = (0, react_1.createContext)("");
|
|
6
|
+
const _useLocalizeContext = () => (0, react_1.useContext)(localizeContext);
|
|
7
|
+
exports._useLocalizeContext = _useLocalizeContext;
|
|
8
|
+
exports._LocalizeProvider = localizeContext.Provider;
|
|
9
|
+
const getLocaleConfigHook = (allConfigurations) => () => {
|
|
10
|
+
const locale = (0, react_1.useContext)(localizeContext);
|
|
11
|
+
return allConfigurations[locale];
|
|
12
|
+
};
|
|
13
|
+
exports.getLocaleConfigHook = getLocaleConfigHook;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DateTimes, FormatDatetimeFunction, LocalizeConfig } from "../types";
|
|
2
|
+
export declare const _formatDatetime: <DT extends string = DateTimes, Locales extends string = string>(localizeConfigs: Record<Locales, LocalizeConfig<DT>>) => FormatDatetimeFunction<DT, Locales>;
|
|
3
|
+
export declare const _useFormatDatetime: <DT extends string = DateTimes>(localizeConfigs: Record<string, LocalizeConfig<DT>>) => () => (value: Date, format: DT) => string;
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
exports._useFormatDatetime = exports._formatDatetime = void 0;
|
|
7
|
+
const context_1 = require("../context/context");
|
|
8
|
+
const curry_1 = require("../utils/curry");
|
|
9
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
10
|
+
const _formatDatetime = (localizeConfigs) => (locale, value, format) => {
|
|
11
|
+
const localeDateTimes = localizeConfigs[locale].dateTime;
|
|
12
|
+
return (0, dayjs_1.default)(value).format(localeDateTimes[format]);
|
|
13
|
+
};
|
|
14
|
+
exports._formatDatetime = _formatDatetime;
|
|
15
|
+
const _useFormatDatetime = (localizeConfigs) => () => {
|
|
16
|
+
const locale = (0, context_1._useLocalizeContext)();
|
|
17
|
+
return (0, curry_1._curry)((0, exports._formatDatetime)(localizeConfigs))(locale);
|
|
18
|
+
};
|
|
19
|
+
exports._useFormatDatetime = _useFormatDatetime;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
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 format_datetime_1 = require("./format-datetime");
|
|
7
|
+
const cs_1 = __importDefault(require("../../locale/cs"));
|
|
8
|
+
const en_1 = __importDefault(require("../../locale/en"));
|
|
9
|
+
const date = new Date("2023-07-21T07:58:35");
|
|
10
|
+
describe("datetime formatter", function () {
|
|
11
|
+
const formatDatetimeWithLocales = (0, format_datetime_1._formatDatetime)({ cs: cs_1.default, en: en_1.default });
|
|
12
|
+
it("format datetime with 'en' locale", function () {
|
|
13
|
+
expect(formatDatetimeWithLocales("cs", date, "dateShort")).toBe("21. 7. 23");
|
|
14
|
+
expect(formatDatetimeWithLocales("cs", date, "dateMedium")).toBe("21. 7. 2023");
|
|
15
|
+
expect(formatDatetimeWithLocales("cs", date, "dateTimeShort")).toBe("21. 7. 23, 7:58");
|
|
16
|
+
expect(formatDatetimeWithLocales("cs", date, "dateTimeMedium")).toBe("21. 7. 2023, 7:58");
|
|
17
|
+
expect(formatDatetimeWithLocales("cs", date, "dateTimeLong")).toBe("21. July 2023, 7:58:35");
|
|
18
|
+
expect(formatDatetimeWithLocales("cs", date, "timeShort")).toBe("7:58");
|
|
19
|
+
expect(formatDatetimeWithLocales("cs", date, "timeFull")).toBe("7:58:35");
|
|
20
|
+
});
|
|
21
|
+
it("format datetime with 'en' locale", function () {
|
|
22
|
+
expect(formatDatetimeWithLocales("en", date, "dateShort")).toBe("7/21/23");
|
|
23
|
+
expect(formatDatetimeWithLocales("en", date, "dateMedium")).toBe("7/21/2023");
|
|
24
|
+
expect(formatDatetimeWithLocales("en", date, "dateTimeShort")).toBe("7/21/23 7:58 AM");
|
|
25
|
+
expect(formatDatetimeWithLocales("en", date, "dateTimeMedium")).toBe("7/21/2023 7:58 AM");
|
|
26
|
+
expect(formatDatetimeWithLocales("en", date, "dateTimeLong")).toBe("July 21. 2023 7:58:35 AM");
|
|
27
|
+
expect(formatDatetimeWithLocales("en", date, "timeShort")).toBe("7:58 AM");
|
|
28
|
+
expect(formatDatetimeWithLocales("en", date, "timeFull")).toBe("7:58:35 AM");
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DateTimes, FormatMoneyFunction, LocalizeConfig } from "../types";
|
|
2
|
+
export declare const _formatMoney: <DT extends string = DateTimes, Locales extends string = string>(localizeConfigs: Record<Locales, LocalizeConfig<DT>>) => FormatMoneyFunction<Locales>;
|
|
3
|
+
export declare const _useFormatMoney: <DT extends string = DateTimes>(localizeConfigs: Record<string, LocalizeConfig<DT>>) => () => (value: number, currency: "CHF" | "AED" | "AFN" | "AMD" | "ANG" | "ARS" | "AUD" | "AWG" | "AZN" | "BDT" | "BGN" | "BHD" | "BIF" | "BRL" | "BTN" | "BYN" | "CAD" | "CLP" | "CNY" | "COP" | "CRC" | "CUP" | "CVE" | "CZK" | "DJF" | "DKK" | "EGP" | "ERN" | "EUR" | "FJD" | "GBP" | "GEL" | "GMD" | "GNF" | "HKD" | "HRK" | "HTG" | "HUF" | "IDR" | "INR" | "IQD" | "ISK" | "JPY" | "KGS" | "KHR" | "KMF" | "KRW" | "KWD" | "KZT" | "LKR" | "LRD" | "LSL" | "MDL" | "MMK" | "MNT" | "MRO" | "MWK" | "MXN" | "MYR" | "MZN" | "NGN" | "NOK" | "NPR" | "NZD" | "PEN" | "PGK" | "PHP" | "PKR" | "PLN" | "PYG" | "RON" | "RSD" | "RUB" | "SBD" | "SDG" | "SEK" | "SGD" | "SLL" | "SRD" | "SYP" | "SZL" | "THB" | "TJS" | "TMT" | "TRY" | "TZS" | "UGX" | "USD" | "UYU" | "UZS" | "VES" | "VND" | "VUV" | "WST" | "XOF" | "XPF" | "YER" | "ZAR" | "ZMW", options?: import("../types").FormatMoneyOptions | undefined) => string;
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
exports._useFormatMoney = exports._formatMoney = void 0;
|
|
7
|
+
const context_1 = require("../context/context");
|
|
8
|
+
const curry_1 = require("../utils/curry");
|
|
9
|
+
const currency_js_1 = __importDefault(require("currency.js"));
|
|
10
|
+
const map_options_1 = require("../utils/map-options");
|
|
11
|
+
const data_1 = require("../utils/data");
|
|
12
|
+
const _formatMoney = (localizeConfigs) => (locale, value, currency, options) => {
|
|
13
|
+
var _a, _b, _c;
|
|
14
|
+
const precision = (_a = options === null || options === void 0 ? void 0 : options.precision) !== null && _a !== void 0 ? _a : 0;
|
|
15
|
+
const symbol = (options === null || options === void 0 ? void 0 : options.preferIsoCode) ? currency : data_1.CURRENCIES[currency].symbol;
|
|
16
|
+
const formatOptions = { ...(0, map_options_1._mapOptions)(localizeConfigs[locale].currency), precision, symbol };
|
|
17
|
+
if (options === null || options === void 0 ? void 0 : options.hideSymbol) {
|
|
18
|
+
formatOptions.pattern = (_b = formatOptions.pattern) === null || _b === void 0 ? void 0 : _b.replace("!", "").trim();
|
|
19
|
+
formatOptions.negativePattern = (_c = formatOptions.negativePattern) === null || _c === void 0 ? void 0 : _c.replace("!", "").trim();
|
|
20
|
+
}
|
|
21
|
+
return (0, currency_js_1.default)(value, { precision }).format(formatOptions);
|
|
22
|
+
};
|
|
23
|
+
exports._formatMoney = _formatMoney;
|
|
24
|
+
const _useFormatMoney = (localizeConfigs) => () => {
|
|
25
|
+
const locale = (0, context_1._useLocalizeContext)();
|
|
26
|
+
return (0, curry_1._curry)((0, exports._formatMoney)(localizeConfigs))(locale);
|
|
27
|
+
};
|
|
28
|
+
exports._useFormatMoney = _useFormatMoney;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
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 format_money_1 = require("./format-money");
|
|
7
|
+
const cs_1 = __importDefault(require("../../locale/cs"));
|
|
8
|
+
const en_1 = __importDefault(require("../../locale/en"));
|
|
9
|
+
describe("money formatter", function () {
|
|
10
|
+
const formatMoneyWithLocales = (0, format_money_1._formatMoney)({ cs: cs_1.default, en: en_1.default });
|
|
11
|
+
it("format money with 'cs' locale", function () {
|
|
12
|
+
expect(formatMoneyWithLocales("cs", 2000.78, "CZK")).toBe("2\xa0001\xa0Kč");
|
|
13
|
+
expect(formatMoneyWithLocales("cs", 2000.78, "CZK", { precision: 1 })).toBe("2\xa0000,8\xa0Kč");
|
|
14
|
+
expect(formatMoneyWithLocales("cs", 2000.78, "CZK", { precision: 1, preferIsoCode: true })).toBe("2\xa0000,8\xa0CZK");
|
|
15
|
+
expect(formatMoneyWithLocales("cs", 2000.78, "CZK", { precision: 1, hideSymbol: true })).toBe("2\xa0000,8");
|
|
16
|
+
expect(formatMoneyWithLocales("cs", 2000.78, "USD")).toBe("2\xa0001\xa0$");
|
|
17
|
+
expect(formatMoneyWithLocales("cs", 2000.78, "USD", { precision: 1 })).toBe("2\xa0000,8\xa0$");
|
|
18
|
+
expect(formatMoneyWithLocales("cs", 2000.78, "USD", { precision: 1, preferIsoCode: true })).toBe("2\xa0000,8\xa0USD");
|
|
19
|
+
expect(formatMoneyWithLocales("cs", 2000.78, "USD", { precision: 1, hideSymbol: true })).toBe("2\xa0000,8");
|
|
20
|
+
});
|
|
21
|
+
it("format money with 'en' locale", function () {
|
|
22
|
+
expect(formatMoneyWithLocales("en", 2000.78, "CZK")).toBe("Kč2,001");
|
|
23
|
+
expect(formatMoneyWithLocales("en", 2000.78, "CZK", { precision: 1 })).toBe("Kč2,000.8");
|
|
24
|
+
expect(formatMoneyWithLocales("en", 2000.78, "CZK", { precision: 1, preferIsoCode: true })).toBe("CZK2,000.8");
|
|
25
|
+
expect(formatMoneyWithLocales("en", 2000.78, "CZK", { precision: 1, hideSymbol: true })).toBe("2,000.8");
|
|
26
|
+
expect(formatMoneyWithLocales("en", 2000.78, "USD")).toBe("$2,001");
|
|
27
|
+
expect(formatMoneyWithLocales("en", 2000.78, "USD", { precision: 1 })).toBe("$2,000.8");
|
|
28
|
+
expect(formatMoneyWithLocales("en", 2000.78, "USD", { precision: 1, preferIsoCode: true })).toBe("USD2,000.8");
|
|
29
|
+
expect(formatMoneyWithLocales("en", 2000.78, "USD", { precision: 1, hideSymbol: true })).toBe("2,000.8");
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DateTimes, FormatNumberFunction, LocalizeConfig } from "../types";
|
|
2
|
+
export declare const _formatNumber: <DT extends string = DateTimes, Locales extends string = string>(localizeConfigs: Record<Locales, LocalizeConfig<DT>>) => FormatNumberFunction<Locales>;
|
|
3
|
+
export declare const _useFormatNumber: <DT extends string = DateTimes>(localizeConfigs: Record<string, LocalizeConfig<DT>>) => () => (value: number, options?: import("../types").FormatNumberOptions | undefined) => string;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
exports._useFormatNumber = exports._formatNumber = void 0;
|
|
7
|
+
const currency_js_1 = __importDefault(require("currency.js"));
|
|
8
|
+
const context_1 = require("../context/context");
|
|
9
|
+
const curry_1 = require("../utils/curry");
|
|
10
|
+
const map_options_1 = require("../utils/map-options");
|
|
11
|
+
const _formatNumber = (localizeConfigs) => (locale, value, options) => {
|
|
12
|
+
var _a;
|
|
13
|
+
const precision = (_a = options === null || options === void 0 ? void 0 : options.precision) !== null && _a !== void 0 ? _a : 0;
|
|
14
|
+
const formatOptions = { ...(0, map_options_1._mapOptions)(localizeConfigs[locale].number), precision };
|
|
15
|
+
return (0, currency_js_1.default)(value, { precision }).format(formatOptions);
|
|
16
|
+
};
|
|
17
|
+
exports._formatNumber = _formatNumber;
|
|
18
|
+
const _useFormatNumber = (localizeConfigs) => () => {
|
|
19
|
+
const locale = (0, context_1._useLocalizeContext)();
|
|
20
|
+
return (0, curry_1._curry)((0, exports._formatNumber)(localizeConfigs))(locale);
|
|
21
|
+
};
|
|
22
|
+
exports._useFormatNumber = _useFormatNumber;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
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 format_number_1 = require("./format-number");
|
|
7
|
+
const cs_1 = __importDefault(require("../../locale/cs"));
|
|
8
|
+
const en_1 = __importDefault(require("../../locale/en"));
|
|
9
|
+
describe("number formatter", function () {
|
|
10
|
+
const formatNumberWithLocales = (0, format_number_1._formatNumber)({ cs: cs_1.default, en: en_1.default });
|
|
11
|
+
it("format number with 'cs' locale", function () {
|
|
12
|
+
expect(formatNumberWithLocales("cs", 2000.78)).toBe("2\xa0001");
|
|
13
|
+
expect(formatNumberWithLocales("cs", 2000.78, { precision: 2 })).toBe("2\xa0000,78");
|
|
14
|
+
});
|
|
15
|
+
it("format number with 'en' locale", function () {
|
|
16
|
+
expect(formatNumberWithLocales("en", 2000.78)).toBe("2,001");
|
|
17
|
+
expect(formatNumberWithLocales("en", 2000.78, { precision: 2 })).toBe("2,000.78");
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DateTimes, FormatPercentageFunction, LocalizeConfig, RoundingType } from "../types";
|
|
2
|
+
export declare const _formatPercentage: <DT extends string = DateTimes, Locales extends string = string>(localizeConfigs: Record<Locales, LocalizeConfig<DT>>) => FormatPercentageFunction<Locales>;
|
|
3
|
+
export declare const _useFormatPercentage: <DT extends string = DateTimes>(localizeConfigs: Record<string, LocalizeConfig<DT>>) => () => (value: number, roundingType?: RoundingType | null | undefined, options?: import("../types").FormatPercentageOptions | undefined) => string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._useFormatPercentage = exports._formatPercentage = void 0;
|
|
4
|
+
const format_number_1 = require("../format-number/format-number");
|
|
5
|
+
const context_1 = require("../context/context");
|
|
6
|
+
const curry_1 = require("../utils/curry");
|
|
7
|
+
const ROUND_FUNCTION_MAP = {
|
|
8
|
+
nearest: Math.round,
|
|
9
|
+
up: Math.ceil,
|
|
10
|
+
down: Math.floor,
|
|
11
|
+
};
|
|
12
|
+
const PERCENTAGE_MULTIPLIER = 100;
|
|
13
|
+
const _formatPercentage = (localizeConfigs) => (locale, value, roundingType = null, options) => {
|
|
14
|
+
const percentage = value * PERCENTAGE_MULTIPLIER;
|
|
15
|
+
const percentageValue = roundingType ? ROUND_FUNCTION_MAP[roundingType](percentage) : percentage;
|
|
16
|
+
return `${(0, format_number_1._formatNumber)(localizeConfigs)(locale, percentageValue, options)}\xa0%`;
|
|
17
|
+
};
|
|
18
|
+
exports._formatPercentage = _formatPercentage;
|
|
19
|
+
const _useFormatPercentage = (localizeConfigs) => () => {
|
|
20
|
+
const locale = (0, context_1._useLocalizeContext)();
|
|
21
|
+
return (0, curry_1._curry)((0, exports._formatPercentage)(localizeConfigs))(locale);
|
|
22
|
+
};
|
|
23
|
+
exports._useFormatPercentage = _useFormatPercentage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
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 format_percentage_1 = require("./format-percentage");
|
|
7
|
+
const cs_1 = __importDefault(require("../../locale/cs"));
|
|
8
|
+
const en_1 = __importDefault(require("../../locale/en"));
|
|
9
|
+
describe("percentage formatter", function () {
|
|
10
|
+
const formatPercentageWithLocales = (0, format_percentage_1._formatPercentage)({ cs: cs_1.default, en: en_1.default });
|
|
11
|
+
it("format percentage with 'cs' locale", function () {
|
|
12
|
+
expect(formatPercentageWithLocales("cs", 0.782)).toBe("78\xa0%");
|
|
13
|
+
expect(formatPercentageWithLocales("cs", 0.782, null, { precision: 2 })).toBe("78,20\xa0%");
|
|
14
|
+
expect(formatPercentageWithLocales("cs", 0.782, "nearest")).toBe("78\xa0%");
|
|
15
|
+
expect(formatPercentageWithLocales("cs", 0.782, "up")).toBe("79\xa0%");
|
|
16
|
+
expect(formatPercentageWithLocales("cs", 0.788, "down")).toBe("78\xa0%");
|
|
17
|
+
});
|
|
18
|
+
it("format percentage with 'en' locale", function () {
|
|
19
|
+
expect(formatPercentageWithLocales("en", 0.782)).toBe("78\xa0%");
|
|
20
|
+
expect(formatPercentageWithLocales("en", 0.782, null, { precision: 2 })).toBe("78.20\xa0%");
|
|
21
|
+
expect(formatPercentageWithLocales("en", 0.782, "nearest")).toBe("78\xa0%");
|
|
22
|
+
expect(formatPercentageWithLocales("en", 0.782, "up")).toBe("79\xa0%");
|
|
23
|
+
expect(formatPercentageWithLocales("en", 0.788, "down")).toBe("78\xa0%");
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCurrencySymbol = void 0;
|
|
4
|
+
const data_1 = require("../utils/data");
|
|
5
|
+
const getCurrencySymbol = (currency) => data_1.CURRENCIES[currency].symbol;
|
|
6
|
+
exports.getCurrencySymbol = getCurrencySymbol;
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CreateLocalizeProps, CreateLocalizeReturn, DateTimes } from "./types";
|
|
2
|
+
export * from "./get-currency-symbol/get-currency-symbol";
|
|
3
|
+
export declare function createLocalize<DT extends string = DateTimes, Locales extends string = string>(props: CreateLocalizeProps<DT, Locales>): CreateLocalizeReturn<DT, Locales>;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createLocalize = void 0;
|
|
18
|
+
const context_1 = require("./context/context");
|
|
19
|
+
const format_number_1 = require("./format-number/format-number");
|
|
20
|
+
const format_percentage_1 = require("./format-percentage/format-percentage");
|
|
21
|
+
const format_datetime_1 = require("./format-datetime/format-datetime");
|
|
22
|
+
const format_money_1 = require("./format-money/format-money");
|
|
23
|
+
__exportStar(require("./get-currency-symbol/get-currency-symbol"), exports);
|
|
24
|
+
function createLocalize(props) {
|
|
25
|
+
return {
|
|
26
|
+
LocalizeProvider: context_1._LocalizeProvider,
|
|
27
|
+
formatDateTime: (0, format_datetime_1._formatDatetime)(props),
|
|
28
|
+
formatNumber: (0, format_number_1._formatNumber)(props),
|
|
29
|
+
formatPercentage: (0, format_percentage_1._formatPercentage)(props),
|
|
30
|
+
formatMoney: (0, format_money_1._formatMoney)(props),
|
|
31
|
+
useFormatDateTime: (0, format_datetime_1._useFormatDatetime)(props),
|
|
32
|
+
useFormatNumber: (0, format_number_1._useFormatNumber)(props),
|
|
33
|
+
useFormatPercentage: (0, format_percentage_1._useFormatPercentage)(props),
|
|
34
|
+
useFormatMoney: (0, format_money_1._useFormatMoney)(props),
|
|
35
|
+
useLocaleConfig: (0, context_1.getLocaleConfigHook)(props),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.createLocalize = createLocalize;
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { CURRENCIES } from "./utils/data";
|
|
2
|
+
import { Provider } from "react";
|
|
3
|
+
export type DateTimes = "timeShort" | "timeFull" | "dateShort" | "dateMedium" | "dateLong" | "dateTimeShort" | "dateTimeMedium" | "dateTimeLong";
|
|
4
|
+
export type LocalizeConfig<DT extends string = DateTimes> = {
|
|
5
|
+
number: {
|
|
6
|
+
thousandsSeparator: string;
|
|
7
|
+
decimalSeparator: string;
|
|
8
|
+
};
|
|
9
|
+
currency: {
|
|
10
|
+
thousandsSeparator: string;
|
|
11
|
+
decimalSeparator: string;
|
|
12
|
+
pattern: string;
|
|
13
|
+
negativePattern: string;
|
|
14
|
+
};
|
|
15
|
+
dateTime: Record<DT, string>;
|
|
16
|
+
};
|
|
17
|
+
export type LocalizeProviderType = Provider<string>;
|
|
18
|
+
export type UseLocaleConfigType<DT extends string = DateTimes> = () => LocalizeConfig<DT>;
|
|
19
|
+
export type FormatNumberFunction<Locales extends string> = (locale: Locales, value: number, options?: FormatNumberOptions) => string;
|
|
20
|
+
export type UseFormatNumberFunction = () => (value: number, options?: FormatNumberOptions) => string;
|
|
21
|
+
export type FormatMoneyFunction<Locales extends string> = (locale: Locales, value: number, currency: Currency, options?: FormatMoneyOptions) => string;
|
|
22
|
+
export type UseFormatMoneyFunction = () => (value: number, currency: Currency, options?: FormatMoneyOptions) => string;
|
|
23
|
+
export type FormatPercentageFunction<Locales extends string> = (locale: Locales, value: number, roundingType?: RoundingType | null, options?: FormatPercentageOptions) => string;
|
|
24
|
+
export type UseFormatPercentageFunction = () => (value: number, roundingType?: RoundingType | null, options?: FormatPercentageOptions) => string;
|
|
25
|
+
export type FormatDatetimeFunction<DT extends string = DateTimes, Locales extends string = string> = (locale: Locales, value: Date, format: DT) => string;
|
|
26
|
+
export type UseFormatDatetimeFunction<DT extends string = DateTimes> = () => (value: Date, format: DT) => string;
|
|
27
|
+
export type CreateLocalizeProps<DT extends string = DateTimes, Locales extends string = string> = Record<Locales, LocalizeConfig<DT>>;
|
|
28
|
+
export type CreateLocalizeReturn<DT extends string = DateTimes, Locales extends string = string> = {
|
|
29
|
+
LocalizeProvider: LocalizeProviderType;
|
|
30
|
+
useLocaleConfig: UseLocaleConfigType<DT>;
|
|
31
|
+
formatNumber: FormatNumberFunction<Locales>;
|
|
32
|
+
useFormatNumber: UseFormatNumberFunction;
|
|
33
|
+
formatMoney: FormatMoneyFunction<Locales>;
|
|
34
|
+
useFormatMoney: UseFormatMoneyFunction;
|
|
35
|
+
formatPercentage: FormatPercentageFunction<Locales>;
|
|
36
|
+
useFormatPercentage: UseFormatPercentageFunction;
|
|
37
|
+
formatDateTime: FormatDatetimeFunction<DT, Locales>;
|
|
38
|
+
useFormatDateTime: UseFormatDatetimeFunction<DT>;
|
|
39
|
+
};
|
|
40
|
+
export type Currency = keyof typeof CURRENCIES;
|
|
41
|
+
export type FormatMoneyOptions = {
|
|
42
|
+
hideSymbol?: boolean;
|
|
43
|
+
precision?: number;
|
|
44
|
+
preferIsoCode?: boolean;
|
|
45
|
+
};
|
|
46
|
+
export type FormatNumberOptions = {
|
|
47
|
+
precision?: number;
|
|
48
|
+
};
|
|
49
|
+
export type RoundingType = "nearest" | "up" | "down";
|
|
50
|
+
export type FormatPercentageOptions = {
|
|
51
|
+
precision?: number;
|
|
52
|
+
};
|
package/src/types.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._curry = void 0;
|
|
4
|
+
function _curry(fn) {
|
|
5
|
+
return (arg1) => {
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
return (...rest) => fn(arg1, ...rest);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
exports._curry = _curry;
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
export declare const CURRENCIES: {
|
|
2
|
+
AED: {
|
|
3
|
+
symbol: string;
|
|
4
|
+
};
|
|
5
|
+
AFN: {
|
|
6
|
+
symbol: string;
|
|
7
|
+
};
|
|
8
|
+
AMD: {
|
|
9
|
+
symbol: string;
|
|
10
|
+
};
|
|
11
|
+
ANG: {
|
|
12
|
+
symbol: string;
|
|
13
|
+
};
|
|
14
|
+
ARS: {
|
|
15
|
+
symbol: string;
|
|
16
|
+
};
|
|
17
|
+
AUD: {
|
|
18
|
+
symbol: string;
|
|
19
|
+
};
|
|
20
|
+
AWG: {
|
|
21
|
+
symbol: string;
|
|
22
|
+
};
|
|
23
|
+
AZN: {
|
|
24
|
+
symbol: string;
|
|
25
|
+
};
|
|
26
|
+
BDT: {
|
|
27
|
+
symbol: string;
|
|
28
|
+
};
|
|
29
|
+
BGN: {
|
|
30
|
+
symbol: string;
|
|
31
|
+
};
|
|
32
|
+
BHD: {
|
|
33
|
+
symbol: string;
|
|
34
|
+
};
|
|
35
|
+
BIF: {
|
|
36
|
+
symbol: string;
|
|
37
|
+
};
|
|
38
|
+
BRL: {
|
|
39
|
+
symbol: string;
|
|
40
|
+
};
|
|
41
|
+
BTN: {
|
|
42
|
+
symbol: string;
|
|
43
|
+
};
|
|
44
|
+
BYN: {
|
|
45
|
+
symbol: string;
|
|
46
|
+
};
|
|
47
|
+
CAD: {
|
|
48
|
+
symbol: string;
|
|
49
|
+
};
|
|
50
|
+
CHF: {
|
|
51
|
+
symbol: string;
|
|
52
|
+
};
|
|
53
|
+
CLP: {
|
|
54
|
+
symbol: string;
|
|
55
|
+
};
|
|
56
|
+
CNY: {
|
|
57
|
+
symbol: string;
|
|
58
|
+
};
|
|
59
|
+
COP: {
|
|
60
|
+
symbol: string;
|
|
61
|
+
};
|
|
62
|
+
CRC: {
|
|
63
|
+
symbol: string;
|
|
64
|
+
};
|
|
65
|
+
CUP: {
|
|
66
|
+
symbol: string;
|
|
67
|
+
};
|
|
68
|
+
CVE: {
|
|
69
|
+
symbol: string;
|
|
70
|
+
};
|
|
71
|
+
CZK: {
|
|
72
|
+
symbol: string;
|
|
73
|
+
};
|
|
74
|
+
DJF: {
|
|
75
|
+
symbol: string;
|
|
76
|
+
};
|
|
77
|
+
DKK: {
|
|
78
|
+
symbol: string;
|
|
79
|
+
};
|
|
80
|
+
EGP: {
|
|
81
|
+
symbol: string;
|
|
82
|
+
};
|
|
83
|
+
ERN: {
|
|
84
|
+
symbol: string;
|
|
85
|
+
};
|
|
86
|
+
EUR: {
|
|
87
|
+
symbol: string;
|
|
88
|
+
};
|
|
89
|
+
FJD: {
|
|
90
|
+
symbol: string;
|
|
91
|
+
};
|
|
92
|
+
GBP: {
|
|
93
|
+
symbol: string;
|
|
94
|
+
};
|
|
95
|
+
GEL: {
|
|
96
|
+
symbol: string;
|
|
97
|
+
};
|
|
98
|
+
GMD: {
|
|
99
|
+
symbol: string;
|
|
100
|
+
};
|
|
101
|
+
GNF: {
|
|
102
|
+
symbol: string;
|
|
103
|
+
};
|
|
104
|
+
HKD: {
|
|
105
|
+
symbol: string;
|
|
106
|
+
};
|
|
107
|
+
HRK: {
|
|
108
|
+
symbol: string;
|
|
109
|
+
};
|
|
110
|
+
HTG: {
|
|
111
|
+
symbol: string;
|
|
112
|
+
};
|
|
113
|
+
HUF: {
|
|
114
|
+
symbol: string;
|
|
115
|
+
};
|
|
116
|
+
IDR: {
|
|
117
|
+
symbol: string;
|
|
118
|
+
};
|
|
119
|
+
INR: {
|
|
120
|
+
symbol: string;
|
|
121
|
+
};
|
|
122
|
+
IQD: {
|
|
123
|
+
symbol: string;
|
|
124
|
+
};
|
|
125
|
+
ISK: {
|
|
126
|
+
symbol: string;
|
|
127
|
+
};
|
|
128
|
+
JPY: {
|
|
129
|
+
symbol: string;
|
|
130
|
+
};
|
|
131
|
+
KGS: {
|
|
132
|
+
symbol: string;
|
|
133
|
+
};
|
|
134
|
+
KHR: {
|
|
135
|
+
symbol: string;
|
|
136
|
+
};
|
|
137
|
+
KMF: {
|
|
138
|
+
symbol: string;
|
|
139
|
+
};
|
|
140
|
+
KRW: {
|
|
141
|
+
symbol: string;
|
|
142
|
+
};
|
|
143
|
+
KWD: {
|
|
144
|
+
symbol: string;
|
|
145
|
+
};
|
|
146
|
+
KZT: {
|
|
147
|
+
symbol: string;
|
|
148
|
+
};
|
|
149
|
+
LKR: {
|
|
150
|
+
symbol: string;
|
|
151
|
+
};
|
|
152
|
+
LRD: {
|
|
153
|
+
symbol: string;
|
|
154
|
+
};
|
|
155
|
+
LSL: {
|
|
156
|
+
symbol: string;
|
|
157
|
+
};
|
|
158
|
+
MDL: {
|
|
159
|
+
symbol: string;
|
|
160
|
+
};
|
|
161
|
+
MMK: {
|
|
162
|
+
symbol: string;
|
|
163
|
+
};
|
|
164
|
+
MNT: {
|
|
165
|
+
symbol: string;
|
|
166
|
+
};
|
|
167
|
+
MRO: {
|
|
168
|
+
symbol: string;
|
|
169
|
+
};
|
|
170
|
+
MWK: {
|
|
171
|
+
symbol: string;
|
|
172
|
+
};
|
|
173
|
+
MXN: {
|
|
174
|
+
symbol: string;
|
|
175
|
+
};
|
|
176
|
+
MYR: {
|
|
177
|
+
symbol: string;
|
|
178
|
+
};
|
|
179
|
+
MZN: {
|
|
180
|
+
symbol: string;
|
|
181
|
+
};
|
|
182
|
+
NGN: {
|
|
183
|
+
symbol: string;
|
|
184
|
+
};
|
|
185
|
+
NOK: {
|
|
186
|
+
symbol: string;
|
|
187
|
+
};
|
|
188
|
+
NPR: {
|
|
189
|
+
symbol: string;
|
|
190
|
+
};
|
|
191
|
+
NZD: {
|
|
192
|
+
symbol: string;
|
|
193
|
+
};
|
|
194
|
+
PEN: {
|
|
195
|
+
symbol: string;
|
|
196
|
+
};
|
|
197
|
+
PGK: {
|
|
198
|
+
symbol: string;
|
|
199
|
+
};
|
|
200
|
+
PHP: {
|
|
201
|
+
symbol: string;
|
|
202
|
+
};
|
|
203
|
+
PKR: {
|
|
204
|
+
symbol: string;
|
|
205
|
+
};
|
|
206
|
+
PLN: {
|
|
207
|
+
symbol: string;
|
|
208
|
+
};
|
|
209
|
+
PYG: {
|
|
210
|
+
symbol: string;
|
|
211
|
+
};
|
|
212
|
+
RON: {
|
|
213
|
+
symbol: string;
|
|
214
|
+
};
|
|
215
|
+
RSD: {
|
|
216
|
+
symbol: string;
|
|
217
|
+
};
|
|
218
|
+
RUB: {
|
|
219
|
+
symbol: string;
|
|
220
|
+
};
|
|
221
|
+
SBD: {
|
|
222
|
+
symbol: string;
|
|
223
|
+
};
|
|
224
|
+
SDG: {
|
|
225
|
+
symbol: string;
|
|
226
|
+
};
|
|
227
|
+
SEK: {
|
|
228
|
+
symbol: string;
|
|
229
|
+
};
|
|
230
|
+
SGD: {
|
|
231
|
+
symbol: string;
|
|
232
|
+
};
|
|
233
|
+
SLL: {
|
|
234
|
+
symbol: string;
|
|
235
|
+
};
|
|
236
|
+
SRD: {
|
|
237
|
+
symbol: string;
|
|
238
|
+
};
|
|
239
|
+
SYP: {
|
|
240
|
+
symbol: string;
|
|
241
|
+
};
|
|
242
|
+
SZL: {
|
|
243
|
+
symbol: string;
|
|
244
|
+
};
|
|
245
|
+
THB: {
|
|
246
|
+
symbol: string;
|
|
247
|
+
};
|
|
248
|
+
TJS: {
|
|
249
|
+
symbol: string;
|
|
250
|
+
};
|
|
251
|
+
TMT: {
|
|
252
|
+
symbol: string;
|
|
253
|
+
};
|
|
254
|
+
TRY: {
|
|
255
|
+
symbol: string;
|
|
256
|
+
};
|
|
257
|
+
TZS: {
|
|
258
|
+
symbol: string;
|
|
259
|
+
};
|
|
260
|
+
UGX: {
|
|
261
|
+
symbol: string;
|
|
262
|
+
};
|
|
263
|
+
USD: {
|
|
264
|
+
symbol: string;
|
|
265
|
+
};
|
|
266
|
+
UYU: {
|
|
267
|
+
symbol: string;
|
|
268
|
+
};
|
|
269
|
+
UZS: {
|
|
270
|
+
symbol: string;
|
|
271
|
+
};
|
|
272
|
+
VES: {
|
|
273
|
+
symbol: string;
|
|
274
|
+
};
|
|
275
|
+
VND: {
|
|
276
|
+
symbol: string;
|
|
277
|
+
};
|
|
278
|
+
VUV: {
|
|
279
|
+
symbol: string;
|
|
280
|
+
};
|
|
281
|
+
WST: {
|
|
282
|
+
symbol: string;
|
|
283
|
+
};
|
|
284
|
+
XOF: {
|
|
285
|
+
symbol: string;
|
|
286
|
+
};
|
|
287
|
+
XPF: {
|
|
288
|
+
symbol: string;
|
|
289
|
+
};
|
|
290
|
+
YER: {
|
|
291
|
+
symbol: string;
|
|
292
|
+
};
|
|
293
|
+
ZAR: {
|
|
294
|
+
symbol: string;
|
|
295
|
+
};
|
|
296
|
+
ZMW: {
|
|
297
|
+
symbol: string;
|
|
298
|
+
};
|
|
299
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CURRENCIES = void 0;
|
|
4
|
+
exports.CURRENCIES = {
|
|
5
|
+
AED: { symbol: "د.إ" },
|
|
6
|
+
AFN: { symbol: "؋" },
|
|
7
|
+
AMD: { symbol: "֏" },
|
|
8
|
+
ANG: { symbol: "ƒ" },
|
|
9
|
+
ARS: { symbol: "$" },
|
|
10
|
+
AUD: { symbol: "$" },
|
|
11
|
+
AWG: { symbol: "ƒ" },
|
|
12
|
+
AZN: { symbol: "₼" },
|
|
13
|
+
BDT: { symbol: "৳" },
|
|
14
|
+
BGN: { symbol: "лв" },
|
|
15
|
+
BHD: { symbol: ".د.ب" },
|
|
16
|
+
BIF: { symbol: "FBu" },
|
|
17
|
+
BRL: { symbol: "R$" },
|
|
18
|
+
BTN: { symbol: "Nu." },
|
|
19
|
+
BYN: { symbol: "Br" },
|
|
20
|
+
CAD: { symbol: "$" },
|
|
21
|
+
CHF: { symbol: "CHF" },
|
|
22
|
+
CLP: { symbol: "$" },
|
|
23
|
+
CNY: { symbol: "¥" },
|
|
24
|
+
COP: { symbol: "$" },
|
|
25
|
+
CRC: { symbol: "₡" },
|
|
26
|
+
CUP: { symbol: "₱" },
|
|
27
|
+
CVE: { symbol: "$" },
|
|
28
|
+
CZK: { symbol: "Kč" },
|
|
29
|
+
DJF: { symbol: "Fdj" },
|
|
30
|
+
DKK: { symbol: "kr" },
|
|
31
|
+
EGP: { symbol: "£" },
|
|
32
|
+
ERN: { symbol: "Nfk" },
|
|
33
|
+
EUR: { symbol: "€" },
|
|
34
|
+
FJD: { symbol: "$" },
|
|
35
|
+
GBP: { symbol: "£" },
|
|
36
|
+
GEL: { symbol: "₾" },
|
|
37
|
+
GMD: { symbol: "D" },
|
|
38
|
+
GNF: { symbol: "FG" },
|
|
39
|
+
HKD: { symbol: "$" },
|
|
40
|
+
HRK: { symbol: "kn" },
|
|
41
|
+
HTG: { symbol: "G" },
|
|
42
|
+
HUF: { symbol: "Ft" },
|
|
43
|
+
IDR: { symbol: "Rp" },
|
|
44
|
+
INR: { symbol: "₹" },
|
|
45
|
+
IQD: { symbol: "ع.د" },
|
|
46
|
+
ISK: { symbol: "kr" },
|
|
47
|
+
JPY: { symbol: "¥" },
|
|
48
|
+
KGS: { symbol: "с" },
|
|
49
|
+
KHR: { symbol: "៛" },
|
|
50
|
+
KMF: { symbol: "CF" },
|
|
51
|
+
KRW: { symbol: "₩" },
|
|
52
|
+
KWD: { symbol: "د.ك" },
|
|
53
|
+
KZT: { symbol: "₸" },
|
|
54
|
+
LKR: { symbol: "₨" },
|
|
55
|
+
LRD: { symbol: "$" },
|
|
56
|
+
LSL: { symbol: "L" },
|
|
57
|
+
MDL: { symbol: "L" },
|
|
58
|
+
MMK: { symbol: "K" },
|
|
59
|
+
MNT: { symbol: "₮" },
|
|
60
|
+
MRO: { symbol: "UM" },
|
|
61
|
+
MWK: { symbol: "MK" },
|
|
62
|
+
MXN: { symbol: "$" },
|
|
63
|
+
MYR: { symbol: "RM" },
|
|
64
|
+
MZN: { symbol: "MT" },
|
|
65
|
+
NGN: { symbol: "₦" },
|
|
66
|
+
NOK: { symbol: "kr" },
|
|
67
|
+
NPR: { symbol: "₨" },
|
|
68
|
+
NZD: { symbol: "$" },
|
|
69
|
+
PEN: { symbol: "S/" },
|
|
70
|
+
PGK: { symbol: "K" },
|
|
71
|
+
PHP: { symbol: "₱" },
|
|
72
|
+
PKR: { symbol: "₨" },
|
|
73
|
+
PLN: { symbol: "zł" },
|
|
74
|
+
PYG: { symbol: "₲" },
|
|
75
|
+
RON: { symbol: "lei" },
|
|
76
|
+
RSD: { symbol: "дин." },
|
|
77
|
+
RUB: { symbol: "₽" },
|
|
78
|
+
SBD: { symbol: "$" },
|
|
79
|
+
SDG: { symbol: "ج.س." },
|
|
80
|
+
SEK: { symbol: "kr" },
|
|
81
|
+
SGD: { symbol: "$" },
|
|
82
|
+
SLL: { symbol: "Le" },
|
|
83
|
+
SRD: { symbol: "$" },
|
|
84
|
+
SYP: { symbol: "£" },
|
|
85
|
+
SZL: { symbol: "E" },
|
|
86
|
+
THB: { symbol: "฿" },
|
|
87
|
+
TJS: { symbol: "ЅМ" },
|
|
88
|
+
TMT: { symbol: "m" },
|
|
89
|
+
TRY: { symbol: "₺" },
|
|
90
|
+
TZS: { symbol: "Sh" },
|
|
91
|
+
UGX: { symbol: "USh" },
|
|
92
|
+
USD: { symbol: "$" },
|
|
93
|
+
UYU: { symbol: "$" },
|
|
94
|
+
UZS: { symbol: "soʻm" },
|
|
95
|
+
VES: { symbol: "Bs" },
|
|
96
|
+
VND: { symbol: "₫" },
|
|
97
|
+
VUV: { symbol: "VT" },
|
|
98
|
+
WST: { symbol: "T" },
|
|
99
|
+
XOF: { symbol: "CFA" },
|
|
100
|
+
XPF: { symbol: "₣" },
|
|
101
|
+
YER: { symbol: "﷼" },
|
|
102
|
+
ZAR: { symbol: "R" },
|
|
103
|
+
ZMW: { symbol: "ZK" },
|
|
104
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._mapOptions = void 0;
|
|
4
|
+
const _mapOptions = (options) => {
|
|
5
|
+
return {
|
|
6
|
+
separator: options.thousandsSeparator,
|
|
7
|
+
decimal: options.decimalSeparator,
|
|
8
|
+
pattern: "pattern" in options ? options.pattern : "#",
|
|
9
|
+
negativePattern: "negativePattern" in options ? options.negativePattern : "-#",
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
exports._mapOptions = _mapOptions;
|