@reldens/utils 0.43.0 → 0.45.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.
- package/index.js +1 -0
- package/lib/env-var.js +51 -0
- package/lib/schema-validator.js +1 -1
- package/lib/validator-interface.js +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -13,6 +13,7 @@ module.exports = {
|
|
|
13
13
|
InteractionArea: require('./lib/interaction-area'),
|
|
14
14
|
ValidatorInterface: require('./lib/validator-interface'),
|
|
15
15
|
SchemaValidator: require('./lib/schema-validator'),
|
|
16
|
+
EnvVar: require('./lib/env-var'),
|
|
16
17
|
Logger: require('./lib/logger'),
|
|
17
18
|
sc: require('./lib/shortcuts')
|
|
18
19
|
};
|
package/lib/env-var.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - EnvVar
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
class EnvVar
|
|
8
|
+
{
|
|
9
|
+
|
|
10
|
+
string(obj, key, defaultValue)
|
|
11
|
+
{
|
|
12
|
+
const val = obj[key];
|
|
13
|
+
if('string' === typeof val){
|
|
14
|
+
return val;
|
|
15
|
+
}
|
|
16
|
+
return defaultValue;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
nonEmptyString(obj, key, defaultValue)
|
|
20
|
+
{
|
|
21
|
+
const val = obj[key];
|
|
22
|
+
if('string' === typeof val && '' !== val.trim()){
|
|
23
|
+
return val;
|
|
24
|
+
}
|
|
25
|
+
return defaultValue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
number(obj, key, defaultValue)
|
|
29
|
+
{
|
|
30
|
+
const val = obj[key];
|
|
31
|
+
if(!isNaN(Number(val)) && '' !== val && null !== val){
|
|
32
|
+
return Number(val);
|
|
33
|
+
}
|
|
34
|
+
return defaultValue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
boolean(obj, key, defaultValue)
|
|
38
|
+
{
|
|
39
|
+
const val = obj[key];
|
|
40
|
+
if('true' === val || '1' === val){
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if('false' === val || '0' === val){
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return defaultValue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = new EnvVar();
|
package/lib/schema-validator.js
CHANGED