@andre1502/react-utilities 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. package/README.md +61 -12
  2. package/dist/Config/Config.js +4 -3
  3. package/dist/Config/Config.js.map +1 -1
  4. package/dist/EnvironmentEnum-BjXsfSRZ.js +9 -0
  5. package/dist/EnvironmentEnum-BjXsfSRZ.js.map +1 -0
  6. package/dist/EnvironmentEnum-UcQ6Il1O.js +9 -0
  7. package/dist/EnvironmentEnum-UcQ6Il1O.js.map +1 -0
  8. package/dist/I18n/I18n.d.ts +6 -0
  9. package/dist/I18n/I18n.js +104 -0
  10. package/dist/I18n/I18n.js.map +1 -0
  11. package/dist/I18n-CB7SyXYJ.js +3291 -0
  12. package/dist/I18n-CB7SyXYJ.js.map +1 -0
  13. package/dist/I18n-yXLN_hDO.js +3288 -0
  14. package/dist/I18n-yXLN_hDO.js.map +1 -0
  15. package/dist/config-cli.cjs +8 -3
  16. package/dist/config-cli.cjs.map +1 -1
  17. package/dist/config-cli.d.ts +2 -0
  18. package/dist/config-cli.js +8 -0
  19. package/dist/config-cli.js.map +1 -1
  20. package/dist/config-cli.mjs +5 -4
  21. package/dist/config-cli.mjs.map +1 -1
  22. package/dist/enums/EnvironmentEnum.d.ts +5 -0
  23. package/dist/enums/EnvironmentEnum.js +13 -0
  24. package/dist/enums/EnvironmentEnum.js.map +1 -0
  25. package/dist/i18n.cjs +15 -0
  26. package/dist/i18n.cjs.map +1 -0
  27. package/dist/i18n.d.ts +3 -0
  28. package/dist/i18n.js +28 -0
  29. package/dist/i18n.js.map +1 -0
  30. package/dist/i18n.mjs +4 -0
  31. package/dist/i18n.mjs.map +1 -0
  32. package/dist/index-cli.cjs +5 -0
  33. package/dist/index-cli.cjs.map +1 -1
  34. package/dist/index-cli.mjs +1 -0
  35. package/dist/index-cli.mjs.map +1 -1
  36. package/dist/index-rn.cjs +9 -0
  37. package/dist/index-rn.cjs.map +1 -1
  38. package/dist/index-rn.d.ts +1 -0
  39. package/dist/index-rn.js +11 -0
  40. package/dist/index-rn.js.map +1 -1
  41. package/dist/index-rn.mjs +3 -0
  42. package/dist/index-rn.mjs.map +1 -1
  43. package/dist/index.cjs +9 -0
  44. package/dist/index.cjs.map +1 -1
  45. package/dist/index.d.ts +1 -0
  46. package/dist/index.js +11 -0
  47. package/dist/index.js.map +1 -1
  48. package/dist/index.mjs +3 -0
  49. package/dist/index.mjs.map +1 -1
  50. package/package.json +11 -6
  51. package/src/Config/Config.ts +4 -3
  52. package/src/I18n/I18n.ts +117 -0
  53. package/src/config-cli.ts +2 -0
  54. package/src/enums/EnvironmentEnum.ts +5 -0
  55. package/src/i18n.ts +4 -0
  56. package/src/index-rn.ts +1 -0
  57. package/src/index.ts +1 -0
  58. package/dist/index-fmt.cjs +0 -16
  59. package/dist/index-fmt.cjs.map +0 -1
  60. package/dist/index-fmt.d.ts +0 -1
  61. package/dist/index-fmt.js +0 -17
  62. package/dist/index-fmt.js.map +0 -1
  63. package/dist/index-fmt.mjs +0 -3
  64. package/dist/index-fmt.mjs.map +0 -1
  65. package/src/index-fmt.ts +0 -1
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './format';
2
+ export * from './i18n';
2
3
  export * from './sentry';
package/dist/index.js CHANGED
@@ -14,6 +14,17 @@ Object.keys(_format).forEach(function (key) {
14
14
  }
15
15
  });
