@stemy/ngx-utils 13.0.5 → 13.1.0

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.
@@ -0,0 +1,77 @@
1
+ function isPrimitive(value) {
2
+ const type = typeof value;
3
+ return value == null || (type !== "object" && type !== "function");
4
+ }
5
+ function isDate(value) {
6
+ return null !== value && !isNaN(value) && "undefined" !== typeof value.getDate;
7
+ }
8
+ function convertValue(value, type) {
9
+ switch (type) {
10
+ case "boolean":
11
+ value = typeof value == "string" ? value.toLowerCase() : value;
12
+ return (value == "no" || value == "false" || value == "0") ? false : !!value;
13
+ case "number":
14
+ const val = parseFloat(value);
15
+ return isNaN(val) ? 0 : val;
16
+ }
17
+ return value;
18
+ }
19
+ function getFromEnv(path, alternatives, value) {
20
+ const name = path.replace(/\.?([A-Z|0-9]+)/g, function (x, y) {
21
+ return "_" + y.toLowerCase();
22
+ }).replace(/\./gi, "_").replace(/^_/, "").toUpperCase();
23
+ const alts = Array.from(alternatives[name] || []);
24
+ alts.unshift(name);
25
+ for (const envName of alts) {
26
+ const envValue = process.env[envName];
27
+ if (typeof envValue !== "undefined") {
28
+ const val = convertValue(envValue, typeof value);
29
+ console.log(name, envName, val);
30
+ return convertValue(envValue, typeof value);
31
+ }
32
+ }
33
+ console.log(name, value);
34
+ return value;
35
+ }
36
+ function createConfigRecursive(target, source, path, alternatives) {
37
+ if (isPrimitive(source) || isDate(source)) {
38
+ return getFromEnv(path, alternatives, source);
39
+ }
40
+ if (Array.isArray(source)) {
41
+ target = Array.isArray(target) ? Array.from(target) : [];
42
+ source.forEach((item, index) => {
43
+ if (target.length > index)
44
+ target[index] = createConfigRecursive(target[index], item, !path ? `${index}` : `${path}.${index}`, alternatives);
45
+ else
46
+ target.push(createConfigRecursive(null, item, !path ? `${index}` : `${path}.${index}`, alternatives));
47
+ });
48
+ return target;
49
+ }
50
+ return Object.keys(source).reduce((result, key) => {
51
+ result[key] = createConfigRecursive(result[key], source[key], !path ? `${key}` : `${path}.${key}`, alternatives);
52
+ return result;
53
+ }, Object.assign({}, target));
54
+ }
55
+ function parseConfig(config) {
56
+ if (typeof config == "string") {
57
+ try {
58
+ config = JSON.parse(config);
59
+ }
60
+ catch (e) {
61
+ return {};
62
+ }
63
+ }
64
+ return config;
65
+ }
66
+ function createConfig(config, alternatives) {
67
+ alternatives = alternatives || {};
68
+ console.log("Parsing config...");
69
+ return createConfigRecursive(null, parseConfig(config), "", alternatives);
70
+ }
71
+
72
+ /**
73
+ * Generated bundle index. Do not edit.
74
+ */
75
+
76
+ export { createConfig };
77
+ //# sourceMappingURL=stemy-ngx-utils-tools.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stemy-ngx-utils-tools.mjs","sources":["../../tools/config.ts","../../tools/stemy-ngx-utils-tools.ts"],"sourcesContent":["export function isPrimitive(value: any): boolean {\r\n const type = typeof value;\r\n return value == null || (type !== \"object\" && type !== \"function\");\r\n}\r\n\r\nexport function isDate(value: any): value is Date {\r\n return null !== value && !isNaN(value) && \"undefined\" !== typeof value.getDate;\r\n}\r\n\r\nexport interface IEnvironmentAlternatives {\r\n [name: string]: string[]\r\n}\r\n\r\nfunction convertValue(value: any, type: string): any {\r\n switch (type) {\r\n case \"boolean\":\r\n value = typeof value == \"string\" ? value.toLowerCase() : value;\r\n return (value == \"no\" || value == \"false\" || value == \"0\") ? false : !!value;\r\n case \"number\":\r\n const val = parseFloat(value);\r\n return isNaN(val) ? 0 : val;\r\n }\r\n return value;\r\n}\r\n\r\nfunction getFromEnv(path: string, alternatives: IEnvironmentAlternatives, value: any): any {\r\n const name = path.replace(/\\.?([A-Z|0-9]+)/g, function (x,y){\r\n return \"_\" + y.toLowerCase()\r\n }).replace(/\\./gi, \"_\").replace(/^_/, \"\").toUpperCase();\r\n const alts = Array.from(alternatives[name] || []);\r\n alts.unshift(name);\r\n for (const envName of alts) {\r\n const envValue = process.env[envName];\r\n if (typeof envValue !== \"undefined\") {\r\n const val = convertValue(envValue, typeof value);\r\n console.log(name, envName, val);\r\n return convertValue(envValue, typeof value);\r\n }\r\n }\r\n console.log(name, value);\r\n return value;\r\n}\r\n\r\nfunction createConfigRecursive(target: any, source: any, path: string, alternatives: IEnvironmentAlternatives): any {\r\n if (isPrimitive(source) || isDate(source)) {\r\n return getFromEnv(path, alternatives, source);\r\n }\r\n if (Array.isArray(source)) {\r\n target = Array.isArray(target) ? Array.from(target) : [];\r\n source.forEach((item, index) => {\r\n if (target.length > index)\r\n target[index] = createConfigRecursive(target[index], item, !path ? `${index}` : `${path}.${index}`, alternatives);\r\n else\r\n target.push(createConfigRecursive(null, item, !path ? `${index}` : `${path}.${index}`, alternatives));\r\n });\r\n return target;\r\n }\r\n return Object.keys(source).reduce((result, key) => {\r\n result[key] = createConfigRecursive(result[key], source[key], !path ? `${key}` : `${path}.${key}`, alternatives);\r\n return result;\r\n }, Object.assign({}, target));\r\n}\r\n\r\nexport function parseConfig(config: any): any {\r\n if (typeof config == \"string\") {\r\n try {\r\n config = JSON.parse(config);\r\n } catch (e) {\r\n return {};\r\n }\r\n }\r\n return config;\r\n}\r\n\r\nexport function createConfig(config: any, alternatives?: IEnvironmentAlternatives): any {\r\n alternatives = alternatives || {};\r\n console.log(\"Parsing config...\");\r\n return createConfigRecursive(null, parseConfig(config), \"\", alternatives);\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":"AAAM,SAAU,WAAW,CAAC,KAAU,EAAA;AAClC,IAAA,MAAM,IAAI,GAAG,OAAO,KAAK,CAAC;AAC1B,IAAA,OAAO,KAAK,IAAI,IAAI,KAAK,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,UAAU,CAAC,CAAC;AACvE,CAAC;AAEK,SAAU,MAAM,CAAC,KAAU,EAAA;AAC7B,IAAA,OAAO,IAAI,KAAK,KAAK,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,WAAW,KAAK,OAAO,KAAK,CAAC,OAA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detector';
14
14
  import * as i1$1 from '@angular/common/http';
15
15
  import { HttpClient, HttpHeaders, HttpParams, HttpUrlEncodingCodec, HttpEventType } from '@angular/common/http';
16
+ import * as JSON5 from 'json5';
16
17
  import * as i1$2 from '@angular/platform-browser';
17
18
  import { ɵDomEventsPlugin, EVENT_MANAGER_PLUGINS } from '@angular/platform-browser';
18
19
  import { addListener, removeListener } from 'resize-detector';
@@ -2524,7 +2525,7 @@ class ConfigService {
2524
2525
  const configUrl = this.configUrl;
2525
2526
  try {
2526
2527
  const config5 = await this.http.get(isDevMode() ? `${configUrl}5` : configUrl, { responseType: "text" }).toPromise();
2527
- return require("json5").parse(config5);
2528
+ return JSON5.parse(config5);
2528
2529
  }
2529
2530
  catch (e) {
2530
2531
  try {