@qingfu/core-env 0.2.7 → 0.2.9

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 (2) hide show
  1. package/lib/utils.js +18 -7
  2. 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' );
@@ -49,9 +50,10 @@ utils.json2xlsx = ( json, mapping, type ) => {
49
50
  };
50
51
 
51
52
  utils.xlsx2json = ( buffer, mapping ) => {
52
- let workbook = xlsx.read( buffer, { type: 'buffer', cellDates: true });
53
+ let type = _.isString( buffer ) ? 'string' : 'buffer';
54
+ let workbook = xlsx.read( buffer, { type, cellDates: true });
53
55
  let worksheet = workbook.Sheets[ workbook.SheetNames[ 0 ]];
54
- let date1904 = workbook.Workbook.WBProps.date1904;
56
+ let date1904 = _.get( workbook, 'Workbook.WBProps.date1904' );
55
57
  function fixImportedDate( date, date1904 ) {
56
58
  let basedate = new Date( 1899, 11, 30, 0, 0, 0 );
57
59
  let dnthresh = basedate.getTime() + ( new Date().getTimezoneOffset() - basedate.getTimezoneOffset() ) * 60000;
@@ -84,14 +86,23 @@ utils.xlsx2json = ( buffer, mapping ) => {
84
86
  })};
85
87
  };
86
88
 
89
+ const pureNumbers = '0123456789';
90
+ utils.generateCode = length => {
91
+ return _.times( length || 6, n => _.sample( pureNumbers )).join( '' );
92
+ };
93
+
94
+ const humanReadable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
87
95
  utils.generateSalt = length => {
88
- let set = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
89
- return _.times( length || 20, n => _.sample( set )).join( '' );
96
+ return _.times( length || 20, n => _.sample( humanReadable )).join( '' );
90
97
  };
91
98
 
92
- utils.generateCode = length => {
93
- let set = '0123456789';
94
- return _.times( length || 6, n => _.sample( set )).join( '' );
99
+ const base62 = baseX( humanReadable );
100
+ utils.hexToBase62 = string => {
101
+ return base62.encode( Buffer.from( string, 'hex' ));
102
+ };
103
+
104
+ utils.base62ToHex = string => {
105
+ return Buffer.from( base62.decode( string )).toString( 'hex' );
95
106
  };
96
107
 
97
108
  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.7",
3
+ "version": "0.2.9",
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",