mybase 1.0.31 → 1.0.34
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/README.md +1 -0
- package/mybase.js +27 -3
- package/package.json +1 -1
package/README.md
CHANGED
package/mybase.js
CHANGED
|
@@ -26,6 +26,7 @@ function validEmail(email) {
|
|
|
26
26
|
// taken from https://www.w3resource.com/javascript/form/email-validation.php
|
|
27
27
|
// strange looking emails might be indeed valid
|
|
28
28
|
// check https://www.w3resource.com/javascript/form/example-javascript-form-validation-email-REC-2822.html
|
|
29
|
+
if (typeof email==='string') email=email.toLowerCase().trim()
|
|
29
30
|
return (/(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/).test(email)
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -124,10 +125,12 @@ function vaultRead(vault, key) {
|
|
|
124
125
|
})
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
function vaultFill(vault, obj, ignoreError = false) {
|
|
128
|
+
function vaultFill(vault, obj, ignoreError = false, keepCache=true) {
|
|
128
129
|
// v2.1
|
|
129
130
|
// fills all strings with ^vault@/secret/... with proper vault values
|
|
130
131
|
// if you call it again, it does reload the configuration
|
|
132
|
+
// v2.2
|
|
133
|
+
// supports keepCache - if vault fails, we will keep previous values instead of filling with false
|
|
131
134
|
return new Promise(async function(resolve, reject) {
|
|
132
135
|
function findVaultKeyMappings(config, keys = []) {
|
|
133
136
|
|
|
@@ -158,6 +161,11 @@ function vaultFill(vault, obj, ignoreError = false) {
|
|
|
158
161
|
if (config[i] !== null) {
|
|
159
162
|
|
|
160
163
|
if (config[i] && config[i].constructor.name === 'Object' && config[i].hasOwnProperty('__vaultkey')) {
|
|
164
|
+
if (keepCache) {
|
|
165
|
+
if (vaultResults[config[i]['__vaultkey']]) config[i] = vaultResults[config[i]['__vaultkey']]
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
else
|
|
161
169
|
config[i] = vaultResults[config[i]['__vaultkey']]
|
|
162
170
|
continue
|
|
163
171
|
}
|
|
@@ -198,7 +206,6 @@ function vaultFill(vault, obj, ignoreError = false) {
|
|
|
198
206
|
|
|
199
207
|
resolve(true)
|
|
200
208
|
})
|
|
201
|
-
|
|
202
209
|
}
|
|
203
210
|
|
|
204
211
|
|
|
@@ -424,6 +431,22 @@ async function portCheck_tcp (port, {timeout = 1000, host='127.0.0.1'} = {}) {
|
|
|
424
431
|
}
|
|
425
432
|
}
|
|
426
433
|
|
|
434
|
+
function ensureProperty(target, propsString, defaultValue = false, debug = false) {
|
|
435
|
+
function iterate(o, parts) {
|
|
436
|
+
if (debug) console.log(parts)
|
|
437
|
+
let pname = parts.shift()
|
|
438
|
+
if (debug) console.log(`iterate`, o, pname)
|
|
439
|
+
if (o.hasOwnProperty(pname) && typeof o[pname] === 'object' && parts.length > 0) return iterate(o[pname], parts)
|
|
440
|
+
if (debug) console.log(`--`, o, pname, o[pname], parts)
|
|
441
|
+
if (o.hasOwnProperty(pname) && parts.length === 0) return o[pname]
|
|
442
|
+
if (debug) console.log(`+++`)
|
|
443
|
+
return defaultValue
|
|
444
|
+
}
|
|
445
|
+
var parts = propsString.split('.')
|
|
446
|
+
return iterate(target, parts)
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
|
|
427
450
|
|
|
428
451
|
function int2ip (ipInt) {
|
|
429
452
|
return ( (ipInt>>>24) +'.' + (ipInt>>16 & 255) +'.' + (ipInt>>8 & 255) +'.' + (ipInt & 255) );
|
|
@@ -463,5 +486,6 @@ module.exports = {
|
|
|
463
486
|
object_shuffle,
|
|
464
487
|
isMochaRunning,
|
|
465
488
|
portCheck_tcp,
|
|
466
|
-
asJSON
|
|
489
|
+
asJSON,
|
|
490
|
+
ensureProperty
|
|
467
491
|
}
|