@jetshop/intl 5.13.0 → 5.13.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.
File without changes
package/index.ts ADDED
@@ -0,0 +1,66 @@
1
+ import React, { useContext } from 'react';
2
+ import IntlContext from '@jetshop/intl/context';
3
+ import formatMessage from 'format-message/types';
4
+
5
+ export const useIntl = () => useContext(IntlContext);
6
+
7
+ type FormatMsgType = typeof formatMessage;
8
+ type FormatMsgTypes =
9
+ | FormatMsgType
10
+ | FormatMsgType['rich']
11
+ | FormatMsgType['number']
12
+ | FormatMsgType['date']
13
+ | FormatMsgType['time']
14
+ | FormatMsgType['select']
15
+ | FormatMsgType['plural']
16
+ | FormatMsgType['selectordinal']
17
+ | FormatMsgType['custom'];
18
+
19
+ type WithContextFormatMessage = ReturnType<typeof withContextFormatMessage>;
20
+
21
+ interface TranslateType extends WithContextFormatMessage {
22
+ rich: (
23
+ ...args: Parameters<FormatMsgType['rich']>
24
+ ) => ReturnType<WithContextFormatMessage>;
25
+ number: (
26
+ ...args: Parameters<FormatMsgType['number']>
27
+ ) => ReturnType<WithContextFormatMessage>;
28
+ date: (
29
+ ...args: Parameters<FormatMsgType['date']>
30
+ ) => ReturnType<WithContextFormatMessage>;
31
+ time: (
32
+ ...args: Parameters<FormatMsgType['time']>
33
+ ) => ReturnType<WithContextFormatMessage>;
34
+ select: (
35
+ ...args: Parameters<FormatMsgType['select']>
36
+ ) => ReturnType<WithContextFormatMessage>;
37
+ plural: (
38
+ ...args: Parameters<FormatMsgType['plural']>
39
+ ) => ReturnType<WithContextFormatMessage>;
40
+ selectordinal: (
41
+ ...args: Parameters<FormatMsgType['selectordinal']>
42
+ ) => ReturnType<WithContextFormatMessage>;
43
+ custom: (
44
+ ...args: Parameters<FormatMsgType['custom']>
45
+ ) => ReturnType<WithContextFormatMessage>;
46
+ }
47
+
48
+ const withContextFormatMessage =
49
+ (callback: (t: FormatMsgType) => ReturnType<FormatMsgTypes>) =>
50
+ (...args: Parameters<FormatMsgTypes>) =>
51
+ React.createElement(IntlContext.Consumer, null, (t: FormatMsgType) =>
52
+ callback(t)(...args)
53
+ );
54
+
55
+ const Translate = withContextFormatMessage((t) => t) as TranslateType;
56
+ Translate.rich = withContextFormatMessage((t) => t.rich);
57
+ Translate.number = withContextFormatMessage((t) => t.number);
58
+ Translate.date = withContextFormatMessage((t) => t.date);
59
+ Translate.time = withContextFormatMessage((t) => t.time);
60
+ Translate.select = withContextFormatMessage((t) => t.select);
61
+ Translate.plural = withContextFormatMessage((t) => t.plural);
62
+ Translate.selectordinal = withContextFormatMessage((t) => t.selectordinal);
63
+ Translate.custom = withContextFormatMessage((t) => t.custom);
64
+
65
+ export const Intl = IntlContext.Consumer;
66
+ export default Translate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetshop/intl",
3
- "version": "5.13.0",
3
+ "version": "5.13.1",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "bin": {
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": ".",
5
+ "declaration": true,
6
+ "allowJs": false
7
+ }
8
+ }
package/index.js DELETED
@@ -1,21 +0,0 @@
1
- import React, { useContext } from 'react';
2
- import IntlContext from '@jetshop/intl/context';
3
-
4
- export const useIntl = () => useContext(IntlContext);
5
-
6
- const withContextFormatMessage =
7
- (callback) =>
8
- (...args) =>
9
- React.createElement(IntlContext.Consumer, {}, (t) => callback(t)(...args));
10
-
11
- const Translate = withContextFormatMessage((t) => t);
12
- Translate.rich = withContextFormatMessage((t) => t.rich);
13
- Translate.number = withContextFormatMessage((t) => t.number);
14
- Translate.date = withContextFormatMessage((t) => t.date);
15
- Translate.time = withContextFormatMessage((t) => t.time);
16
- Translate.select = withContextFormatMessage((t) => t.select);
17
- Translate.plural = withContextFormatMessage((t) => t.plural);
18
- Translate.selectordinal = withContextFormatMessage((t) => t.selectordinal);
19
- Translate.custom = withContextFormatMessage((t) => t.custom);
20
- export const Intl = IntlContext.Consumer;
21
- export default Translate;