mybase 1.0.35 → 1.0.36

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/mybase.js +8 -1
  3. package/package.json +1 -1
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
@@ -30,6 +30,12 @@ function validEmail(email) {
30
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)
31
31
  }
32
32
 
33
+ function arrayRandomItem(arry,defaultValue=false) {
34
+ if (Array.isArray(arry)) {
35
+ return arry[Math.floor(Math.random()*arry.length)]
36
+ }
37
+ return defaultValue
38
+ }
33
39
 
34
40
  function validIp(str) {
35
41
  if (str && typeof str==='string') {
@@ -523,5 +529,6 @@ module.exports = {
523
529
  isMochaRunning,
524
530
  portCheck_tcp,
525
531
  asJSON,
526
- ensureProperty
532
+ ensureProperty,
533
+ arrayRandomItem
527
534
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mybase",
3
- "version": "1.0.35",
3
+ "version": "1.0.36",
4
4
  "description": "",
5
5
  "main": "mybase.js",
6
6
  "scripts": {