16
16
  });
17
+ var _i18n = require("./i18n");
18
+ Object.keys(_i18n).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _i18n[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function get() {
24
+ return _i18n[key];
25
+ }
26
+ });
27
+ });
17
28
  var _sentry = require("./sentry");
18
29
  Object.keys(_sentry).forEach(function (key) {
19
30
  if (key === "default" || key === "__esModule") return;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_format","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_sentry"],"sources":["../src/index.ts"],"sourcesContent":["export * from './format';\nexport * from './sentry';\n"],"mappings":";;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,OAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,OAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,OAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAC,OAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_format","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_i18n","_sentry"],"sources":["../src/index.ts"],"sourcesContent":["export * from './format';\nexport * from './i18n';\nexport * from './sentry';\n"],"mappings":";;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,KAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,KAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,KAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAC,KAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,OAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,OAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,OAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAE,OAAA,CAAAN,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
package/dist/index.mjs CHANGED
@@ -1,6 +1,9 @@
1
1
  export { CurrencySymbolEnum, formatAccountNumber, formatNumber, getCurrencySymbol, parseFormatNumber } from './format.mjs';
2
+ export { E as EnvironmentEnum } from './EnvironmentEnum-UcQ6Il1O.js';
3
+ export { g as getV, i as initI18n } from './I18n-yXLN_hDO.js';
2
4
  export { i as initSentry, r as recordAdditionalSentryHttp } from './React-BaJ1KfGF.js';
3
5
  import '@formatjs/intl-numberformat';
6
+ import 'cross-fetch';
4
7
  import '@sentry/react';
5
8
  import './Utils-Cq948gfa.js';
6
9
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andre1502/react-utilities",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "module to combine common functions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,11 +15,6 @@
15
15
  "require": "./dist/index.cjs",
16
16
  "import": "./dist/index.mjs"
17
17
  },
18
- "./fmt": {
19
- "types": "./dist/index-fmt.d.ts",
20
- "require": "./dist/index-fmt.cjs",
21
- "import": "./dist/index-fmt.mjs"
22
- },
23
18
  "./react-native": {
24
19
  "types": "./dist/index-rn.d.ts",
25
20
  "require": "./dist/index-rn.cjs",
@@ -35,6 +30,11 @@
35
30
  "require": "./dist/format.cjs",
36
31
  "import": "./dist/format.mjs"
37
32
  },
33
+ "./i18n": {
34
+ "types": "./dist/i18n.d.ts",
35
+ "require": "./dist/i18n.cjs",
36
+ "import": "./dist/i18n.mjs"
37
+ },
38
38
  "./sentry": {
39
39
  "types": "./dist/sentry.d.ts",
40
40
  "require": "./dist/sentry.cjs",
@@ -89,6 +89,11 @@
89
89
  "@types/lodash": "^4.17.7",
90
90
  "google-auth-library": "^9.11.0",
91
91
  "googleapis": "^140.0.1",
92
+ "i18next": "^23.16.5",
93
+ "i18next-chained-backend": "^4.6.2",
94
+ "i18next-http-backend": "^2.6.2",
95
+ "i18next-localstorage-backend": "^4.2.0",
96
+ "i18next-resources-to-backend": "^1.2.1",
92
97
  "lodash": "^4.17.21",
93
98
  "sitemap": "^8.0.0"
94
99
  },
@@ -1,4 +1,5 @@
1
1
  import * as lodash from 'lodash';
2
+ import { EnvironmentEnum } from '../enums/EnvironmentEnum';
2
3
  import { OutputMap } from '../interfaces/Config/OutputMap';
3
4
  import { OutputOptions } from '../interfaces/Config/OutputOptions';
4
5
  import { outputToFile } from './Output';
@@ -137,17 +138,17 @@ const envMap = (env: string): string => {
137
138
  case 'dev':
138
139
  case 'develop':
139
140
  case 'development':
140
- result = 'dev';
141
+ result = EnvironmentEnum.DEV;
141
142
  break;
142
143
  case 'stg':
143
144
  case 'stag':
144
145
  case 'staging':
145
- result = 'staging';
146
+ result = EnvironmentEnum.STAGING;
146
147
  break;
147
148
  case 'prd':
148
149
  case 'prod':
149
150
  case 'production':
150
- result = 'production';
151
+ result = EnvironmentEnum.PRODUCTION;
151
152
  break;
152
153
  default:
153
154
  throw new Error(`env ${env} not supported.`);
@@ -0,0 +1,117 @@
1
+ import i18next, { InitOptions, ThirdPartyModule } from 'i18next';
2
+ import ChainedBackend from 'i18next-chained-backend';
3
+ import HttpBackend from 'i18next-http-backend';
4
+ import LocalStorageBackend from 'i18next-localstorage-backend';
5
+ import ResourcesToBackend from 'i18next-resources-to-backend';
6
+
7
+ const getV = (divider: number): number => {
8
+ return Math.floor(Date.now() / divider);
9
+ };
10
+
11
+ const initI18n = (
12
+ initReactI18next: ThirdPartyModule,
13
+ lang: string,
14
+ fallbackLang: string,
15
+ langCacheExpiredTimeMs: number,
16
+ resources: { [key: string]: any },
17
+ version: string,
18
+ withLocalstorageBackend?: boolean,
19
+ cdnUrl?: string,
20
+ debug?: boolean,
21
+ ) => {
22
+ let backends: Array<any> = [];
23
+ let backendOptions: Array<any> = [];
24
+ const langs = Object.keys(resources);
25
+
26
+ // https://www.i18next.com/how-to/backend-fallback
27
+ if (withLocalstorageBackend) {
28
+ const versions: { [key: string]: string } = {};
29
+
30
+ langs.forEach((value) => Object.assign(versions, { [value]: version }));
31
+
32
+ backends.push(LocalStorageBackend);
33
+ backendOptions.push({
34
+ // prefix for stored languages
35
+ prefix: `i18next_res_`,
36
+
37
+ // expiration
38
+ expirationTime: langCacheExpiredTimeMs,
39
+
40
+ // language versions
41
+ versions: versions,
42
+ });
43
+ }
44
+
45
+ if (cdnUrl) {
46
+ backends.push(HttpBackend);
47
+ backendOptions.push({
48
+ // load resources from url path
49
+ loadPath: `${cdnUrl}/locales/{{lng}}.json`,
50
+ // adds parameters to resource URL. 'example.com' -> 'example.com?v=1.3.5'
51
+ queryStringParams: {
52
+ v: `${version}.${getV(langCacheExpiredTimeMs)}`,
53
+ },
54
+
55
+ reloadInterval: langCacheExpiredTimeMs, // can be used to reload resources in a specific interval (milliseconds) (useful in server environments)
56
+ });
57
+ }
58
+
59
+ backends.push(ResourcesToBackend(resources));
60
+
61
+ // https://www.i18next.com/misc/creating-own-plugins#languagedetector
62
+ const languageDetector: any = {
63
+ type: 'languageDetector',
64
+ name: 'customDetector',
65
+ async: false,
66
+ init: () => {
67
+ /* use services and options */
68
+ },
69
+ detect: (callback: any) => {
70
+ return lang;
71
+ },
72
+ };
73
+
74
+ const config: InitOptions = {
75
+ debug: debug ?? false,
76
+ compatibilityJSON: 'v4',
77
+ ns: ['translation'],
78
+ defaultNS: 'translation',
79
+ lng: lang,
80
+ fallbackLng: fallbackLang,
81
+ load: 'currentOnly',
82
+ keySeparator: false,
83
+ nonExplicitSupportedLngs: true,
84
+ backend: {
85
+ backends: backends,
86
+ backendOptions: backendOptions,
87
+ cacheHitMode: 'refreshAndUpdateStore',
88
+ reloadInterval: langCacheExpiredTimeMs,
89
+ refreshExpirationTime: langCacheExpiredTimeMs, // only after determined time it should trigger a refresh if necessary
90
+ },
91
+ react: {
92
+ bindI18nStore: 'added', // this way, when the HttpBackend delivers new translations (thanks to refreshAndUpdateStore), the UI gets updated
93
+ },
94
+ interpolation: {
95
+ escapeValue: false, // react already safes from xss
96
+ },
97
+ };
98
+
99
+ if (!i18next.isInitialized) {
100
+ i18next
101
+ .use(ChainedBackend)
102
+ .use(languageDetector)
103
+ .use(initReactI18next) // passes i18n down to react-i18next
104
+ .init(config, (ex, t) => {
105
+ if (ex) {
106
+ console.error(`Error when i18n init`, ex);
107
+ return;
108
+ }
109
+
110
+ setInterval(() => {
111
+ i18next.reloadResources();
112
+ }, langCacheExpiredTimeMs);
113
+ });
114
+ }
115
+ };
116
+
117
+ export { getV, initI18n };
package/src/config-cli.ts CHANGED
@@ -3,6 +3,7 @@ import { JSONClient } from 'google-auth-library/build/src/auth/googleauth';
3
3
  import { exportConfig, processConfig } from './Config/Config';
4
4
  import { authorizeServiceAccount, fetchGoogleSheet } from './Config/GoogleAuth';
5
5
  import { exportLocales, processLocales } from './Config/Locales';
6
+ import { EnvironmentEnum } from './enums/EnvironmentEnum';
6
7
  import { ConfigOptions } from './interfaces/Config/ConfigOptions';
7
8
 
8
9
  export { transformConfig } from './Config/Config';
@@ -10,6 +11,7 @@ export { transformSitemap } from './Config/Sitemap';
10
11
  export * from './interfaces/Config/ConfigOptions';
11
12
  export * from './interfaces/Config/OutputOptions';
12
13
  export type { ExportAs, FormatAs } from './types/Config/OptionType';
14
+ export { EnvironmentEnum };
13
15
 
14
16
  /**
15
17
  * Private function to fetch locales
@@ -0,0 +1,5 @@
1
+ export enum EnvironmentEnum {
2
+ DEV = 'dev',
3
+ STAGING = 'staging',
4
+ PRODUCTION = 'production',
5
+ }
package/src/i18n.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { EnvironmentEnum } from './enums/EnvironmentEnum';
2
+
3
+ export * from './I18n/I18n';
4
+ export { EnvironmentEnum };
package/src/index-rn.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './format';
2
+ export * from './i18n';
2
3
  export * from './sentry-rn';
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './format';
2
+ export * from './i18n';
2
3
  export * from './sentry';
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- var format = require('./format.cjs');
4
- require('@formatjs/intl-numberformat');
5
-
6
-
7
-
8
- Object.defineProperty(exports, "CurrencySymbolEnum", {
9
- enumerable: true,
10
- get: function () { return format.CurrencySymbolEnum; }
11
- });
12
- exports.formatAccountNumber = format.formatAccountNumber;
13
- exports.formatNumber = format.formatNumber;
14
- exports.getCurrencySymbol = format.getCurrencySymbol;
15
- exports.parseFormatNumber = format.parseFormatNumber;
16
- //# sourceMappingURL=index-fmt.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-fmt.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
@@ -1 +0,0 @@
1
- export * from './format';
package/dist/index-fmt.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _format = require("./format");
7
- Object.keys(_format).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _format[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function get() {
13
- return _format[key];
14
- }
15
- });
16
- });
17
- //# sourceMappingURL=index-fmt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-fmt.js","names":["_format","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../src/index-fmt.ts"],"sourcesContent":["export * from './format';\n"],"mappings":";;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -1,3 +0,0 @@
1
- export { CurrencySymbolEnum, formatAccountNumber, formatNumber, getCurrencySymbol, parseFormatNumber } from './format.mjs';
2
- import '@formatjs/intl-numberformat';
3
- //# sourceMappingURL=index-fmt.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-fmt.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
package/src/index-fmt.ts DELETED
@@ -1 +0,0 @@
1
- export * from './format';