mybase 1.0.31 → 1.0.32
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 +18 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/mybase.js
CHANGED
|
@@ -424,6 +424,22 @@ async function portCheck_tcp (port, {timeout = 1000, host='127.0.0.1'} = {}) {
|
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
426
|
|
|
427
|
+
function ensureProperty(target, propsString, defaultValue = false, debug = false) {
|
|
428
|
+
function iterate(o, parts) {
|
|
429
|
+
if (debug) console.log(parts)
|
|
430
|
+
let pname = parts.shift()
|
|
431
|
+
if (debug) console.log(`iterate`, o, pname)
|
|
432
|
+
if (o.hasOwnProperty(pname) && typeof o[pname] === 'object' && parts.length > 0) return iterate(o[pname], parts)
|
|
433
|
+
if (debug) console.log(`--`, o, pname, o[pname], parts)
|
|
434
|
+
if (o.hasOwnProperty(pname) && parts.length === 0) return o[pname]
|
|
435
|
+
if (debug) console.log(`+++`)
|
|
436
|
+
return defaultValue
|
|
437
|
+
}
|
|
438
|
+
var parts = propsString.split('.')
|
|
439
|
+
return iterate(target, parts)
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
|
|
427
443
|
|
|
428
444
|
function int2ip (ipInt) {
|
|
429
445
|
return ( (ipInt>>>24) +'.' + (ipInt>>16 & 255) +'.' + (ipInt>>8 & 255) +'.' + (ipInt & 255) );
|
|
@@ -463,5 +479,6 @@ module.exports = {
|
|
|
463
479
|
object_shuffle,
|
|
464
480
|
isMochaRunning,
|
|
465
481
|
portCheck_tcp,
|
|
466
|
-
asJSON
|
|
482
|
+
asJSON,
|
|
483
|
+
ensureProperty
|
|
467
484
|
}
|