lgutils 1.2.32 → 1.3.5

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/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  export declare const accAdd: (arg1: number, arg2: number) => number;
3
2
 
4
3
  export declare const accDiv: (arg1: number, arg2: number) => number;
@@ -13,7 +12,7 @@ export declare const DATE_FORMAT = "YYYY/MM/DD";
13
12
 
14
13
  export declare function digitCnUppercase(n: number): string;
15
14
 
16
- export declare const download: (data: string, strFileName?: string, strMimeType?: string, isImgUrl?: boolean | undefined) => boolean | undefined;
15
+ export declare const download: (data: string, strFileName?: string, strMimeType?: string, isImgUrl?: boolean | undefined) => true | undefined;
17
16
 
18
17
  export declare const fileReaderToBase64: (target: any) => (cb: (p: any) => void) => void;
19
18
 
@@ -89,8 +88,12 @@ export declare const isArray: (value: any) => boolean;
89
88
 
90
89
  export declare const isBlob: (value: any) => any;
91
90
 
91
+ export declare const isCardNo: (cardNum: any) => boolean;
92
+
92
93
  export declare const isDate: (value: any) => boolean;
93
94
 
95
+ export declare const isEmail: (emailStr: string) => boolean;
96
+
94
97
  export declare const isFile: (value: any) => any;
95
98
 
96
99
  export declare const isNil: (val: any) => val is NIL;
@@ -99,6 +102,10 @@ export declare const isNull: (value: any) => boolean;
99
102
 
100
103
  export declare const isObject: (value: any) => boolean;
101
104
 
105
+ export declare const isPhone: (phone: any) => boolean;
106
+
107
+ export declare const isSMSCode: (code: any) => any;
108
+
102
109
  export declare const isUndefined: (value: any) => boolean;
103
110
 
104
111
  export declare const log: (...rest: any) => void;
@@ -21,6 +21,20 @@ const inBrowser = typeof window !== 'undefined';
21
21
  const trimString = (str) => {
22
22
  return str.replace(/(^\s*)|(\s*$)/g, '');
23
23
  };
24
+ const isEmail = (emailStr) => {
25
+ const emailPat = /^(.+)@(.+)\.(.+)$/;
26
+ return emailPat.test(emailStr);
27
+ };
28
+ const isCardNo = (cardNum) => {
29
+ const cardPat = /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/;
30
+ return cardPat.test(cardNum);
31
+ };
32
+ const isPhone = (phone) => {
33
+ return /^[1](\d{10})$/.test(phone);
34
+ };
35
+ const isSMSCode = (code) => {
36
+ return code.match(/^\d{6}$/);
37
+ };
24
38
  const random = (min, max) => Math.round(Math.random() * (max - min) + min);
