mybase 1.0.41 → 1.0.43

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 +2 -1
  2. package/mybase.js +13 -3
  3. package/package.json +2 -1
package/README.md CHANGED
@@ -18,6 +18,7 @@ var { isLocal } = require('mybase')
18
18
  ### getTemp(filename=false) // returns temp directory of current OS, optionally appends a filename to it
19
19
  ### softexit(message=false,seconds=60,exitcode=-1)
20
20
  ### validHPassword(hpassword)
21
+ ### randomHPassword(length=10)
21
22
  ### validIp(ip)
22
23
  ### validTime(t)
23
24
  ### randomIP()
@@ -36,7 +37,7 @@ var { isLocal } = require('mybase')
36
37
  ### Geoip2Paths() : boolean | object
37
38
  ### arrayRandomItem(array,defaultValue=false)
38
39
  ### maxmindOpen(geoipFile) : <Promise>
39
-
40
+ ### utcnow():int
40
41
  ## Encryption
41
42
  ### decryptAES_CBC_NOIV(encryptedHex, encryptionKey)
42
43
  ### encryptAES_CBC_NOIV(plainString, encryptionKey)
package/mybase.js CHANGED
@@ -3,13 +3,14 @@ const debug = require('debug')('mybase')
3
3
  const os = require('os')
4
4
  const fs = require('fs')
5
5
  const path = require('path')
6
-
7
6
  const net = require('net')
8
7
  const chalk = require('chalk')
9
8
  const punycode = require('punycode');
10
9
  const _validURL = require('@7c/validurl')
11
10
  const { match } = require('assert');
12
11
  const validator = require('validator')
12
+ const sha512 = require('js-sha512')
13
+
13
14
 
14
15
  Date.prototype.yyyymmdd = function() {
15
16
  var mm = this.getMonth() + 1; // getMonth() is zero-based
@@ -22,7 +23,10 @@ Date.prototype.yyyymmdd = function() {
22
23
  };
23
24
 
24
25
  function validHPassword(hpassword) { return (hpassword && hpassword.length === 128 && hpassword.search(/^[a-f0-9]+$/) == 0) }
25
-
26
+ function randomHPassword(length=10) {
27
+ let plain = randomString(length)
28
+ return sha512(plain)
29
+ }
26
30
  function validEmail_old(email) { return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) }
27
31
 
28
32
  function validEmail(email) {
@@ -44,6 +48,10 @@ function arrayRandomItem(arry,defaultValue=false) {
44
48
  return defaultValue
45
49
  }
46
50
 
51
+ function utcnow() {
52
+ return Math.floor(Date.now() / 1000)
53
+ }
54
+
47
55
  function validIp(str) {
48
56
  if (str && typeof str==='string') {
49
57
  let splitted
@@ -599,5 +607,7 @@ module.exports = {
599
607
  ensureProperty,
600
608
  arrayRandomItem,
601
609
  promiseTimeout,
602
- Geoip2Paths
610
+ utcnow,
611
+ Geoip2Paths,
612
+ randomHPassword
603
613
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mybase",
3
- "version": "1.0.41",
3
+ "version": "1.0.43",
4
4
  "description": "",
5
5
  "main": "mybase.js",
6
6
  "scripts": {
@@ -13,6 +13,7 @@
13
13
  "aes-js": "^3.1.2",
14
14
  "chalk": "^3.0.0",
15
15
  "debug": "^4.3.1",
16
+ "js-sha512": "^0.8.0",
16
17
  "punycode": "^2.1.1",
17
18
  "validator": "^13.7.0"
18
19
  },