mybase 1.0.35 → 1.0.38
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 -1
- package/mybase.js +13 -2
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ var { isLocal } = require('mybase')
|
|
|
34
34
|
### ip2int(), int2ip()
|
|
35
35
|
### ensureProperty(obj,'tier.tier',defaultValue)
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
### arrayRandomItem(array,defaultValue=false)
|
|
38
38
|
### maxmindOpen(geoipFile) : <Promise>
|
|
39
39
|
```
|
|
40
40
|
var handle = await maxmindOpen(config.geoip.country)
|
package/mybase.js
CHANGED
|
@@ -6,7 +6,7 @@ const chalk = require('chalk')
|
|
|
6
6
|
const punycode = require('punycode');
|
|
7
7
|
const _validURL = require('@7c/validurl')
|
|
8
8
|
const { match } = require('assert');
|
|
9
|
-
|
|
9
|
+
const validator = require('validator')
|
|
10
10
|
|
|
11
11
|
Date.prototype.yyyymmdd = function() {
|
|
12
12
|
var mm = this.getMonth() + 1; // getMonth() is zero-based
|
|
@@ -23,6 +23,10 @@ function validHPassword(hpassword) { return (hpassword && hpassword.length === 1
|
|
|
23
23
|
function validEmail_old(email) { return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) }
|
|
24
24
|
|
|
25
25
|
function validEmail(email) {
|
|
26
|
+
if (typeof email==='string')
|
|
27
|
+
return validator.isEmail(email) // validator needs a string
|
|
28
|
+
return false
|
|
29
|
+
// giving up old style, was not reliable
|
|
26
30
|
// taken from https://www.w3resource.com/javascript/form/email-validation.php
|
|
27
31
|
// strange looking emails might be indeed valid
|
|
28
32
|
// check https://www.w3resource.com/javascript/form/example-javascript-form-validation-email-REC-2822.html
|
|
@@ -30,6 +34,12 @@ function validEmail(email) {
|
|
|
30
34
|
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)
|
|
31
35
|
}
|
|
32
36
|
|
|
37
|
+
function arrayRandomItem(arry,defaultValue=false) {
|
|
38
|
+
if (Array.isArray(arry)) {
|
|
39
|
+
return arry[Math.floor(Math.random()*arry.length)]
|
|
40
|
+
}
|
|
41
|
+
return defaultValue
|
|
42
|
+
}
|
|
33
43
|
|
|
34
44
|
function validIp(str) {
|
|
35
45
|
if (str && typeof str==='string') {
|
|
@@ -523,5 +533,6 @@ module.exports = {
|
|
|
523
533
|
isMochaRunning,
|
|
524
534
|
portCheck_tcp,
|
|
525
535
|
asJSON,
|
|
526
|
-
ensureProperty
|
|
536
|
+
ensureProperty,
|
|
537
|
+
arrayRandomItem
|
|
527
538
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mybase",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.38",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "mybase.js",
|
|
6
6
|
"scripts": {
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"@7c/validurl": "0.0.3",
|
|
13
13
|
"chalk": "^3.0.0",
|
|
14
14
|
"debug": "^4.3.1",
|
|
15
|
-
"punycode": "^2.1.1"
|
|
15
|
+
"punycode": "^2.1.1",
|
|
16
|
+
"validator": "^13.7.0"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
18
19
|
"chai": "^4.2.0",
|