@qingfu/core-env 0.2.7 → 0.2.8
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/lib/utils.js +15 -5
- package/package.json +4 -3
package/lib/utils.js
CHANGED
|
@@ -3,6 +3,7 @@ const _ = require( 'lodash' );
|
|
|
3
3
|
const crypto = require( 'crypto' );
|
|
4
4
|
const xml2js = require( 'xml2js' );
|
|
5
5
|
const xlsx = require( 'xlsx' );
|
|
6
|
+
const baseX = require( 'base-x' );
|
|
6
7
|
const pinyin = require( 'pinyin' );
|
|
7
8
|
const qrcode = require( 'qr-image' );
|
|
8
9
|
const request = require( 'superagent' );
|
|
@@ -84,14 +85,23 @@ utils.xlsx2json = ( buffer, mapping ) => {
|
|
|
84
85
|
})};
|
|
85
86
|
};
|
|
86
87
|
|
|
88
|
+
const pureNumbers = '0123456789';
|
|
89
|
+
utils.generateCode = length => {
|
|
90
|
+
return _.times( length || 6, n => _.sample( pureNumbers )).join( '' );
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const humanReadable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
87
94
|
utils.generateSalt = length => {
|
|
88
|
-
|
|
89
|
-
return _.times( length || 20, n => _.sample( set )).join( '' );
|
|
95
|
+
return _.times( length || 20, n => _.sample( humanReadable )).join( '' );
|
|
90
96
|
};
|
|
91
97
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return
|
|
98
|
+
const base62 = baseX( humanReadable );
|
|
99
|
+
utils.hexToBase62 = string => {
|
|
100
|
+
return base62.encode( Buffer.from( string, 'hex' ));
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
utils.base62ToHex = string => {
|
|
104
|
+
return Buffer.from( base62.decode( string )).toString( 'hex' );
|
|
95
105
|
};
|
|
96
106
|
|
|
97
107
|
utils.generateHash = ( string, algorithm = 'md5', encoding = 'hex' ) => {
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qingfu/core-env",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"readmeFilename": "README.md",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@koa/cors": "4.0.0",
|
|
7
7
|
"@koa/router": "12.0.0",
|
|
8
|
+
"base-x": "4.0.0",
|
|
8
9
|
"bull": "4.10.4",
|
|
9
10
|
"busboy": "1.6.0",
|
|
10
11
|
"cookie": "0.5.0",
|
|
@@ -13,7 +14,7 @@
|
|
|
13
14
|
"ioredis": "4.28.5",
|
|
14
15
|
"jsonwebtoken": "9.0.0",
|
|
15
16
|
"koa": "2.14.2",
|
|
16
|
-
"koa-bodyparser": "4.4.
|
|
17
|
+
"koa-bodyparser": "4.4.1",
|
|
17
18
|
"koa-favicon": "2.1.0",
|
|
18
19
|
"koa-helmet": "7.0.2",
|
|
19
20
|
"koa-logger": "3.2.1",
|
|
@@ -21,7 +22,7 @@
|
|
|
21
22
|
"koa-qs": "3.0.0",
|
|
22
23
|
"lodash": "4.17.21",
|
|
23
24
|
"moleculer": "0.14.29",
|
|
24
|
-
"mongoose": "7.3.
|
|
25
|
+
"mongoose": "7.3.1",
|
|
25
26
|
"mongoose-cast-aggregation": "0.3.1",
|
|
26
27
|
"mongoose-geojson-schema": "2.2.4",
|
|
27
28
|
"mongoose-lean-defaults": "2.2.1",
|