mybase 1.0.29 → 1.0.33
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 +34 -5
- package/package.json +2 -2
package/README.md
CHANGED
package/mybase.js
CHANGED
|
@@ -21,7 +21,13 @@ Date.prototype.yyyymmdd = function() {
|
|
|
21
21
|
function validHPassword(hpassword) { return (hpassword && hpassword.length === 128 && hpassword.search(/^[a-f0-9]+$/) == 0) }
|
|
22
22
|
|
|
23
23
|
function validEmail_old(email) { return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) }
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
function validEmail(email) {
|
|
26
|
+
// taken from https://www.w3resource.com/javascript/form/email-validation.php
|
|
27
|
+
// strange looking emails might be indeed valid
|
|
28
|
+
// check https://www.w3resource.com/javascript/form/example-javascript-form-validation-email-REC-2822.html
|
|
29
|
+
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
|
+
}
|
|
25
31
|
|
|
26
32
|
|
|
27
33
|
function validIp(str) {
|
|
@@ -29,7 +35,7 @@ function validIp(str) {
|
|
|
29
35
|
let splitted
|
|
30
36
|
if (splitted=str.match(/^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/)) {
|
|
31
37
|
for(let octet of splitted) {
|
|
32
|
-
if (parseInt(octet)>=0
|
|
38
|
+
if (parseInt(octet)>=0 && parseInt(octet)<=255) continue
|
|
33
39
|
return false
|
|
34
40
|
}
|
|
35
41
|
return true
|
|
@@ -118,10 +124,12 @@ function vaultRead(vault, key) {
|
|
|
118
124
|
})
|
|
119
125
|
}
|
|
120
126
|
|
|
121
|
-
function vaultFill(vault, obj, ignoreError = false) {
|
|
127
|
+
function vaultFill(vault, obj, ignoreError = false, keepCache=true) {
|
|
122
128
|
// v2.1
|
|
123
129
|
// fills all strings with ^vault@/secret/... with proper vault values
|
|
124
130
|
// if you call it again, it does reload the configuration
|
|
131
|
+
// v2.2
|
|
132
|
+
// supports keepCache - if vault fails, we will keep previous values instead of filling with false
|
|
125
133
|
return new Promise(async function(resolve, reject) {
|
|
126
134
|
function findVaultKeyMappings(config, keys = []) {
|
|
127
135
|
|
|
@@ -152,6 +160,11 @@ function vaultFill(vault, obj, ignoreError = false) {
|
|
|
152
160
|
if (config[i] !== null) {
|
|
153
161
|
|
|
154
162
|
if (config[i] && config[i].constructor.name === 'Object' && config[i].hasOwnProperty('__vaultkey')) {
|
|
163
|
+
if (keepCache) {
|
|
164
|
+
if (vaultResults[config[i]['__vaultkey']]) config[i] = vaultResults[config[i]['__vaultkey']]
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
else
|
|
155
168
|
config[i] = vaultResults[config[i]['__vaultkey']]
|
|
156
169
|
continue
|
|
157
170
|
}
|
|
@@ -192,7 +205,6 @@ function vaultFill(vault, obj, ignoreError = false) {
|
|
|
192
205
|
|
|
193
206
|
resolve(true)
|
|
194
207
|
})
|
|
195
|
-
|
|
196
208
|
}
|
|
197
209
|
|
|
198
210
|
|
|
@@ -418,6 +430,22 @@ async function portCheck_tcp (port, {timeout = 1000, host='127.0.0.1'} = {}) {
|
|
|
418
430
|
}
|
|
419
431
|
}
|
|
420
432
|
|
|
433
|
+
function ensureProperty(target, propsString, defaultValue = false, debug = false) {
|
|
434
|
+
function iterate(o, parts) {
|
|
435
|
+
if (debug) console.log(parts)
|
|
436
|
+
let pname = parts.shift()
|
|
437
|
+
if (debug) console.log(`iterate`, o, pname)
|
|
438
|
+
if (o.hasOwnProperty(pname) && typeof o[pname] === 'object' && parts.length > 0) return iterate(o[pname], parts)
|
|
439
|
+
if (debug) console.log(`--`, o, pname, o[pname], parts)
|
|
440
|
+
if (o.hasOwnProperty(pname) && parts.length === 0) return o[pname]
|
|
441
|
+
if (debug) console.log(`+++`)
|
|
442
|
+
return defaultValue
|
|
443
|
+
}
|
|
444
|
+
var parts = propsString.split('.')
|
|
445
|
+
return iterate(target, parts)
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
|
|
421
449
|
|
|
422
450
|
function int2ip (ipInt) {
|
|
423
451
|
return ( (ipInt>>>24) +'.' + (ipInt>>16 & 255) +'.' + (ipInt>>8 & 255) +'.' + (ipInt & 255) );
|
|
@@ -457,5 +485,6 @@ module.exports = {
|
|
|
457
485
|
object_shuffle,
|
|
458
486
|
isMochaRunning,
|
|
459
487
|
portCheck_tcp,
|
|
460
|
-
asJSON
|
|
488
|
+
asJSON,
|
|
489
|
+
ensureProperty
|
|
461
490
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mybase",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.33",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "mybase.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"author": "",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@7c/validurl": "0.0.
|
|
12
|
+
"@7c/validurl": "0.0.3",
|
|
13
13
|
"chalk": "^3.0.0",
|
|
14
14
|
"debug": "^4.3.1",
|
|
15
15
|
"punycode": "^2.1.1"
|