@andre1502/react-utilities 0.9.0 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +72 -17
- package/dist/Config/Config.js +21 -4
- package/dist/Config/Config.js.map +1 -1
- package/dist/Config/Output.js +9 -1
- package/dist/Config/Output.js.map +1 -1
- package/dist/EnvironmentEnum-BjXsfSRZ.js +9 -0
- package/dist/EnvironmentEnum-BjXsfSRZ.js.map +1 -0
- package/dist/EnvironmentEnum-UcQ6Il1O.js +9 -0
- package/dist/EnvironmentEnum-UcQ6Il1O.js.map +1 -0
- package/dist/I18n/I18n.d.ts +6 -0
- package/dist/I18n/I18n.js +104 -0
- package/dist/I18n/I18n.js.map +1 -0
- package/dist/I18n-CB7SyXYJ.js +3291 -0
- package/dist/I18n-CB7SyXYJ.js.map +1 -0
- package/dist/I18n-yXLN_hDO.js +3288 -0
- package/dist/I18n-yXLN_hDO.js.map +1 -0
- package/dist/config-cli.cjs +34 -5
- package/dist/config-cli.cjs.map +1 -1
- package/dist/config-cli.d.ts +2 -0
- package/dist/config-cli.js +8 -0
- package/dist/config-cli.js.map +1 -1
- package/dist/config-cli.mjs +32 -7
- package/dist/config-cli.mjs.map +1 -1
- package/dist/enums/EnvironmentEnum.d.ts +5 -0
- package/dist/enums/EnvironmentEnum.js +13 -0
- package/dist/enums/EnvironmentEnum.js.map +1 -0
- package/dist/i18n.cjs +15 -0
- package/dist/i18n.cjs.map +1 -0
- package/dist/i18n.d.ts +3 -0
- package/dist/i18n.js +28 -0
- package/dist/i18n.js.map +1 -0
- package/dist/i18n.mjs +4 -0
- package/dist/i18n.mjs.map +1 -0
- package/dist/index-cli.cjs +5 -0
- package/dist/index-cli.cjs.map +1 -1
- package/dist/index-cli.mjs +1 -0
- package/dist/index-cli.mjs.map +1 -1
- package/dist/index-rn.cjs +9 -0
- package/dist/index-rn.cjs.map +1 -1
- package/dist/index-rn.d.ts +1 -0
- package/dist/index-rn.js +11 -0
- package/dist/index-rn.js.map +1 -1
- package/dist/index-rn.mjs +3 -0
- package/dist/index-rn.mjs.map +1 -1
- package/dist/index.cjs +9 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -6
- package/src/Config/Config.ts +22 -4
- package/src/Config/Output.ts +16 -7
- package/src/I18n/I18n.ts +117 -0
- package/src/config-cli.ts +2 -0
- package/src/enums/EnvironmentEnum.ts +5 -0
- package/src/i18n.ts +4 -0
- package/src/index-rn.ts +1 -0
- package/src/index.ts +1 -0
- package/dist/index-fmt.cjs +0 -16
- package/dist/index-fmt.cjs.map +0 -1
- package/dist/index-fmt.d.ts +0 -1
- package/dist/index-fmt.js +0 -17
- package/dist/index-fmt.js.map +0 -1
- package/dist/index-fmt.mjs +0 -3
- package/dist/index-fmt.mjs.map +0 -1
- package/src/index-fmt.ts +0 -1
package/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# react-utilities
|
2
2
|
|
3
|
+
[![npm version](https://badge.fury.io/js/@andre1502%2Freact-utilities.svg)](https://badge.fury.io/js/@andre1502%2Freact-utilities)
|
4
|
+
|
3
5
|
Library to combine common functions
|
4
6
|
|
5
7
|
## Installation
|
@@ -30,7 +32,7 @@ const { fetchLocales } = require('@andre1502/react-utilities/cli');
|
|
30
32
|
// OR
|
31
33
|
const { fetchLocales } = require('@andre1502/react-utilities/config-cli');
|
32
34
|
|
33
|
-
https://docs.google.com/spreadsheets/d/<google-sheet-id>/edit
|
35
|
+
// https://docs.google.com/spreadsheets/d/<google-sheet-id>/edit
|
34
36
|
const optionLocales = {
|
35
37
|
spreadsheetId: '', // Google Sheet Id
|
36
38
|
spreadsheetTab: '', // Google Sheet Tab for locales
|
@@ -50,19 +52,20 @@ fetchLocales(optionLocales);
|
|
50
52
|
Config file only support export as js file, since you need to combine it with transform function.
|
51
53
|
|
52
54
|
```js
|
53
|
-
const { fetchConfig } = require('@andre1502
|
55
|
+
const { fetchConfig } = require('@andre1502/react-utilities/cli');
|
54
56
|
// OR
|
55
|
-
const { fetchConfig } = require('@andre1502
|
57
|
+
const { fetchConfig } = require('@andre1502/react-utilities/config-cli');
|
56
58
|
|
57
|
-
https://docs.google.com/spreadsheets/d/<google-sheet-id>/edit
|
59
|
+
// https://docs.google.com/spreadsheets/d/<google-sheet-id>/edit
|
58
60
|
const optionConfig = {
|
59
61
|
spreadsheetId: '', // Google Sheet Id
|
60
62
|
spreadsheetTab: '', // Google Sheet Tab for config;
|
61
63
|
formatAs: 'config',
|
62
64
|
output: {
|
63
65
|
folder: '.', // config folder location
|
64
|
-
filename: 'versionConfig
|
66
|
+
filename: 'versionConfig', // config filename
|
65
67
|
isFilenameLowercase: false, // set if filename need to be lowercase
|
68
|
+
exportAs: 'json', // export config as 'ts' | 'json' | 'js'
|
66
69
|
},
|
67
70
|
};
|
68
71
|
|
@@ -85,6 +88,20 @@ module.exports = {
|
|
85
88
|
};
|
86
89
|
```
|
87
90
|
|
91
|
+
```json
|
92
|
+
{
|
93
|
+
"params": {
|
94
|
+
"<app-brand>": {
|
95
|
+
"API_MAIN_URL": {
|
96
|
+
"dev": "<api-dev>",
|
97
|
+
"stag": "<api-staging>",
|
98
|
+
"prod": "<api-production>"
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
```
|
104
|
+
|
88
105
|
### Fetch All
|
89
106
|
|
90
107
|
To fetch both locales and config.
|
@@ -94,10 +111,10 @@ const { fetchAll } = require('@andre1502/react-utilities/cli');
|
|
94
111
|
// OR
|
95
112
|
const { fetchAll } = require('@andre1502/react-utilities/config-cli');
|
96
113
|
|
97
|
-
https://docs.google.com/spreadsheets/d/<google-sheet-id>/edit
|
114
|
+
// https://docs.google.com/spreadsheets/d/<google-sheet-id>/edit
|
98
115
|
const spreadsheetId = ''; // Google Sheet Id
|
99
116
|
const spreadsheetLocalesTab = ''; // Google Sheet Tab for locales
|
100
|
-
const spreadsheetConfigTab = '' // Google Sheet Tab for config;
|
117
|
+
const spreadsheetConfigTab = ''; // Google Sheet Tab for config;
|
101
118
|
|
102
119
|
const optionLocales = {
|
103
120
|
spreadsheetId: spreadsheetId,
|
@@ -116,8 +133,9 @@ const optionConfig = {
|
|
116
133
|
formatAs: 'config',
|
117
134
|
output: {
|
118
135
|
folder: '.', // config folder location
|
119
|
-
filename: 'versionConfig
|
136
|
+
filename: 'versionConfig', // config filename
|
120
137
|
isFilenameLowercase: false, // set if filename need to be lowercase
|
138
|
+
exportAs: 'json', // export locales as 'ts' | 'json' | 'js'
|
121
139
|
},
|
122
140
|
};
|
123
141
|
|
@@ -189,7 +207,9 @@ Add sentry file in root project with this code
|
|
189
207
|
```js
|
190
208
|
const { releaseSentrySourceMap } = require('@andre1502/react-utilities/cli');
|
191
209
|
// OR
|
192
|
-
const {
|
210
|
+
const {
|
211
|
+
releaseSentrySourceMap,
|
212
|
+
} = require('@andre1502/react-utilities/sentry-cli');
|
193
213
|
|
194
214
|
releaseSentrySourceMap({
|
195
215
|
env: '',
|
@@ -268,8 +288,6 @@ initSentry({
|
|
268
288
|
```js
|
269
289
|
import { formatAccountNumber } from '@andre1502/react-utilities';
|
270
290
|
// OR
|
271
|
-
import { formatAccountNumber } from '@andre1502/react-utilities/fmt';
|
272
|
-
// OR
|
273
291
|
import { formatAccountNumber } from '@andre1502/react-utilities/format';
|
274
292
|
|
275
293
|
const accountNumber = '1234567890123456';
|
@@ -285,8 +303,6 @@ console.log(`result: ${result}`);
|
|
285
303
|
```js
|
286
304
|
import { formatNumber } from '@andre1502/react-utilities';
|
287
305
|
// OR
|
288
|
-
import { formatNumber } from '@andre1502/react-utilities/fmt';
|
289
|
-
// OR
|
290
306
|
import { formatNumber } from '@andre1502/react-utilities/format';
|
291
307
|
|
292
308
|
const result = formatNumber({
|
@@ -309,8 +325,6 @@ console.log(`result: ${result}`);
|
|
309
325
|
```js
|
310
326
|
import { getCurrencySymbol } from '@andre1502/react-utilities';
|
311
327
|
// OR
|
312
|
-
import { getCurrencySymbol } from '@andre1502/react-utilities/fmt';
|
313
|
-
// OR
|
314
328
|
import { getCurrencySymbol } from '@andre1502/react-utilities/format';
|
315
329
|
|
316
330
|
const currency = 'TWD';
|
@@ -327,8 +341,6 @@ console.log(`result: ${result}`);
|
|
327
341
|
```js
|
328
342
|
import { parseFormatNumber } from '@andre1502/react-utilities';
|
329
343
|
// OR
|
330
|
-
import { parseFormatNumber } from '@andre1502/react-utilities/fmt';
|
331
|
-
// OR
|
332
344
|
import { parseFormatNumber } from '@andre1502/react-utilities/format';
|
333
345
|
|
334
346
|
const lang = 'zh-TW';
|
@@ -338,3 +350,46 @@ const result = parseFormatNumber(lang, value);
|
|
338
350
|
console.log(`result: ${result}`);
|
339
351
|
// output: 1000
|
340
352
|
```
|
353
|
+
|
354
|
+
## I18n
|
355
|
+
|
356
|
+
```js
|
357
|
+
import { initReactI18next } from 'react-i18next';
|
358
|
+
import { version } from './package.json';
|
359
|
+
import enUS from './en-US.json';
|
360
|
+
// ---
|
361
|
+
import { EnvironmentEnum, initI18n } from '@andre1502/react-utilities';
|
362
|
+
// OR
|
363
|
+
import { EnvironmentEnum, initI18n } from '@andre1502/react-utilities/i18n';
|
364
|
+
|
365
|
+
const localLang = 'en-US';
|
366
|
+
const fallbackLang = 'en-US';
|
367
|
+
const langCacheExpiredTimeMs = 60 * 60 * 1000;
|
368
|
+
|
369
|
+
// translation language from json file.
|
370
|
+
const resources = {
|
371
|
+
'en-US': { translation: enUS },
|
372
|
+
};
|
373
|
+
|
374
|
+
// optional, if false or undefined will use resources value
|
375
|
+
const withLocalstorageBackend = false;
|
376
|
+
|
377
|
+
// change this to real CDN url or cloud storage with direct access like AWS S3 or GCP cloud storage.
|
378
|
+
// optional, if empty, false or undefined will use resources value
|
379
|
+
const cdnUrl = 'http://cdnurl.com';
|
380
|
+
|
381
|
+
// optional, if false or undefined disable debug mode
|
382
|
+
const debug = false;
|
383
|
+
|
384
|
+
initI18n(
|
385
|
+
initReactI18next,
|
386
|
+
localLang,
|
387
|
+
fallbackLang,
|
388
|
+
langCacheExpiredTimeMs,
|
389
|
+
resources,
|
390
|
+
version,
|
391
|
+
withLocalstorageBackend,
|
392
|
+
cdnUrl,
|
393
|
+
debug,
|
394
|
+
);
|
395
|
+
```
|
package/dist/Config/Config.js
CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.transformConfig = exports.processConfig = exports.exportConfig = void 0;
|
7
7
|
var lodash = _interopRequireWildcard(require("lodash"));
|
8
|
+
var _EnvironmentEnum = require("../enums/EnvironmentEnum");
|
8
9
|
var _Output = require("./Output");
|
9
10
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
10
11
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
@@ -92,7 +93,23 @@ var exportConfig = exports.exportConfig = function exportConfig(data, options) {
|
|
92
93
|
var config = {
|
93
94
|
params: data
|
94
95
|
};
|
95
|
-
var content =
|
96
|
+
var content = '';
|
97
|
+
switch (options.exportAs) {
|
98
|
+
case 'ts':
|
99
|
+
content = 'export default ' + JSON.stringify(config, null, 2);
|
100
|
+
options.filename = "".concat(options.filename, ".ts");
|
101
|
+
break;
|
102
|
+
case 'json':
|
103
|
+
content = JSON.stringify(config, null, 2);
|
104
|
+
options.filename = "".concat(options.filename, ".json");
|
105
|
+
break;
|
106
|
+
case 'js':
|
107
|
+
content = "module.exports = ".concat(JSON.stringify(config, null, 2));
|
108
|
+
options.filename = "".concat(options.filename, ".js");
|
109
|
+
break;
|
110
|
+
default:
|
111
|
+
throw new Error("exportAs ".concat(options.exportAs, " not supported."));
|
112
|
+
}
|
96
113
|
(0, _Output.outputToFile)(content, options);
|
97
114
|
};
|
98
115
|
|
@@ -108,17 +125,17 @@ var envMap = function envMap(env) {
|
|
108
125
|
case 'dev':
|
109
126
|
case 'develop':
|
110
127
|
case 'development':
|
111
|
-
result =
|
128
|
+
result = _EnvironmentEnum.EnvironmentEnum.DEV;
|
112
129
|
break;
|
113
130
|
case 'stg':
|
114
131
|
case 'stag':
|
115
132
|
case 'staging':
|
116
|
-
result =
|
133
|
+
result = _EnvironmentEnum.EnvironmentEnum.STAGING;
|
117
134
|
break;
|
118
135
|
case 'prd':
|
119
136
|
case 'prod':
|
120
137
|
case 'production':
|
121
|
-
result =
|
138
|
+
result = _EnvironmentEnum.EnvironmentEnum.PRODUCTION;
|
122
139
|
break;
|
123
140
|
default:
|
124
141
|
throw new Error("env ".concat(env, " not supported."));
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Config.js","names":["lodash","_interopRequireWildcard","require","_Output","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","_typeof","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","o","Symbol","iterator","constructor","prototype","processConfig","exports","rows","versionConfig","params","map","key","forEach","row","index","processRow","data","versionName","paramsName","undefined","paramsTypeHandler","isJsonString","str","JSON","parse","booleanText","includes","toUpperCase","exportConfig","options","config","content","concat","stringify","outputToFile","envMap","env","result","Error","contentMap","value","exportAs","isNull","transformConfig","configKeyPrefix","envKey","keys","newConfigKey","extensionFile","join","Array","isArray"],"sources":["../../src/Config/Config.ts"],"sourcesContent":["import * as lodash from 'lodash';\nimport { OutputMap } from '../interfaces/Config/OutputMap';\nimport { OutputOptions } from '../interfaces/Config/OutputOptions';\nimport { outputToFile } from './Output';\n\n/**\n * Process config data\n *\n * @param {any[][]} rows\n * @return {OutputMap}\n */\nconst processConfig = (rows: any[][]): OutputMap => {\n let versionConfig: OutputMap = {};\n\n let params = rows[0].map((key) => {\n return key;\n });\n\n rows.forEach((row: string[], index: number) => {\n if (index === 0) {\n return;\n }\n\n versionConfig = processRow(row, params, versionConfig);\n });\n\n return versionConfig;\n};\n\n/**\n * Process config item\n *\n * @param {string[]} data\n * @param {string[]} params\n * @param {OutputMap} versionConfig\n * @return {OutputMap}\n */\nconst processRow = (\n data: string[],\n params: string[],\n versionConfig: OutputMap,\n): OutputMap => {\n const versionName = data[0];\n versionConfig[versionName] = {};\n\n params.forEach((paramsName, index) => {\n if (index === 0 || data[index] === undefined || data[index] === '') {\n return;\n }\n\n versionConfig[versionName][paramsName] = paramsTypeHandler(data[index]);\n });\n\n return versionConfig;\n};\n\n/**\n * Check is JSON value\n *\n * @param {string} str\n * @return {boolean}\n */\nconst isJsonString = (str: string): boolean => {\n try {\n JSON.parse(str);\n } catch (e) {\n return false;\n }\n\n return true;\n};\n\n/**\n * Handling config value type\n *\n * @param {string} params\n * @return {any}\n */\nconst paramsTypeHandler = (params: string): any => {\n const booleanText = ['TRUE', 'FALSE'];\n\n if (booleanText.includes(params.toUpperCase())) {\n return params === 'TRUE';\n }\n\n if (isJsonString(params)) {\n return JSON.parse(params);\n }\n\n return params;\n};\n\n/**\n * Export config data into js file\n *\n * @param {OutputMap} data\n * @param {OutputOptions} options\n * @return {void}\n */\nconst exportConfig = (data: OutputMap, options: OutputOptions): void => {\n const config = {\n params: data,\n };\n\n const content = `module.exports = ${JSON.stringify(config, null, 2)}`;\n\n outputToFile(content, options);\n};\n\n/**\n * Handling env map value\n *\n * @param {string} env\n * @return {string}\n */\nconst envMap = (env: string): string => {\n let result;\n\n switch (env) {\n case 'dev':\n case 'develop':\n case 'development':\n result = 'dev';\n break;\n case 'stg':\n case 'stag':\n case 'staging':\n result = 'staging';\n break;\n case 'prd':\n case 'prod':\n case 'production':\n result = 'production';\n break;\n default:\n throw new Error(`env ${env} not supported.`);\n }\n\n return result;\n};\n\n/**\n * Mapping content to exportAs value\n *\n * @param {string} key\n * @param {any} value\n * @param {string} exportAs\n * @return {string}\n */\nconst contentMap = (key: string, value: any, exportAs: string): string => {\n let content = '';\n\n switch (exportAs) {\n case 'ts':\n if (lodash.isNull(value)) {\n content += `export const ${key}: string | null = ${value};\\n`;\n } else if (typeof value === 'boolean') {\n content += `export const ${key}: boolean = ${value};\\n`;\n } else {\n content += `export const ${key} = '${value}';\\n`;\n }\n break;\n case 'js':\n content += `export const ${key} = \"${value}\";\\n`;\n break;\n case 'env':\n content += `${key} = \"${value}\"\\n`;\n break;\n default:\n throw new Error(`exportAs ${exportAs} not supported.`);\n }\n\n return content;\n};\n\n/**\n * Transform config\n *\n * @param {OutputMap} data\n * @param {string} env\n * @param {string} configKeyPrefix\n * @param {OutputOptions} options\n * @return {void}\n */\nconst transformConfig = (\n data: OutputMap,\n env: string,\n configKeyPrefix: string,\n options: OutputOptions,\n): void => {\n const envKey = configKeyPrefix ? `${configKeyPrefix}ENV` : 'ENV';\n\n let content = contentMap(envKey, envMap(env), options.exportAs!);\n\n Object.keys(data).forEach((key) => {\n const newConfigKey = configKeyPrefix ? `${configKeyPrefix}${key}` : key;\n\n if (key === 'BASE_PROJECT') {\n const extensionFile = [\n `.${data[key]}.js`,\n `.${data[key]}.jsx`,\n `.${data[key]}.ts`,\n `.${data[key]}.tsx`,\n `.${data[key]}.css`,\n `.${data[key]}.json`,\n `.${data[key]}.scss`,\n ];\n\n content += contentMap(\n newConfigKey,\n extensionFile.join(','),\n options.exportAs!,\n );\n\n return;\n }\n\n if (key === 'SITEMAP') {\n content += contentMap(\n newConfigKey,\n JSON.stringify(data[key]),\n options.exportAs!,\n );\n\n return;\n }\n\n if (Array.isArray(data[key])) {\n content += contentMap(\n newConfigKey,\n data[key].join(','),\n options.exportAs!,\n );\n\n return;\n }\n\n if (typeof data[key] === 'object') {\n if (data[key].hasOwnProperty(env)) {\n content += contentMap(newConfigKey, data[key][env], options.exportAs!);\n } else {\n content += contentMap(\n newConfigKey,\n JSON.stringify(data[key]),\n options.exportAs!,\n );\n }\n\n return;\n }\n\n content += contentMap(newConfigKey, data[key], options.exportAs!);\n });\n\n outputToFile(content, options);\n};\n\nexport { exportConfig, processConfig, transformConfig };\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAGA,IAAAC,OAAA,GAAAD,OAAA;AAAwC,SAAAE,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,yBAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAJ,wBAAAI,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,gBAAAK,OAAA,CAAAL,CAAA,0BAAAA,CAAA,sBAAAA,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAAP,MAAA,CAAAC,cAAA,CAAAJ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AC,EACvBpB,OAAO,CAACY,QACV,CAAC;MAED;IACF;IAEA,IAAI9B,GAAG,KAAK,SAAS,EAAE;MACrBoB,OAAO,IAAIQ,UAAU,CACnBQ,YAAY,EACZxB,IAAI,CAACU,SAAS,CAACjB,IAAI,CAACL,GAAG,CAAC,CAAC,EACzBkB,OAAO,CAACY,QACV,CAAC;MAED;IACF;IAEA,IAAIS,KAAK,CAACC,OAAO,CAACnC,IAAI,CAACL,GAAG,CAAC,CAAC,EAAE;MAC5BoB,OAAO,IAAIQ,UAAU,CACnBQ,YAAY,EACZ/B,IAAI,CAACL,GAAG,CAAC,CAACsC,IAAI,CAAC,GAAG,CAAC,EACnBpB,OAAO,CAACY,QACV,CAAC;MAED;IACF;IAEA,IAAIvD,OAAA,CAAO8B,IAAI,CAACL,GAAG,CAAC,MAAK,QAAQ,EAAE;MACjC,IAAIK,IAAI,CAACL,GAAG,CAAC,CAACf,cAAc,CAACwC,GAAG,CAAC,EAAE;QACjCL,OAAO,IAAIQ,UAAU,CAACQ,YAAY,EAAE/B,IAAI,CAACL,GAAG,CAAC,CAACyB,GAAG,CAAC,EAAEP,OAAO,CAACY,QAAS,CAAC;MACxE,CAAC,MAAM;QACLV,OAAO,IAAIQ,UAAU,CACnBQ,YAAY,EACZxB,IAAI,CAACU,SAAS,CAACjB,IAAI,CAACL,GAAG,CAAC,CAAC,EACzBkB,OAAO,CAACY,QACV,CAAC;MACH;MAEA;IACF;IAEAV,OAAO,IAAIQ,UAAU,CAACQ,YAAY,EAAE/B,IAAI,CAACL,GAAG,CAAC,EAAEkB,OAAO,CAACY,QAAS,CAAC;EACnE,CAAC,CAAC;EAEF,IAAAP,oBAAY,EAACH,OAAO,EAAEF,OAAO,CAAC;AAChC,CAAC","ignoreList":[]}
|
1
|
+
{"version":3,"file":"Config.js","names":["lodash","_interopRequireWildcard","require","_EnvironmentEnum","_Output","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","_typeof","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","o","Symbol","iterator","constructor","prototype","processConfig","exports","rows","versionConfig","params","map","key","forEach","row","index","processRow","data","versionName","paramsName","undefined","paramsTypeHandler","isJsonString","str","JSON","parse","booleanText","includes","toUpperCase","exportConfig","options","config","content","exportAs","stringify","filename","concat","Error","outputToFile","envMap","env","result","EnvironmentEnum","DEV","STAGING","PRODUCTION","contentMap","value","isNull","transformConfig","configKeyPrefix","envKey","keys","newConfigKey","extensionFile","join","Array","isArray"],"sources":["../../src/Config/Config.ts"],"sourcesContent":["import * as lodash from 'lodash';\nimport { EnvironmentEnum } from '../enums/EnvironmentEnum';\nimport { OutputMap } from '../interfaces/Config/OutputMap';\nimport { OutputOptions } from '../interfaces/Config/OutputOptions';\nimport { outputToFile } from './Output';\n\n/**\n * Process config data\n *\n * @param {any[][]} rows\n * @return {OutputMap}\n */\nconst processConfig = (rows: any[][]): OutputMap => {\n let versionConfig: OutputMap = {};\n\n let params = rows[0].map((key) => {\n return key;\n });\n\n rows.forEach((row: string[], index: number) => {\n if (index === 0) {\n return;\n }\n\n versionConfig = processRow(row, params, versionConfig);\n });\n\n return versionConfig;\n};\n\n/**\n * Process config item\n *\n * @param {string[]} data\n * @param {string[]} params\n * @param {OutputMap} versionConfig\n * @return {OutputMap}\n */\nconst processRow = (\n data: string[],\n params: string[],\n versionConfig: OutputMap,\n): OutputMap => {\n const versionName = data[0];\n versionConfig[versionName] = {};\n\n params.forEach((paramsName, index) => {\n if (index === 0 || data[index] === undefined || data[index] === '') {\n return;\n }\n\n versionConfig[versionName][paramsName] = paramsTypeHandler(data[index]);\n });\n\n return versionConfig;\n};\n\n/**\n * Check is JSON value\n *\n * @param {string} str\n * @return {boolean}\n */\nconst isJsonString = (str: string): boolean => {\n try {\n JSON.parse(str);\n } catch (e) {\n return false;\n }\n\n return true;\n};\n\n/**\n * Handling config value type\n *\n * @param {string} params\n * @return {any}\n */\nconst paramsTypeHandler = (params: string): any => {\n const booleanText = ['TRUE', 'FALSE'];\n\n if (booleanText.includes(params.toUpperCase())) {\n return params === 'TRUE';\n }\n\n if (isJsonString(params)) {\n return JSON.parse(params);\n }\n\n return params;\n};\n\n/**\n * Export config data into js file\n *\n * @param {OutputMap} data\n * @param {OutputOptions} options\n * @return {void}\n */\nconst exportConfig = (data: OutputMap, options: OutputOptions): void => {\n const config = {\n params: data,\n };\n\n let content = '';\n\n switch (options.exportAs) {\n case 'ts':\n content = 'export default ' + JSON.stringify(config, null, 2);\n options.filename = `${options.filename}.ts`;\n break;\n case 'json':\n content = JSON.stringify(config, null, 2);\n options.filename = `${options.filename}.json`;\n break;\n case 'js':\n content = `module.exports = ${JSON.stringify(config, null, 2)}`;\n options.filename = `${options.filename}.js`;\n break;\n default:\n throw new Error(`exportAs ${options.exportAs} not supported.`);\n }\n\n outputToFile(content, options);\n};\n\n/**\n * Handling env map value\n *\n * @param {string} env\n * @return {string}\n */\nconst envMap = (env: string): string => {\n let result;\n\n switch (env) {\n case 'dev':\n case 'develop':\n case 'development':\n result = EnvironmentEnum.DEV;\n break;\n case 'stg':\n case 'stag':\n case 'staging':\n result = EnvironmentEnum.STAGING;\n break;\n case 'prd':\n case 'prod':\n case 'production':\n result = EnvironmentEnum.PRODUCTION;\n break;\n default:\n throw new Error(`env ${env} not supported.`);\n }\n\n return result;\n};\n\n/**\n * Mapping content to exportAs value\n *\n * @param {string} key\n * @param {any} value\n * @param {string} exportAs\n * @return {string}\n */\nconst contentMap = (key: string, value: any, exportAs: string): string => {\n let content = '';\n\n switch (exportAs) {\n case 'ts':\n if (lodash.isNull(value)) {\n content += `export const ${key}: string | null = ${value};\\n`;\n } else if (typeof value === 'boolean') {\n content += `export const ${key}: boolean = ${value};\\n`;\n } else {\n content += `export const ${key} = '${value}';\\n`;\n }\n break;\n case 'js':\n content += `export const ${key} = \"${value}\";\\n`;\n break;\n case 'env':\n content += `${key} = \"${value}\"\\n`;\n break;\n default:\n throw new Error(`exportAs ${exportAs} not supported.`);\n }\n\n return content;\n};\n\n/**\n * Transform config\n *\n * @param {OutputMap} data\n * @param {string} env\n * @param {string} configKeyPrefix\n * @param {OutputOptions} options\n * @return {void}\n */\nconst transformConfig = (\n data: OutputMap,\n env: string,\n configKeyPrefix: string,\n options: OutputOptions,\n): void => {\n const envKey = configKeyPrefix ? `${configKeyPrefix}ENV` : 'ENV';\n\n let content = contentMap(envKey, envMap(env), options.exportAs!);\n\n Object.keys(data).forEach((key) => {\n const newConfigKey = configKeyPrefix ? `${configKeyPrefix}${key}` : key;\n\n if (key === 'BASE_PROJECT') {\n const extensionFile = [\n `.${data[key]}.js`,\n `.${data[key]}.jsx`,\n `.${data[key]}.ts`,\n `.${data[key]}.tsx`,\n `.${data[key]}.css`,\n `.${data[key]}.json`,\n `.${data[key]}.scss`,\n ];\n\n content += contentMap(\n newConfigKey,\n extensionFile.join(','),\n options.exportAs!,\n );\n\n return;\n }\n\n if (key === 'SITEMAP') {\n content += contentMap(\n newConfigKey,\n JSON.stringify(data[key]),\n options.exportAs!,\n );\n\n return;\n }\n\n if (Array.isArray(data[key])) {\n content += contentMap(\n newConfigKey,\n data[key].join(','),\n options.exportAs!,\n );\n\n return;\n }\n\n if (typeof data[key] === 'object') {\n if (data[key].hasOwnProperty(env)) {\n content += contentMap(newConfigKey, data[key][env], options.exportAs!);\n } else {\n content += contentMap(\n newConfigKey,\n JSON.stringify(data[key]),\n options.exportAs!,\n );\n }\n\n return;\n }\n\n content += contentMap(newConfigKey, data[key], options.exportAs!);\n });\n\n outputToFile(content, options);\n};\n\nexport { exportConfig, processConfig, transformConfig };\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AAGA,IAAAE,OAAA,GAAAF,OAAA;AAAwC,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,yBAA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;AAChC,CAAC","ignoreList":[]}
|
package/dist/Config/Output.js
CHANGED
@@ -18,7 +18,15 @@ var outputToFile = exports.outputToFile = function outputToFile(content, options
|
|
18
18
|
filename = filename.toLowerCase();
|
19
19
|
}
|
20
20
|
var filePath = "".concat(options.folder, "/").concat(filename);
|
21
|
-
(0, _fs.
|
21
|
+
if (!(0, _fs.existsSync)(options.folder)) {
|
22
|
+
(0, _fs.mkdirSync)(options.folder, {
|
23
|
+
recursive: true
|
24
|
+
});
|
25
|
+
}
|
26
|
+
(0, _fs.writeFile)(filePath, content, {
|
27
|
+
encoding: 'utf-8',
|
28
|
+
flag: 'w'
|
29
|
+
}, function (err) {
|
22
30
|
if (err) {
|
23
31
|
throw err;
|
24
32
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Output.js","names":["_fs","require","outputToFile","exports","content","options","filename","isFilenameLowercase","toLowerCase","filePath","concat","folder","writeFile","err","console","log"],"sources":["../../src/Config/Output.ts"],"sourcesContent":["import { writeFile } from 'fs';\nimport { OutputOptions } from '../interfaces/Config/OutputOptions';\n\n/**\n * Write content into target file\n *\n * @param {string} content\n * @param {OutputOptions} options\n * @return {void}\n */\nconst outputToFile = (content: string, options: OutputOptions): void => {\n let filename = options.filename;\n\n if (options.isFilenameLowercase) {\n filename = filename.toLowerCase();\n }\n\n const filePath = `${options.folder}/${filename}`;\n\n writeFile(filePath
|
1
|
+
{"version":3,"file":"Output.js","names":["_fs","require","outputToFile","exports","content","options","filename","isFilenameLowercase","toLowerCase","filePath","concat","folder","existsSync","mkdirSync","recursive","writeFile","encoding","flag","err","console","log"],"sources":["../../src/Config/Output.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFile } from 'fs';\nimport { OutputOptions } from '../interfaces/Config/OutputOptions';\n\n/**\n * Write content into target file\n *\n * @param {string} content\n * @param {OutputOptions} options\n * @return {void}\n */\nconst outputToFile = (content: string, options: OutputOptions): void => {\n let filename = options.filename;\n\n if (options.isFilenameLowercase) {\n filename = filename.toLowerCase();\n }\n\n const filePath = `${options.folder}/${filename}`;\n\n if (!existsSync(options.folder)) {\n mkdirSync(options.folder, { recursive: true });\n }\n\n writeFile(\n filePath,\n content,\n { encoding: 'utf-8', flag: 'w' },\n function (err) {\n if (err) {\n throw err;\n }\n\n console.log(filePath, content);\n },\n );\n};\n\nexport { outputToFile };\n"],"mappings":";;;;;;AAAA,IAAAA,GAAA,GAAAC,OAAA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG,SAAfA,YAAYA,CAAIE,OAAe,EAAEC,OAAsB,EAAW;EACtE,IAAIC,QAAQ,GAAGD,OAAO,CAACC,QAAQ;EAE/B,IAAID,OAAO,CAACE,mBAAmB,EAAE;IAC/BD,QAAQ,GAAGA,QAAQ,CAACE,WAAW,CAAC,CAAC;EACnC;EAEA,IAAMC,QAAQ,MAAAC,MAAA,CAAML,OAAO,CAACM,MAAM,OAAAD,MAAA,CAAIJ,QAAQ,CAAE;EAEhD,IAAI,CAAC,IAAAM,cAAU,EAACP,OAAO,CAACM,MAAM,CAAC,EAAE;IAC/B,IAAAE,aAAS,EAACR,OAAO,CAACM,MAAM,EAAE;MAAEG,SAAS,EAAE;IAAK,CAAC,CAAC;EAChD;EAEA,IAAAC,aAAS,EACPN,QAAQ,EACRL,OAAO,EACP;IAAEY,QAAQ,EAAE,OAAO;IAAEC,IAAI,EAAE;EAAI,CAAC,EAChC,UAAUC,GAAG,EAAE;IACb,IAAIA,GAAG,EAAE;MACP,MAAMA,GAAG;IACX;IAEAC,OAAO,CAACC,GAAG,CAACX,QAAQ,EAAEL,OAAO,CAAC;EAChC,CACF,CAAC;AACH,CAAC","ignoreList":[]}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
exports.EnvironmentEnum = void 0;
|
4
|
+
(function (EnvironmentEnum) {
|
5
|
+
EnvironmentEnum["DEV"] = "dev";
|
6
|
+
EnvironmentEnum["STAGING"] = "staging";
|
7
|
+
EnvironmentEnum["PRODUCTION"] = "production";
|
8
|
+
})(exports.EnvironmentEnum || (exports.EnvironmentEnum = {}));
|
9
|
+
//# sourceMappingURL=EnvironmentEnum-BjXsfSRZ.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"EnvironmentEnum-BjXsfSRZ.js","sources":["../src/enums/EnvironmentEnum.ts"],"sourcesContent":[null],"names":["EnvironmentEnum"],"mappings":";;AAAYA,iCAIX;AAJD,CAAA,UAAYA,eAAe,EAAA;AACzBA,EAAAA,eAAA,CAAA,KAAA,CAAA,GAAA,KAAW,CAAA;AACXA,EAAAA,eAAA,CAAA,SAAA,CAAA,GAAA,SAAmB,CAAA;AACnBA,EAAAA,eAAA,CAAA,YAAA,CAAA,GAAA,YAAyB,CAAA;AAC3B,CAAC,EAJWA,uBAAe,KAAfA,uBAAe,GAI1B,EAAA,CAAA,CAAA;;"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
var EnvironmentEnum;
|
2
|
+
(function (EnvironmentEnum) {
|
3
|
+
EnvironmentEnum["DEV"] = "dev";
|
4
|
+
EnvironmentEnum["STAGING"] = "staging";
|
5
|
+
EnvironmentEnum["PRODUCTION"] = "production";
|
6
|
+
})(EnvironmentEnum || (EnvironmentEnum = {}));
|
7
|
+
|
8
|
+
export { EnvironmentEnum as E };
|
9
|
+
//# sourceMappingURL=EnvironmentEnum-UcQ6Il1O.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"EnvironmentEnum-UcQ6Il1O.js","sources":["../src/enums/EnvironmentEnum.ts"],"sourcesContent":[null],"names":["EnvironmentEnum"],"mappings":"IAAYA,gBAIX;AAJD,CAAA,UAAYA,eAAe,EAAA;AACzBA,EAAAA,eAAA,CAAA,KAAA,CAAA,GAAA,KAAW,CAAA;AACXA,EAAAA,eAAA,CAAA,SAAA,CAAA,GAAA,SAAmB,CAAA;AACnBA,EAAAA,eAAA,CAAA,YAAA,CAAA,GAAA,YAAyB,CAAA;AAC3B,CAAC,EAJWA,eAAe,KAAfA,eAAe,GAI1B,EAAA,CAAA,CAAA;;;;"}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { ThirdPartyModule } from 'i18next';
|
2
|
+
declare const getV: (divider: number) => number;
|
3
|
+
declare const initI18n: (initReactI18next: ThirdPartyModule, lang: string, fallbackLang: string, langCacheExpiredTimeMs: number, resources: {
|
4
|
+
[key: string]: any;
|
5
|
+
}, version: string, withLocalstorageBackend?: boolean, cdnUrl?: string, debug?: boolean) => void;
|
6
|
+
export { getV, initI18n };
|
@@ -0,0 +1,104 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.initI18n = exports.getV = void 0;
|
7
|
+
var _i18next = _interopRequireDefault(require("i18next"));
|
8
|
+
var _i18nextChainedBackend = _interopRequireDefault(require("i18next-chained-backend"));
|
9
|
+
var _i18nextHttpBackend = _interopRequireDefault(require("i18next-http-backend"));
|
10
|
+
var _i18nextLocalstorageBackend = _interopRequireDefault(require("i18next-localstorage-backend"));
|
11
|
+
var _i18nextResourcesToBackend = _interopRequireDefault(require("i18next-resources-to-backend"));
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
13
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
14
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
16
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
17
|
+
var getV = exports.getV = function getV(divider) {
|
18
|
+
return Math.floor(Date.now() / divider);
|
19
|
+
};
|
20
|
+
var initI18n = exports.initI18n = function initI18n(initReactI18next, lang, fallbackLang, langCacheExpiredTimeMs, resources, version, withLocalstorageBackend, cdnUrl, debug) {
|
21
|
+
var backends = [];
|
22
|
+
var backendOptions = [];
|
23
|
+
var langs = Object.keys(resources);
|
24
|
+
|
25
|
+
// https://www.i18next.com/how-to/backend-fallback
|
26
|
+
if (withLocalstorageBackend) {
|
27
|
+
var versions = {};
|
28
|
+
langs.forEach(function (value) {
|
29
|
+
return Object.assign(versions, _defineProperty({}, value, version));
|
30
|
+
});
|
31
|
+
backends.push(_i18nextLocalstorageBackend["default"]);
|
32
|
+
backendOptions.push({
|
33
|
+
// prefix for stored languages
|
34
|
+
prefix: "i18next_res_",
|
35
|
+
// expiration
|
36
|
+
expirationTime: langCacheExpiredTimeMs,
|
37
|
+
// language versions
|
38
|
+
versions: versions
|
39
|
+
});
|
40
|
+
}
|
41
|
+
if (cdnUrl) {
|
42
|
+
backends.push(_i18nextHttpBackend["default"]);
|
43
|
+
backendOptions.push({
|
44
|
+
// load resources from url path
|
45
|
+
loadPath: "".concat(cdnUrl, "/locales/{{lng}}.json"),
|
46
|
+
// adds parameters to resource URL. 'example.com' -> 'example.com?v=1.3.5'
|
47
|
+
queryStringParams: {
|
48
|
+
v: "".concat(version, ".").concat(getV(langCacheExpiredTimeMs))
|
49
|
+
},
|
50
|
+
reloadInterval: langCacheExpiredTimeMs // can be used to reload resources in a specific interval (milliseconds) (useful in server environments)
|
51
|
+
});
|
52
|
+
}
|
53
|
+
backends.push((0, _i18nextResourcesToBackend["default"])(resources));
|
54
|
+
|
55
|
+
// https://www.i18next.com/misc/creating-own-plugins#languagedetector
|
56
|
+
var languageDetector = {
|
57
|
+
type: 'languageDetector',
|
58
|
+
name: 'customDetector',
|
59
|
+
async: false,
|
60
|
+
init: function init() {
|
61
|
+
/* use services and options */
|
62
|
+
},
|
63
|
+
detect: function detect(callback) {
|
64
|
+
return lang;
|
65
|
+
}
|
66
|
+
};
|
67
|
+
var config = {
|
68
|
+
debug: debug !== null && debug !== void 0 ? debug : false,
|
69
|
+
compatibilityJSON: 'v4',
|
70
|
+
ns: ['translation'],
|
71
|
+
defaultNS: 'translation',
|
72
|
+
lng: lang,
|
73
|
+
fallbackLng: fallbackLang,
|
74
|
+
load: 'currentOnly',
|
75
|
+
keySeparator: false,
|
76
|
+
nonExplicitSupportedLngs: true,
|
77
|
+
backend: {
|
78
|
+
backends: backends,
|
79
|
+
backendOptions: backendOptions,
|
80
|
+
cacheHitMode: 'refreshAndUpdateStore',
|
81
|
+
reloadInterval: langCacheExpiredTimeMs,
|
82
|
+
refreshExpirationTime: langCacheExpiredTimeMs // only after determined time it should trigger a refresh if necessary
|
83
|
+
},
|
84
|
+
react: {
|
85
|
+
bindI18nStore: 'added' // this way, when the HttpBackend delivers new translations (thanks to refreshAndUpdateStore), the UI gets updated
|
86
|
+
},
|
87
|
+
interpolation: {
|
88
|
+
escapeValue: false // react already safes from xss
|
89
|
+
}
|
90
|
+
};
|
91
|
+
if (!_i18next["default"].isInitialized) {
|
92
|
+
_i18next["default"].use(_i18nextChainedBackend["default"]).use(languageDetector).use(initReactI18next) // passes i18n down to react-i18next
|
93
|
+
.init(config, function (ex, t) {
|
94
|
+
if (ex) {
|
95
|
+
console.error("Error when i18n init", ex);
|
96
|
+
return;
|
97
|
+
}
|
98
|
+
setInterval(function () {
|
99
|
+
_i18next["default"].reloadResources();
|
100
|
+
}, langCacheExpiredTimeMs);
|
101
|
+
});
|
102
|
+
}
|
103
|
+
};
|
104
|
+
//# sourceMappingURL=I18n.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"I18n.js","names":["_i18next","_interopRequireDefault","require","_i18nextChainedBackend","_i18nextHttpBackend","_i18nextLocalstorageBackend","_i18nextResourcesToBackend","e","__esModule","_typeof","o","Symbol","iterator","constructor","prototype","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","toPrimitive","call","TypeError","String","Number","getV","exports","divider","Math","floor","Date","now","initI18n","initReactI18next","lang","fallbackLang","langCacheExpiredTimeMs","resources","version","withLocalstorageBackend","cdnUrl","debug","backends","backendOptions","langs","keys","versions","forEach","assign","push","LocalStorageBackend","prefix","expirationTime","HttpBackend","loadPath","concat","queryStringParams","v","reloadInterval","ResourcesToBackend","languageDetector","type","name","async","init","detect","callback","config","compatibilityJSON","ns","defaultNS","lng","fallbackLng","load","keySeparator","nonExplicitSupportedLngs","backend","cacheHitMode","refreshExpirationTime","react","bindI18nStore","interpolation","escapeValue","i18next","isInitialized","use","ChainedBackend","ex","console","error","setInterval","reloadResources"],"sources":["../../src/I18n/I18n.ts"],"sourcesContent":["import i18next, { InitOptions, ThirdPartyModule } from 'i18next';\nimport ChainedBackend from 'i18next-chained-backend';\nimport HttpBackend from 'i18next-http-backend';\nimport LocalStorageBackend from 'i18next-localstorage-backend';\nimport ResourcesToBackend from 'i18next-resources-to-backend';\n\nconst getV = (divider: number): number => {\n return Math.floor(Date.now() / divider);\n};\n\nconst initI18n = (\n initReactI18next: ThirdPartyModule,\n lang: string,\n fallbackLang: string,\n langCacheExpiredTimeMs: number,\n resources: { [key: string]: any },\n version: string,\n withLocalstorageBackend?: boolean,\n cdnUrl?: string,\n debug?: boolean,\n) => {\n let backends: Array<any> = [];\n let backendOptions: Array<any> = [];\n const langs = Object.keys(resources);\n\n // https://www.i18next.com/how-to/backend-fallback\n if (withLocalstorageBackend) {\n const versions: { [key: string]: string } = {};\n\n langs.forEach((value) => Object.assign(versions, { [value]: version }));\n\n backends.push(LocalStorageBackend);\n backendOptions.push({\n // prefix for stored languages\n prefix: `i18next_res_`,\n\n // expiration\n expirationTime: langCacheExpiredTimeMs,\n\n // language versions\n versions: versions,\n });\n }\n\n if (cdnUrl) {\n backends.push(HttpBackend);\n backendOptions.push({\n // load resources from url path\n loadPath: `${cdnUrl}/locales/{{lng}}.json`,\n // adds parameters to resource URL. 'example.com' -> 'example.com?v=1.3.5'\n queryStringParams: {\n v: `${version}.${getV(langCacheExpiredTimeMs)}`,\n },\n\n reloadInterval: langCacheExpiredTimeMs, // can be used to reload resources in a specific interval (milliseconds) (useful in server environments)\n });\n }\n\n backends.push(ResourcesToBackend(resources));\n\n // https://www.i18next.com/misc/creating-own-plugins#languagedetector\n const languageDetector: any = {\n type: 'languageDetector',\n name: 'customDetector',\n async: false,\n init: () => {\n /* use services and options */\n },\n detect: (callback: any) => {\n return lang;\n },\n };\n\n const config: InitOptions = {\n debug: debug ?? false,\n compatibilityJSON: 'v4',\n ns: ['translation'],\n defaultNS: 'translation',\n lng: lang,\n fallbackLng: fallbackLang,\n load: 'currentOnly',\n keySeparator: false,\n nonExplicitSupportedLngs: true,\n backend: {\n backends: backends,\n backendOptions: backendOptions,\n cacheHitMode: 'refreshAndUpdateStore',\n reloadInterval: langCacheExpiredTimeMs,\n refreshExpirationTime: langCacheExpiredTimeMs, // only after determined time it should trigger a refresh if necessary\n },\n react: {\n bindI18nStore: 'added', // this way, when the HttpBackend delivers new translations (thanks to refreshAndUpdateStore), the UI gets updated\n },\n interpolation: {\n escapeValue: false, // react already safes from xss\n },\n };\n\n if (!i18next.isInitialized) {\n i18next\n .use(ChainedBackend)\n .use(languageDetector)\n .use(initReactI18next) // passes i18n down to react-i18next\n .init(config, (ex, t) => {\n if (ex) {\n console.error(`Error when i18n init`, ex);\n return;\n }\n\n setInterval(() => {\n i18next.reloadResources();\n }, langCacheExpiredTimeMs);\n });\n }\n};\n\nexport { getV, initI18n };\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,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