25
39
  const playAudio = (mp3Id) => {
26
40
  const audioArr = document.querySelectorAll('audio');
@@ -247,13 +261,10 @@ function normalizeFormValues(values) {
247
261
  }
248
262
  function normalizeSearchParams(params) {
249
263
  if (params.startDate || params.endDate) {
250
- params = {
251
- ...omit__default(params, ['startDate', 'endDate']),
252
- dateRange: [
264
+ params = Object.assign(Object.assign({}, omit__default(params, ['startDate', 'endDate'])), { dateRange: [
253
265
  params.startDate && moment__default(params.startDate),
254
266
  params.endDate && moment__default(params.endDate)
255
- ]
256
- };
267
+ ] });
257
268
  }
258
269
  Object.entries(params).forEach(([key, value]) => {
259
270
  if (typeof value === 'string' && value.includes(',')) {
@@ -343,20 +354,19 @@ const download = (data, strFileName = 'download', strMimeType = 'application/oct
343
354
  const fn = strFileName;
344
355
  let blob = null;
345
356
  let fr = null;
346
- const d2b = (u) => {
347
- const p = u.split(/[:;,]/);
348
- const t = p[1];
349
- const dec = p[2] === 'base64' ? atob : decodeURIComponent;
350
- const bin = dec(p.pop());
351
- const mx = bin.length;
352
- let i = 0;
353
- const uia = new Uint8Array(mx);
354
- for (i; i < mx; ++i)
355
- uia[i] = bin.charCodeAt(i);
356
- return new B([uia], {
357
- type: t
358
- });
359
- };
357
+ // const d2b = (u: any) => {
358
+ // const p = u.split(/[:;,]/)
359
+ // const t = p[1]
360
+ // const dec = p[2] === 'base64' ? atob : decodeURIComponent
361
+ // const bin = dec(p.pop())
362
+ // const mx = bin.length
363
+ // let i = 0
364
+ // const uia = new Uint8Array(mx)
365
+ // for (i; i < mx; ++i) uia[i] = bin.charCodeAt(i)
366
+ // return new B([uia], {
367
+ // type: t
368
+ // })
369
+ // }
360
370
  const saver = (url, winMode) => {
361
371
  if ('download' in a) {
362
372
  // html5 A[download]
@@ -394,9 +404,10 @@ const download = (data, strFileName = 'download', strMimeType = 'application/oct
394
404
  // }
395
405
  // go ahead and download dataURLs right away
396
406
  if (String(x).match(/^data\:[\w+\-]+\/[\w+\-]+[,;]/)) {
397
- return navigator.msSaveBlob // IE10 can't do a[download], only Blobs:
398
- ? navigator.msSaveBlob(d2b(x), fn)
399
- : saver(x); // everyone else can save dataURLs un-processed
407
+ return saver(x);
408
+ // return navigator?.msSaveBlob // IE10 can't do a[download], only Blobs:
409
+ // ? navigator?.msSaveBlob(d2b(x), fn)
410
+ // : saver(x) // everyone else can save dataURLs un-processed
400
411
  } // end if dataURL passed?
401
412
  try {
402
413
  blob =
@@ -413,10 +424,10 @@ const download = (data, strFileName = 'download', strMimeType = 'application/oct
413
424
  // blob = b.getBlob(m); // the blob
414
425
  // }
415
426
  }
416
- if (navigator.msSaveBlob) {
417
- // IE10+ : (has Blob, but not a[download] or URL)
418
- return navigator.msSaveBlob(blob, fn);
419
- }
427
+ // if (navigator.msSaveBlob) {
428
+ // // IE10+ : (has Blob, but not a[download] or URL)
429
+ // return navigator.msSaveBlob(blob, fn)
430
+ // }
420
431
  if (self.URL) {
421
432
  // simple fast and modern way using Blob and URL:
422
433
  // saver(self.URL.createObjectURL(blob), true);
@@ -477,11 +488,15 @@ exports.getValueWithNil = getValueWithNil;
477
488
  exports.inBrowser = inBrowser;
478
489
  exports.isArray = isArray;
479
490
  exports.isBlob = isBlob;
491
+ exports.isCardNo = isCardNo;
480
492
  exports.isDate = isDate;
493
+ exports.isEmail = isEmail;
481
494
  exports.isFile = isFile;
482
495
  exports.isNil = isNil;
483
496
  exports.isNull = isNull;
484
497
  exports.isObject = isObject;
498
+ exports.isPhone = isPhone;
499
+ exports.isSMSCode = isSMSCode;
485
500
  exports.isUndefined = isUndefined;
486
501
  exports.log = log;
487
502
  exports.normalizeFormValues = normalizeFormValues;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("qs"),e=require("d3-format"),r=require("lodash/omit"),o=require("moment");function a(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var n=a(r),s=a(o);const i="undefined"!=typeof window,l=t=>t&&"number"==typeof t.size&&"string"==typeof t.type&&"function"==typeof t.slice,c=i?localStorage:{};let p={};const d=e.format(",.2f"),u=e.format(","),m=e.format(".2%"),f=g(d),h=g(u),x=g(m);function g(t){return e=>w(e)?S:t(e)}const y=t=>d(t/1e4),M=g(y),b=(D="增信",function(t){return t?D:"不"+D});var D;const w=t=>null==t||""===t,S="——";function Y(t,e="YYYY-MM-DD"){return s(new Date(t)).format(e)}const A=g(Y),v={d:"天",m:"个月",y:"年"};function R(t){return t?`${parseInt(t,10)}${v[t.slice(-1).toLowerCase()]}`:t}const N=g(R);exports.DATE_FORMAT="YYYY/MM/DD",exports.FORMAT_DATE="YYYY-MM-DD",exports.FORMAT_TIME="YYYY-MM-DD HH:mm:ss",exports.NIL_STRING=S,exports.accAdd=(t,e)=>{let r,o,a;try{r=t.toString().split(".")[1].length}catch(n){r=0}try{o=e.toString().split(".")[1].length}catch(n){o=0}return a=Math.pow(10,Math.max(r,o)),(t*a+e*a)/a},exports.accDiv=(t,e)=>{let r,o,a=0,n=0;try{a=t.toString().split(".")[1].length}catch(s){}try{n=e.toString().split(".")[1].length}catch(s){}return r=Number(t.toString().replace(".","")),o=Number(e.toString().replace(".","")),r/o*Math.pow(10,n-a)},exports.accMul=(t,e)=>{let r=0,o=t.toString(),a=e.toString();try{r+=o.split(".")[1].length}catch(n){}try{r+=a.split(".")[1].length}catch(n){}return Number(o.replace(".",""))*Number(a.replace(".",""))/Math.pow(10,r)},exports.accSub=function(t,e){let r,o,a,n;try{r=t.toString().split(".")[1].length}catch(s){r=0}try{o=e.toString().split(".")[1].length}catch(s){o=0}return a=Math.pow(10,Math.max(r,o)),n=r>=o?r:o,((t*a-e*a)/a).toFixed(n)},exports.cutTimeFn=t=>`00‘${0===t?"00":"0"+Math.floor(t/60)}’${0===t?"00":t%60>=10?t%60:"0"+t%60}`,exports.digitCnUppercase=function(t){var e=["角","分"],r=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],o=[["元","万","亿"],["","拾","佰","仟"]],a=t<0?"欠":"";t=Math.abs(t);for(var n="",s=0;s<e.length;s++)n+=(r[Math.floor(10*t*Math.pow(10,s))%10]+e[s]).replace(/零./,"");for(n=n||"整",t=Math.floor(t),s=0;s<o[0].length&&t>0;s++){for(var i="",l=0;l<o[1].length&&t>0;l++)i=r[t%10]+o[1][l]+i,t=Math.floor(t/10);n=i.replace(/(零.)*零$/,"").replace(/^$/,"零")+o[0][s]+n}return a+n.replace(/(零.)*零元/,"元").replace(/(零.)+/g,"零").replace(/^整$/,"零元整")},exports.download=(t,e="download",r="application/octet-stream",o)=>{const a=window;let n=r,s=t;const i=document,l=i.createElement("a"),c=t=>String(t),p=a.Blob||c(l),d=e;let u=null,m=null;const f=(e,r)=>{if("download"in l)return l.href=o?t:e,l.setAttribute("download",d),l.innerHTML="downloading...",i.body.appendChild(l),setTimeout((()=>{l.click(),i.body.removeChild(l),!0===r&&setTimeout((()=>{a.URL.revokeObjectURL(l.href)}),250)}),66),!0;const n=i.createElement("iframe");i.body.appendChild(n),r||(e="data:"+e.replace(/^data:([\w\/\-\+]+)/,"application/octet-stream")),n.src=e,setTimeout((()=>{i.body.removeChild(n)}),333)};if(String(s).match(/^data\:[\w+\-]+\/[\w+\-]+[,;]/))return navigator.msSaveBlob?navigator.msSaveBlob((t=>{const e=t.split(/[:;,]/),r=e[1],o=("base64"===e[2]?atob:decodeURIComponent)(e.pop()),a=o.length;let n=0;const s=new Uint8Array(a);for(;n<a;++n)s[n]=o.charCodeAt(n);return new p([s],{type:r})})(s),d):f(s);try{u=s instanceof p?s:new p([s],{type:n})}catch(h){}if(navigator.msSaveBlob)return navigator.msSaveBlob(u,d);if(a.URL)f(a.URL.createObjectURL(u),!0);else{if("string"==typeof u||u.constructor===c(l))try{return f("data:"+n+";base64,"+a.btoa(u))}catch(h){return f("data:"+n+","+encodeURIComponent(u))}m=new FileReader,m.onload=function(){f(this.result)},m.readAsDataURL(u)}return!0},exports.fileReaderToBase64=t=>e=>{const r=new FileReader;r.onload=t=>{e&&e(t.target.result)},r.readAsDataURL(t)},exports.format10k=y,exports.format10kNil=M,exports.formatCash=d,exports.formatCash2=t=>(Math.floor(100*t)/100).toFixed(2),exports.formatCashInt=u,exports.formatCashIntNil=h,exports.formatCashNil=f,exports.formatCreditEnhanced=b,exports.formatDate=Y,exports.formatDateNil=A,exports.formatDuration=R,exports.formatDurationNil=N,exports.formatRatio=m,exports.formatRatioNil=x,exports.getBase64=t=>new Promise(((e,r)=>{const o=new FileReader;o.readAsDataURL(t),o.onload=()=>e(o.result),o.onerror=t=>r(t)})),exports.getItem=t=>((p[t]||c.getItem(""+t))&&(p[t]=JSON.parse(c.getItem(""+t)||"null")),p[t]),exports.getQueryObject=(e=window.location.href)=>{const r=e.split("?")[1];return t.parse(r||"")},exports.getSearchParams=t=>new URLSearchParams(t),exports.getValOfArr=t=>{const e=t.length,r=t.reduce(((t,e)=>t+e),0),o=t.reduce(((t,e)=>t*e),1);return{min:Math.min.apply(null,t),max:Math.max.apply(null,t),sum:r,average:r/e,mull:o}},exports.getValueWithNil=t=>w(t)?S:t,exports.inBrowser=i,exports.isArray=t=>Array.isArray(t),exports.isBlob=l,exports.isDate=t=>t instanceof Date,exports.isFile=t=>l(t)&&"string"==typeof t.name&&("object"==typeof t.lastModifiedDate||"number"==typeof t.lastModified),exports.isNil=w,exports.isNull=t=>null===t,exports.isObject=t=>t===Object(t),exports.isUndefined=t=>void 0===t,exports.log=(...t)=>{console.group("====================="),console.info(...t),console.groupEnd()},exports.normalizeFormValues=function(t){return Object.entries(t).filter((([t,e])=>void 0!==e&&"all"!==e)).reduce(((t,[e,r])=>(Array.isArray(r)&&r.some((t=>s.isMoment(t)))?(r[0]&&(t.startDate=r[0].format("YYYY-MM-DD")),r[1]&&(t.endDate=r[1].format("YYYY-MM-DD"))):t[e]=s.isMoment(r)?r.format("YYYY-MM-DD"):r,t)),{})},exports.normalizeSearchParams=function(t){return(t.startDate||t.endDate)&&(t={...n(t,["startDate","endDate"]),dateRange:[t.startDate&&s(t.startDate),t.endDate&&s(t.endDate)]}),Object.entries(t).forEach((([e,r])=>{"string"==typeof r&&r.includes(",")&&(t[e]="all")})),t},exports.os=()=>{if(!i)return{isTablet:!1,isPhone:!1,isAndroid:!1,isPc:!1};const t=navigator.userAgent,e=/(?:Windows Phone)/.test(t),r=/(?:SymbianOS)/.test(t)||e,o=/(?:Android)/.test(t),a=/(?:Firefox)/.test(t),n=/(?:iPad|PlayBook)/.test(t)||o&&!/(?:Mobile)/.test(t)||a&&/(?:Tablet)/.test(t),s=/(?:iPhone)/.test(t)&&!n;return{isTablet:n,isPhone:s,isAndroid:o,isPc:!s&&!o&&!r}},exports.playAudio=t=>{const e=document.querySelectorAll("audio");Array.from(e).forEach((t=>{t.pause(),t.currentTime=0})),document.querySelector(`#${t}`).play()},exports.random=(t,e)=>Math.round(Math.random()*(e-t)+t),exports.randomString=(t=32)=>{const e="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",r=e.length;let o="";for(let a=0;a<t;a++)o+=e.charAt(Math.floor(Math.random()*r));return o},exports.removeAll=()=>(p={},c.clear()),exports.removeItem=t=>(delete p[t],c.removeItem(""+t)),exports.setItem=(t,e)=>(p[t]=e,c.setItem(""+t,JSON.stringify(e))),exports.setProxyObj=(t,e,r)=>new Proxy(t,{get:(t,r)=>(e(),Reflect.get(t,r)),set:(t,e,o)=>(r(),Reflect.set(t,e,o))}),exports.sortObj=(t,e,r="asc")=>t.sort(((t,o)=>"asc"===r?o[e]-t[e]:t[e]-o[e])),exports.sumObj=(t,e)=>t.reduce(((t,r)=>r[e]+t),0),exports.trimString=t=>t.replace(/(^\s*)|(\s*$)/g,"");
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("qs"),e=require("d3-format"),r=require("lodash/omit"),o=require("moment");function a(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var s=a(r),n=a(o);const i="undefined"!=typeof window,l=t=>t&&"number"==typeof t.size&&"string"==typeof t.type&&"function"==typeof t.slice,c=i?localStorage:{};let p={};const d=e.format(",.2f"),u=e.format(","),m=e.format(".2%"),f=g(d),h=g(u),x=g(m);function g(t){return e=>w(e)?S:t(e)}const y=t=>d(t/1e4),M=g(y),D=(b="增信",function(t){return t?b:"不"+b});var b;const w=t=>null==t||""===t,S="——";function Y(t,e="YYYY-MM-DD"){return n(new Date(t)).format(e)}const A=g(Y),R={d:"天",m:"个月",y:"年"};function O(t){return t?`${parseInt(t,10)}${R[t.slice(-1).toLowerCase()]}`:t}const N=g(O);exports.DATE_FORMAT="YYYY/MM/DD",exports.FORMAT_DATE="YYYY-MM-DD",exports.FORMAT_TIME="YYYY-MM-DD HH:mm:ss",exports.NIL_STRING=S,exports.accAdd=(t,e)=>{let r,o,a;try{r=t.toString().split(".")[1].length}catch(s){r=0}try{o=e.toString().split(".")[1].length}catch(s){o=0}return a=Math.pow(10,Math.max(r,o)),(t*a+e*a)/a},exports.accDiv=(t,e)=>{let r,o,a=0,s=0;try{a=t.toString().split(".")[1].length}catch(n){}try{s=e.toString().split(".")[1].length}catch(n){}return r=Number(t.toString().replace(".","")),o=Number(e.toString().replace(".","")),r/o*Math.pow(10,s-a)},exports.accMul=(t,e)=>{let r=0,o=t.toString(),a=e.toString();try{r+=o.split(".")[1].length}catch(s){}try{r+=a.split(".")[1].length}catch(s){}return Number(o.replace(".",""))*Number(a.replace(".",""))/Math.pow(10,r)},exports.accSub=function(t,e){let r,o,a,s;try{r=t.toString().split(".")[1].length}catch(n){r=0}try{o=e.toString().split(".")[1].length}catch(n){o=0}return a=Math.pow(10,Math.max(r,o)),s=r>=o?r:o,((t*a-e*a)/a).toFixed(s)},exports.cutTimeFn=t=>`00‘${0===t?"00":"0"+Math.floor(t/60)}’${0===t?"00":t%60>=10?t%60:"0"+t%60}`,exports.digitCnUppercase=function(t){var e=["角","分"],r=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],o=[["元","万","亿"],["","拾","佰","仟"]],a=t<0?"欠":"";t=Math.abs(t);for(var s="",n=0;n<e.length;n++)s+=(r[Math.floor(10*t*Math.pow(10,n))%10]+e[n]).replace(/零./,"");for(s=s||"整",t=Math.floor(t),n=0;n<o[0].length&&t>0;n++){for(var i="",l=0;l<o[1].length&&t>0;l++)i=r[t%10]+o[1][l]+i,t=Math.floor(t/10);s=i.replace(/(零.)*零$/,"").replace(/^$/,"零")+o[0][n]+s}return a+s.replace(/(零.)*零元/,"元").replace(/(零.)+/g,"零").replace(/^整$/,"零元整")},exports.download=(t,e="download",r="application/octet-stream",o)=>{const a=window;let s=r,n=t;const i=document,l=i.createElement("a"),c=t=>String(t),p=a.Blob||c(l),d=e;let u=null,m=null;const f=(e,r)=>{if("download"in l)return l.href=o?t:e,l.setAttribute("download",d),l.innerHTML="downloading...",i.body.appendChild(l),setTimeout((()=>{l.click(),i.body.removeChild(l),!0===r&&setTimeout((()=>{a.URL.revokeObjectURL(l.href)}),250)}),66),!0;const s=i.createElement("iframe");i.body.appendChild(s),r||(e="data:"+e.replace(/^data:([\w\/\-\+]+)/,"application/octet-stream")),s.src=e,setTimeout((()=>{i.body.removeChild(s)}),333)};if(String(n).match(/^data\:[\w+\-]+\/[\w+\-]+[,;]/))return f(n);try{u=n instanceof p?n:new p([n],{type:s})}catch(h){}if(a.URL)f(a.URL.createObjectURL(u),!0);else{if("string"==typeof u||u.constructor===c(l))try{return f("data:"+s+";base64,"+a.btoa(u))}catch(h){return f("data:"+s+","+encodeURIComponent(u))}m=new FileReader,m.onload=function(){f(this.result)},m.readAsDataURL(u)}return!0},exports.fileReaderToBase64=t=>e=>{const r=new FileReader;r.onload=t=>{e&&e(t.target.result)},r.readAsDataURL(t)},exports.format10k=y,exports.format10kNil=M,exports.formatCash=d,exports.formatCash2=t=>(Math.floor(100*t)/100).toFixed(2),exports.formatCashInt=u,exports.formatCashIntNil=h,exports.formatCashNil=f,exports.formatCreditEnhanced=D,exports.formatDate=Y,exports.formatDateNil=A,exports.formatDuration=O,exports.formatDurationNil=N,exports.formatRatio=m,exports.formatRatioNil=x,exports.getBase64=t=>new Promise(((e,r)=>{const o=new FileReader;o.readAsDataURL(t),o.onload=()=>e(o.result),o.onerror=t=>r(t)})),exports.getItem=t=>((p[t]||c.getItem(""+t))&&(p[t]=JSON.parse(c.getItem(""+t)||"null")),p[t]),exports.getQueryObject=(e=window.location.href)=>{const r=e.split("?")[1];return t.parse(r||"")},exports.getSearchParams=t=>new URLSearchParams(t),exports.getValOfArr=t=>{const e=t.length,r=t.reduce(((t,e)=>t+e),0),o=t.reduce(((t,e)=>t*e),1);return{min:Math.min.apply(null,t),max:Math.max.apply(null,t),sum:r,average:r/e,mull:o}},exports.getValueWithNil=t=>w(t)?S:t,exports.inBrowser=i,exports.isArray=t=>Array.isArray(t),exports.isBlob=l,exports.isCardNo=t=>/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/.test(t),exports.isDate=t=>t instanceof Date,exports.isEmail=t=>/^(.+)@(.+)\.(.+)$/.test(t),exports.isFile=t=>l(t)&&"string"==typeof t.name&&("object"==typeof t.lastModifiedDate||"number"==typeof t.lastModified),exports.isNil=w,exports.isNull=t=>null===t,exports.isObject=t=>t===Object(t),exports.isPhone=t=>/^[1](\d{10})$/.test(t),exports.isSMSCode=t=>t.match(/^\d{6}$/),exports.isUndefined=t=>void 0===t,exports.log=(...t)=>{console.group("====================="),console.info(...t),console.groupEnd()},exports.normalizeFormValues=function(t){return Object.entries(t).filter((([t,e])=>void 0!==e&&"all"!==e)).reduce(((t,[e,r])=>(Array.isArray(r)&&r.some((t=>n.isMoment(t)))?(r[0]&&(t.startDate=r[0].format("YYYY-MM-DD")),r[1]&&(t.endDate=r[1].format("YYYY-MM-DD"))):t[e]=n.isMoment(r)?r.format("YYYY-MM-DD"):r,t)),{})},exports.normalizeSearchParams=function(t){return(t.startDate||t.endDate)&&(t=Object.assign(Object.assign({},s(t,["startDate","endDate"])),{dateRange:[t.startDate&&n(t.startDate),t.endDate&&n(t.endDate)]})),Object.entries(t).forEach((([e,r])=>{"string"==typeof r&&r.includes(",")&&(t[e]="all")})),t},exports.os=()=>{if(!i)return{isTablet:!1,isPhone:!1,isAndroid:!1,isPc:!1};const t=navigator.userAgent,e=/(?:Windows Phone)/.test(t),r=/(?:SymbianOS)/.test(t)||e,o=/(?:Android)/.test(t),a=/(?:Firefox)/.test(t),s=/(?:iPad|PlayBook)/.test(t)||o&&!/(?:Mobile)/.test(t)||a&&/(?:Tablet)/.test(t),n=/(?:iPhone)/.test(t)&&!s;return{isTablet:s,isPhone:n,isAndroid:o,isPc:!n&&!o&&!r}},exports.playAudio=t=>{const e=document.querySelectorAll("audio");Array.from(e).forEach((t=>{t.pause(),t.currentTime=0})),document.querySelector(`#${t}`).play()},exports.random=(t,e)=>Math.round(Math.random()*(e-t)+t),exports.randomString=(t=32)=>{const e="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",r=e.length;let o="";for(let a=0;a<t;a++)o+=e.charAt(Math.floor(Math.random()*r));return o},exports.removeAll=()=>(p={},c.clear()),exports.removeItem=t=>(delete p[t],c.removeItem(""+t)),exports.setItem=(t,e)=>(p[t]=e,c.setItem(""+t,JSON.stringify(e))),exports.setProxyObj=(t,e,r)=>new Proxy(t,{get:(t,r)=>(e(),Reflect.get(t,r)),set:(t,e,o)=>(r(),Reflect.set(t,e,o))}),exports.sortObj=(t,e,r="asc")=>t.sort(((t,o)=>"asc"===r?o[e]-t[e]:t[e]-o[e])),exports.sumObj=(t,e)=>t.reduce(((t,r)=>r[e]+t),0),exports.trimString=t=>t.replace(/(^\s*)|(\s*$)/g,"");
@@ -12,6 +12,20 @@ const inBrowser = typeof window !== 'undefined';
12
12
  const trimString = (str) => {
13
13
  return str.replace(/(^\s*)|(\s*$)/g, '');
14
14
  };
15
+ const isEmail = (emailStr) => {
16
+ const emailPat = /^(.+)@(.+)\.(.+)$/;
17
+ return emailPat.test(emailStr);
18
+ };
19
+ const isCardNo = (cardNum) => {
20
+ const cardPat = /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/;
21
+ return cardPat.test(cardNum);
22
+ };
23
+ const isPhone = (phone) => {
24
+ return /^[1](\d{10})$/.test(phone);
25
+ };
26
+ const isSMSCode = (code) => {
27
+ return code.match(/^\d{6}$/);
28
+ };
15
29
  const random = (min, max) => Math.round(Math.random() * (max - min) + min);
16
30
  const playAudio = (mp3Id) => {
17
31
  const audioArr = document.querySelectorAll('audio');
@@ -238,13 +252,10 @@ function normalizeFormValues(values) {
238
252
  }
239
253
  function normalizeSearchParams(params) {
240
254
  if (params.startDate || params.endDate) {
241
- params = {
242
- ...omit(params, ['startDate', 'endDate']),
243
- dateRange: [
255
+ params = Object.assign(Object.assign({}, omit(params, ['startDate', 'endDate'])), { dateRange: [
244
256
  params.startDate && moment(params.startDate),
245
257
  params.endDate && moment(params.endDate)
246
- ]
247
- };
258
+ ] });
248
259
  }
249
260
  Object.entries(params).forEach(([key, value]) => {
250
261
  if (typeof value === 'string' && value.includes(',')) {
@@ -334,20 +345,19 @@ const download = (data, strFileName = 'download', strMimeType = 'application/oct
334
345
  const fn = strFileName;
335
346
  let blob = null;
336
347
  let fr = null;
337
- const d2b = (u) => {
338
- const p = u.split(/[:;,]/);
339
- const t = p[1];
340
- const dec = p[2] === 'base64' ? atob : decodeURIComponent;
341
- const bin = dec(p.pop());
342
- const mx = bin.length;
343
- let i = 0;
344
- const uia = new Uint8Array(mx);
345
- for (i; i < mx; ++i)
346
- uia[i] = bin.charCodeAt(i);
347
- return new B([uia], {
348
- type: t
349
- });
350
- };
348
+ // const d2b = (u: any) => {
349
+ // const p = u.split(/[:;,]/)
350
+ // const t = p[1]
351
+ // const dec = p[2] === 'base64' ? atob : decodeURIComponent
352
+ // const bin = dec(p.pop())
353
+ // const mx = bin.length
354
+ // let i = 0
355
+ // const uia = new Uint8Array(mx)
356
+ // for (i; i < mx; ++i) uia[i] = bin.charCodeAt(i)
357
+ // return new B([uia], {
358
+ // type: t
359
+ // })
360
+ // }
351
361
  const saver = (url, winMode) => {
352
362
  if ('download' in a) {
353
363
  // html5 A[download]
@@ -385,9 +395,10 @@ const download = (data, strFileName = 'download', strMimeType = 'application/oct
385
395
  // }
386
396
  // go ahead and download dataURLs right away
387
397
  if (String(x).match(/^data\:[\w+\-]+\/[\w+\-]+[,;]/)) {
388
- return navigator.msSaveBlob // IE10 can't do a[download], only Blobs:
389
- ? navigator.msSaveBlob(d2b(x), fn)
390
- : saver(x); // everyone else can save dataURLs un-processed
398
+ return saver(x);
399
+ // return navigator?.msSaveBlob // IE10 can't do a[download], only Blobs:
400
+ // ? navigator?.msSaveBlob(d2b(x), fn)
401
+ // : saver(x) // everyone else can save dataURLs un-processed
391
402
  } // end if dataURL passed?
392
403
  try {
393
404
  blob =
@@ -404,10 +415,10 @@ const download = (data, strFileName = 'download', strMimeType = 'application/oct
404
415
  // blob = b.getBlob(m); // the blob
405
416
  // }
406
417
  }
407
- if (navigator.msSaveBlob) {
408
- // IE10+ : (has Blob, but not a[download] or URL)
409
- return navigator.msSaveBlob(blob, fn);
410
- }
418
+ // if (navigator.msSaveBlob) {
419
+ // // IE10+ : (has Blob, but not a[download] or URL)
420
+ // return navigator.msSaveBlob(blob, fn)
421
+ // }
411
422
  if (self.URL) {
412
423
  // simple fast and modern way using Blob and URL:
413
424
  // saver(self.URL.createObjectURL(blob), true);
@@ -433,4 +444,4 @@ const download = (data, strFileName = 'download', strMimeType = 'application/oct
433
444
  return true;
434
445
  };
435
446
 
436
- export { DATE_FORMAT, FORMAT_DATE, FORMAT_TIME, NIL_STRING, accAdd, accDiv, accMul, accSub, cutTimeFn, digitCnUppercase, download, fileReaderToBase64, format10k, format10kNil, formatCash, formatCash2, formatCashInt, formatCashIntNil, formatCashNil, formatCreditEnhanced, formatDate, formatDateNil, formatDuration, formatDurationNil, formatRatio, formatRatioNil, getBase64, getItem, getQueryObject, getSearchParams, getValOfArr, getValueWithNil, inBrowser, isArray, isBlob, isDate, isFile, isNil, isNull, isObject, isUndefined, log, normalizeFormValues, normalizeSearchParams, os, playAudio, random, randomString, removeAll, removeItem, setItem, setProxyObj, sortObj, sumObj, trimString };
447
+ export { DATE_FORMAT, FORMAT_DATE, FORMAT_TIME, NIL_STRING, accAdd, accDiv, accMul, accSub, cutTimeFn, digitCnUppercase, download, fileReaderToBase64, format10k, format10kNil, formatCash, formatCash2, formatCashInt, formatCashIntNil, formatCashNil, formatCreditEnhanced, formatDate, formatDateNil, formatDuration, formatDurationNil, formatRatio, formatRatioNil, getBase64, getItem, getQueryObject, getSearchParams, getValOfArr, getValueWithNil, inBrowser, isArray, isBlob, isCardNo, isDate, isEmail, isFile, isNil, isNull, isObject, isPhone, isSMSCode, isUndefined, log, normalizeFormValues, normalizeSearchParams, os, playAudio, random, randomString, removeAll, removeItem, setItem, setProxyObj, sortObj, sumObj, trimString };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lgutils",
3
- "version": "1.2.32",
3
+ "version": "1.3.5",
4
4
  "description": "lgutils",
5
5
  "main": "index.js",
6
6
  "module": "lib/lgutils.cjs.prod.js",
@@ -35,5 +35,5 @@
35
35
  "@types/moment": "^2.13.0",
36
36
  "@types/qs": "^6.9.0"
37
37
  },
38
- "gitHead": "60742b3c620ea1b856d5eb15de74b10f96b7663d"
38
+ "gitHead": "35e3d5499dce983ef12a69119674dd64416567ba"
39
39
  }