mybase 1.0.34 → 1.0.35
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/mybase.js +37 -1
- package/package.json +1 -1
package/mybase.js
CHANGED
|
@@ -333,7 +333,42 @@ function softexit(message = false, seconds = 60, exitcode = 1) {
|
|
|
333
333
|
setTimeout(() => { process.exit(exitcode) }, seconds * 1000)
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
-
function validHostname(
|
|
336
|
+
function validHostname(value) {
|
|
337
|
+
// credit: https://github.com/miguelmota/is-valid-hostname/blob/master/index.js
|
|
338
|
+
if (typeof value !== 'string') return false
|
|
339
|
+
|
|
340
|
+
const validHostnameChars = /^[a-zA-Z0-9-.]{1,253}\.?$/g
|
|
341
|
+
if (!validHostnameChars.test(value)) {
|
|
342
|
+
return false
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (value.endsWith('.')) {
|
|
346
|
+
value = value.slice(0, value.length - 1)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (value.length > 253) {
|
|
350
|
+
return false
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const labels = value.split('.')
|
|
354
|
+
|
|
355
|
+
const isValid = labels.every(function (label) {
|
|
356
|
+
const validLabelChars = /^([a-zA-Z0-9-]+)$/g
|
|
357
|
+
|
|
358
|
+
const validLabel = (
|
|
359
|
+
validLabelChars.test(label) &&
|
|
360
|
+
label.length < 64 &&
|
|
361
|
+
!label.startsWith('-') &&
|
|
362
|
+
!label.endsWith('-')
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
return validLabel
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
return isValid
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function validHostname2(domainName) {
|
|
337
372
|
var domainNameRegex = /^(?:[a-z0-9](?:[a-z0-9_\-]{0,61}[a-z0-9])?\.){0,126}(?:[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9]))\.?$/i
|
|
338
373
|
if (!domainName || typeof domainName!=='string') return false
|
|
339
374
|
// is an ip host
|
|
@@ -472,6 +507,7 @@ module.exports = {
|
|
|
472
507
|
validHPassword,
|
|
473
508
|
validEmail,
|
|
474
509
|
validHostname,
|
|
510
|
+
validHostname2,
|
|
475
511
|
validIp,validIpNative,
|
|
476
512
|
validUUID4,
|
|
477
513
|
getTemp,
|