@qingfu/core-env 0.2.6 → 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/socket.js CHANGED
@@ -24,8 +24,9 @@ if ( TRANSFORMER ) {
24
24
  primus.on( 'connection', spark => {
25
25
  spark.on( 'data', ( data = {} ) => {
26
26
  if ([ 'join', 'leave' ].includes( data.action )) {
27
- let room = _.isArray( data.rooms ) && data.rooms.join( ' ' ) ||
28
- _.isString( data.rooms ) && data.rooms.trim() || data.room;
27
+ let room = data.rooms || data.room;
28
+ room = _.isArray( room ) && room.join( ' ' ) ||
29
+ _.isString( room ) && room.trim() || room;
29
30
  if ( room ) spark[ data.action ]( room );
30
31
  }
31
32
  });
@@ -39,8 +40,9 @@ if ( TRANSFORMER ) {
39
40
  name: 'primus',
40
41
  events: {
41
42
  'websocket'( data ) {
42
- let room = _.isArray( data.rooms ) && data.rooms.join( ' ' ) ||
43
- _.isString( data.rooms ) && data.rooms || data.room;
43
+ let room = data.rooms || data.room;
44
+ room = _.isArray( room ) && room.join( ' ' ) ||
45
+ _.isString( room ) && room.trim() || room;
44
46
  if ( room ) primus.room( room ).write( data );
45
47
  }
46
48
  }
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
- let set = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
89
- return _.times( length || 20, n => _.sample( set )).join( '' );
95
+ return _.times( length || 20, n => _.sample( humanReadable )).join( '' );
90
96
  };
91
97
 
92
- utils.generateCode = length => {
93
- let set = '0123456789';
94
- return _.times( length || 6, n => _.sample( set )).join( '' );
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.6",
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.0",
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.0",
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",