@qingfu/core-env 0.1.4 → 0.1.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.
Files changed (2) hide show
  1. package/lib/utils.js +11 -1
  2. package/package.json +1 -1
package/lib/utils.js CHANGED
@@ -17,6 +17,10 @@ utils.json2xml = json => {
17
17
  return builder.buildObject( json );
18
18
  };
19
19
 
20
+ utils.trimZeroWidthSpace = string => {
21
+ return _.isString( string ) ? string.trim().replace( /[\uFEFF\u0001\u200b-\u200f\u202a-\u202e]/g, '' ) : string;
22
+ };
23
+
20
24
  utils.json2xlsx = ( json, mapping, type = 'xlsx' ) => {
21
25
  let data = json.map( obj => mapping.map( v => {
22
26
  let value = v.value ? v.value( obj ) : _.get( obj, v.field );
@@ -56,7 +60,7 @@ utils.xlsx2json = ( buffer, mapping ) => {
56
60
  return _.transform( mapping, ( r, map ) => {
57
61
  if ( map.index === -1 ) return;
58
62
  let value = values[ map.index ];
59
- if ( _.isString( value )) value = value.trim().replace( /\u200B/g, '' );
63
+ if ( _.isString( value )) value = utils.trimZeroWidthSpace( value );
60
64
  else if ( value instanceof Date ) value = fixImportedDate( value, date1904 );
61
65
  r[ map.field ] = ( map.format || _.identity )( value );
62
66
  }, {});
@@ -129,6 +133,12 @@ utils.paramsToSign = ( params, head, identity = _.identity ) => {
129
133
  }
130
134
  };
131
135
 
136
+ utils.emailFormat = function( string ) {
137
+ let regex = /([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi;
138
+ let emails = ( string || '' ).match( regex );
139
+ return emails && emails.join( ', ' );
140
+ };
141
+
132
142
  utils.dateFormat = Date.prototype.format = function( fmt = 'yyyy-MM-dd' ) {
133
143
  let o = {
134
144
  'M+': this.getMonth() + 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qingfu/core-env",
3
- "version": "0.1.4",
3
+ "version": "0.1.8",
4
4
  "readmeFilename": "README.md",
5
5
  "dependencies": {
6
6
  "@koa/cors": "3.1.0",