lgutils 1.3.14 → 1.3.25

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
@@ -126,6 +126,8 @@ export declare const isEmail: (emailStr: string) => boolean
126
126
 
127
127
  export declare const isFile: (value: any) => any
128
128
 
129
+ export declare const isMinigram: () => boolean
130
+
129
131
  export declare const isNil: (val: any) => val is NIL
130
132
 
131
133
  export declare const isNull: (value: any) => boolean
@@ -138,6 +140,8 @@ export declare const isSMSCode: (code: any) => any
138
140
 
139
141
  export declare const isUndefined: (value: any) => boolean
140
142
 
143
+ export declare const isWX: () => boolean
144
+
141
145
  declare interface IWSObj {
142
146
  open?: (params?: any) => any
143
147
  msg: (params: any) => any
@@ -4,11 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var qs = require('qs');
6
6
  var d3Format = require('d3-format');
7
- var moment = require('moment');
7
+ var dayjs = require('dayjs');
8
8
 
9
9
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
10
10
 
11
- var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
11
+ var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
12
12
 
13
13
  const log = (...rest) => {
14
14
  console.group('=====================');
@@ -36,7 +36,7 @@ const isSMSCode = (code) => {
36
36
  const random = (min, max) => Math.round(Math.random() * (max - min) + min);
37
37
  const playAudio = (mp3Id) => {
38
38
  const audioArr = document.querySelectorAll('audio');
39
- Array.from(audioArr).forEach(mp3 => {
39
+ Array.from(audioArr).forEach((mp3) => {
40
40
  mp3.pause();
41
41
  mp3.currentTime = 0;
42
42
  });
@@ -56,11 +56,11 @@ const getValOfArr = (_array) => {
56
56
  max: Math.max.apply(null, _array),
57
57
  sum,
58
58
  average: sum / len,
59
- mull
59
+ mull,
60
60
  };
61
61
  };
62
62
  const sumObj = (obj, key) => obj.reduce((prev, cur) => cur[key] + prev, 0);
63
- const sortObj = (obj, property, type = 'asc') => obj.sort((a, b) => type === 'asc' ? b[property] - a[property] : a[property] - b[property]);
63
+ const sortObj = (obj, property, type = 'asc') => obj.sort((a, b) => (type === 'asc' ? a[property] - b[property] : b[property] - a[property]));
64
64
  const isUndefined = (value) => value === undefined;
65
65
  const isNull = (value) => value === null;
66
66
  const isObject = (value) => value === Object(value);
@@ -72,8 +72,7 @@ const isBlob = (value) => value &&
72
72
  typeof value.slice === 'function';
73
73
  const isFile = (value) => isBlob(value) &&
74
74
  typeof value.name === 'string' &&
75
- (typeof value.lastModifiedDate === 'object' ||
76
- typeof value.lastModified === 'number');
75
+ (typeof value.lastModifiedDate === 'object' || typeof value.lastModified === 'number');
77
76
  const getQueryObject = (url = window.location.href) => {
78
77
  // const search = url.substring(url.lastIndexOf('?') + 1)
79
78
  // let obj: any = {}
@@ -104,7 +103,7 @@ const getBase64 = (file) => {
104
103
  const reader = new FileReader();
105
104
  reader.readAsDataURL(file);
106
105
  reader.onload = () => resolve(reader.result);
107
- reader.onerror = error => reject(error);
106
+ reader.onerror = (error) => reject(error);
108
107
  });
109
108
  };
110
109
  const os = () => {
@@ -113,7 +112,7 @@ const os = () => {
113
112
  isTablet: false,
114
113
  isPhone: false,
115
114
  isAndroid: false,
116
- isPc: false
115
+ isPc: false,
117
116
  };
118
117
  const ua = navigator.userAgent, isWindowsPhone = /(?:Windows Phone)/.test(ua), isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone, isAndroid = /(?:Android)/.test(ua), isFireFox = /(?:Firefox)/.test(ua),
119
118
  // isChrome = /(?:Chrome|CriOS)/.test(ua),
@@ -124,7 +123,7 @@ const os = () => {
124
123
  isTablet: isTablet,
125
124
  isPhone: isPhone,
126
125
  isAndroid: isAndroid,
127
- isPc: isPc
126
+ isPc: isPc,
128
127
  };
129
128
  };
130
129
  const accMul = (arg1, arg2) => {
@@ -137,8 +136,7 @@ const accMul = (arg1, arg2) => {
137
136
  m += s2.split('.')[1].length;
138
137
  }
139
138
  catch (e) { }
140
- return ((Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) /
141
- Math.pow(10, m));
139
+ return (Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) / Math.pow(10, m);
142
140
  };
143
141
  const accDiv = (arg1, arg2) => {
144
142
  let t1 = 0, t2 = 0, r1, r2;
@@ -198,6 +196,14 @@ const randomString = (len = 32) => {
198
196
  pwd += chars.charAt(Math.floor(Math.random() * maxPos));
199
197
  }
200
198
  return pwd;
199
+ };
200
+ const isWX = () => {
201
+ const ua = navigator.userAgent.toLowerCase();
202
+ return /MicroMessenger/i.test(ua);
203
+ };
204
+ const isMinigram = () => {
205
+ // @ts-ignore: 判断小程序环境
206
+ return (window === null || window === void 0 ? void 0 : window.__wxjs_environment) ? true : false;
201
207
  };
202
208
 
203
209
  const storage = inBrowser ? localStorage : {};
@@ -236,42 +242,6 @@ const SERVER_DATE_FROMAT = 'YYYY-MM-DD';
236
242
  const DATE_FORMAT = 'YYYY/MM/DD';
237
243
  const FORMAT_DATE = SERVER_DATE_FROMAT;
238
244
  const FORMAT_TIME = 'YYYY-MM-DD HH:mm:ss';
239
- // type IndexType = { [x: string]: any }
240
- // export function normalizeFormValues<T extends IndexType>(values: T) {
241
- // return Object.entries(values)
242
- // .filter(([key, value]) => value !== undefined && value !== 'all')
243
- // .reduce((mem: any, [key, value]) => {
244
- // // array for [moment, moment]
245
- // if (Array.isArray(value) && value.some((val) => moment.isMoment(val))) {
246
- // if (value[0]) {
247
- // mem.startDate = value[0].format(SERVER_DATE_FROMAT)
248
- // }
249
- // if (value[1]) {
250
- // mem.endDate = value[1].format(SERVER_DATE_FROMAT)
251
- // }
252
- // } else if (moment.isMoment(value)) {
253
- // mem[key] = value.format(SERVER_DATE_FROMAT)
254
- // } else mem[key] = value
255
- // return mem
256
- // }, {} as T)
257
- // }
258
- // export function normalizeSearchParams(params: IndexType) {
259
- // if (params.startDate || params.endDate) {
260
- // params = {
261
- // ...omit(params, ['startDate', 'endDate']),
262
- // dateRange: [
263
- // params.startDate && moment(params.startDate),
264
- // params.endDate && moment(params.endDate),
265
- // ],
266
- // }
267
- // }
268
- // Object.entries(params).forEach(([key, value]) => {
269
- // if (typeof value === 'string' && value.includes(',')) {
270
- // params[key] = 'all'
271
- // }
272
- // })
273
- // return params
274
- // }
275
245
  const format10k = (n) => formatCash(n / 10000);
276
246
  const format10kNil = withDefaultNil(format10k);
277
247
  // null == undefined
@@ -309,7 +279,7 @@ function digitCnUppercase(n) {
309
279
  .replace(/^整$/, '零元整'));
310
280
  }
311
281
  function formatDate(d, formatType = SERVER_DATE_FROMAT) {
312
- return moment__default(new Date(d)).format(formatType);
282
+ return dayjs__default(new Date(d)).format(formatType);
313
283
  }
314
284
  const formatDateNil = withDefaultNil(formatDate);
315
285
  const unit = {
@@ -603,12 +573,14 @@ exports.isCardNo = isCardNo;
603
573
  exports.isDate = isDate;
604
574
  exports.isEmail = isEmail;
605
575
  exports.isFile = isFile;
576
+ exports.isMinigram = isMinigram;
606
577
  exports.isNil = isNil;
607
578
  exports.isNull = isNull;
608
579
  exports.isObject = isObject;
609
580
  exports.isPhone = isPhone;
610
581
  exports.isSMSCode = isSMSCode;
611
582
  exports.isUndefined = isUndefined;
583
+ exports.isWX = isWX;
612
584
  exports.log = log;
613
585
  exports.os = os;
614
586
  exports.playAudio = playAudio;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("qs"),t=require("d3-format");function o(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var r=o(require("moment"));const s=(...e)=>{console.group("====================="),console.info(...e),console.groupEnd()},n="undefined"!=typeof window,a=e=>e&&"number"==typeof e.size&&"string"==typeof e.type&&"function"==typeof e.slice,i=n?localStorage:{};let c={};const l=t.format(",.2f"),p=t.format(","),d=t.format(".2%"),u=f(l),h=f(p),m=f(d);function f(e){return t=>y(t)?w:e(t)}const x=e=>l(e/1e4),g=f(x),y=e=>null==e||""===e,w="——";function b(e,t="YYYY-MM-DD"){return r(new Date(e)).format(t)}const M=f(b),S={d:"天",m:"个月",y:"年"};function v(e){return e?`${parseInt(e,10)}${S[e.slice(-1).toLowerCase()]}`:e}const D=f(v);exports.DATE_FORMAT="YYYY/MM/DD",exports.FORMAT_DATE="YYYY-MM-DD",exports.FORMAT_TIME="YYYY-MM-DD HH:mm:ss",exports.NIL_STRING=w,exports.WS=class{constructor(e,t){this.socket=null,this.timer=null,this.ioUrl="",this.heartTime=1e4;this.ioUrl=e,this.socket=t?new WebSocket(e,t):new WebSocket(e)}init(e){const t=this;t.heartInfo=(null==e?void 0:e.heartInfo)?JSON.stringify(null==e?void 0:e.heartInfo):"ws HeartBeat!",t.socket.addEventListener("open",(()=>{s("ws connect!"),t.start(t.heartInfo),e.open&&e.open()}),!1),t.socket.addEventListener("disconnect",(()=>{console.info("[ws info]: disconnect and reconnect... "),e.disconnect&&e.disconnect(),t.socket=new WebSocket(t.ioUrl)}),!1),t.socket.addEventListener("error",(t=>{console.info("---------------"),console.info("[ws error]: "),console.info(t),console.info("---------------"),e.error&&e.error()}),!1),t.socket.addEventListener("close",e.close,!1),t.socket.addEventListener("message",(o=>{t.reset(),e.msg(o)}),!1)}close(){this.timer&&clearTimeout(this.timer),console.info("[ws close]: close!"),this.socket.close()}start(e){const t=this;t.timer=setTimeout((()=>{t.socket.send(e)}),t.heartTime)}send(e){this.socket.send(e)}reset(){const e=this;clearTimeout(e.timer),e.start(e.heartInfo)}getSocketState(){return this.socket.readyState}setHeartTime(e){this.heartTime=e,this.reset()}},exports.accAdd=(e,t)=>{let o,r,s;try{o=e.toString().split(".")[1].length}catch(n){o=0}try{r=t.toString().split(".")[1].length}catch(n){r=0}return s=Math.pow(10,Math.max(o,r)),(e*s+t*s)/s},exports.accDiv=(e,t)=>{let o,r,s=0,n=0;try{s=e.toString().split(".")[1].length}catch(a){}try{n=t.toString().split(".")[1].length}catch(a){}return o=Number(e.toString().replace(".","")),r=Number(t.toString().replace(".","")),o/r*Math.pow(10,n-s)},exports.accMul=(e,t)=>{let o=0,r=e.toString(),s=t.toString();try{o+=r.split(".")[1].length}catch(n){}try{o+=s.split(".")[1].length}catch(n){}return Number(r.replace(".",""))*Number(s.replace(".",""))/Math.pow(10,o)},exports.accSub=function(e,t){let o,r,s,n;try{o=e.toString().split(".")[1].length}catch(a){o=0}try{r=t.toString().split(".")[1].length}catch(a){r=0}return s=Math.pow(10,Math.max(o,r)),n=o>=r?o:r,((e*s-t*s)/s).toFixed(n)},exports.copyToClipboard=function(e){var t=document.createElement("textarea");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)},exports.cutTimeFn=e=>`00‘${0===e?"00":"0"+Math.floor(e/60)}’${0===e?"00":e%60>=10?e%60:"0"+e%60}`,exports.digitCnUppercase=function(e){var t=["角","分"],o=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],r=[["元","万","亿"],["","拾","佰","仟"]],s=e<0?"欠":"";e=Math.abs(e);for(var n="",a=0;a<t.length;a++)n+=(o[Math.floor(10*e*Math.pow(10,a))%10]+t[a]).replace(/零./,"");for(n=n||"整",e=Math.floor(e),a=0;a<r[0].length&&e>0;a++){for(var i="",c=0;c<r[1].length&&e>0;c++)i=o[e%10]+r[1][c]+i,e=Math.floor(e/10);n=i.replace(/(零.)*零$/,"").replace(/^$/,"零")+r[0][a]+n}return s+n.replace(/(零.)*零元/,"元").replace(/(零.)+/g,"零").replace(/^整$/,"零元整")},exports.disableBrowserZoom=function(){document.addEventListener("keydown",(function(e){!0!==e.ctrlKey&&!0!==e.metaKey||61!==e.which&&107!==e.which&&173!==e.which&&109!==e.which&&187!==e.which&&189!==e.which||e.preventDefault()}),!1),window.addEventListener("mousewheel",(function(e){(!0===e.ctrlKey||e.metaKey)&&e.preventDefault()}),{passive:!1}),window.addEventListener("DOMMouseScroll",(function(e){(!0===e.ctrlKey||e.metaKey)&&e.preventDefault()}),{passive:!1})},exports.download=(e,t="download",o="application/octet-stream",r)=>{const s=window;let n=o,a=e;const i=document,c=i.createElement("a"),l=e=>String(e),p=s.Blob||l(c),d=t;let u=null,h=null;const m=(t,o)=>{if("download"in c)return c.href=r?e:t,c.setAttribute("download",d),c.innerHTML="downloading...",i.body.appendChild(c),setTimeout((()=>{c.click(),i.body.removeChild(c),!0===o&&setTimeout((()=>{s.URL.revokeObjectURL(c.href)}),250)}),66),!0;const n=i.createElement("iframe");i.body.appendChild(n),o||(t="data:"+t.replace(/^data:([\w\/\-\+]+)/,"application/octet-stream")),n.src=t,setTimeout((()=>{i.body.removeChild(n)}),333)};if(String(a).match(/^data\:[\w+\-]+\/[\w+\-]+[,;]/))return m(a);try{u=a instanceof p?a:new p([a],{type:n})}catch(f){}if(s.URL)m(s.URL.createObjectURL(u),!0);else{if("string"==typeof u||u.constructor===l(c))try{return m("data:"+n+";base64,"+s.btoa(u))}catch(f){return m("data:"+n+","+encodeURIComponent(u))}h=new FileReader,h.onload=function(){m(this.result)},h.readAsDataURL(u)}return!0},exports.fileReaderToBase64=e=>t=>{const o=new FileReader;o.onload=e=>{t&&t(e.target.result)},o.readAsDataURL(e)},exports.format10k=x,exports.format10kNil=g,exports.formatCash=l,exports.formatCash2=e=>(Math.floor(100*e)/100).toFixed(2),exports.formatCashInt=p,exports.formatCashIntNil=h,exports.formatCashNil=u,exports.formatDate=b,exports.formatDateNil=M,exports.formatDuration=v,exports.formatDurationNil=D,exports.formatRatio=d,exports.formatRatioNil=m,exports.getBase64=e=>new Promise(((t,o)=>{const r=new FileReader;r.readAsDataURL(e),r.onload=()=>t(r.result),r.onerror=e=>o(e)})),exports.getItem=e=>((c[e]||i.getItem(""+e))&&(c[e]=JSON.parse(i.getItem(""+e)||"null")),c[e]),exports.getQueryObject=(t=window.location.href)=>{const o=t.split("?")[1];return e.parse(o||"")},exports.getSearchParams=e=>new URLSearchParams(e),exports.getValOfArr=e=>{const t=e.length,o=e.reduce(((e,t)=>e+t),0),r=e.reduce(((e,t)=>e*t),1);return{min:Math.min.apply(null,e),max:Math.max.apply(null,e),sum:o,average:o/t,mull:r}},exports.getValueWithNil=e=>y(e)?w:e,exports.inBrowser=n,exports.isArray=e=>Array.isArray(e),exports.isBlob=a,exports.isCardNo=e=>/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/.test(e),exports.isDate=e=>e instanceof Date,exports.isEmail=e=>/^(.+)@(.+)\.(.+)$/.test(e),exports.isFile=e=>a(e)&&"string"==typeof e.name&&("object"==typeof e.lastModifiedDate||"number"==typeof e.lastModified),exports.isNil=y,exports.isNull=e=>null===e,exports.isObject=e=>e===Object(e),exports.isPhone=e=>/^[1](\d{10})$/.test(e),exports.isSMSCode=e=>e.match(/^\d{6}$/),exports.isUndefined=e=>void 0===e,exports.log=s,exports.os=()=>{if(!n)return{isTablet:!1,isPhone:!1,isAndroid:!1,isPc:!1};const e=navigator.userAgent,t=/(?:Windows Phone)/.test(e),o=/(?:SymbianOS)/.test(e)||t,r=/(?:Android)/.test(e),s=/(?:Firefox)/.test(e),a=/(?:iPad|PlayBook)/.test(e)||r&&!/(?:Mobile)/.test(e)||s&&/(?:Tablet)/.test(e),i=/(?:iPhone)/.test(e)&&!a;return{isTablet:a,isPhone:i,isAndroid:r,isPc:!i&&!r&&!o}},exports.playAudio=e=>{const t=document.querySelectorAll("audio");Array.from(t).forEach((e=>{e.pause(),e.currentTime=0})),document.querySelector(`#${e}`).play()},exports.random=(e,t)=>Math.round(Math.random()*(t-e)+e),exports.randomString=(e=32)=>{const t="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",o=t.length;let r="";for(let s=0;s<e;s++)r+=t.charAt(Math.floor(Math.random()*o));return r},exports.removeAll=()=>(c={},i.clear()),exports.removeItem=e=>(delete c[e],i.removeItem(""+e)),exports.setItem=(e,t)=>(c[e]=t,i.setItem(""+e,JSON.stringify(t))),exports.setProxyObj=(e,t,o)=>new Proxy(e,{get:(e,o)=>(t(),Reflect.get(e,o)),set:(e,t,r)=>(o(),Reflect.set(e,t,r))}),exports.sortObj=(e,t,o="asc")=>e.sort(((e,r)=>"asc"===o?r[t]-e[t]:e[t]-r[t])),exports.sumObj=(e,t)=>e.reduce(((e,o)=>o[t]+e),0),exports.trimString=e=>e.replace(/(^\s*)|(\s*$)/g,"");
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("qs"),t=require("d3-format");function o(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var r=o(require("dayjs"));const s=(...e)=>{console.group("====================="),console.info(...e),console.groupEnd()},n="undefined"!=typeof window,a=e=>e&&"number"==typeof e.size&&"string"==typeof e.type&&"function"==typeof e.slice,i=n?localStorage:{};let c={};const l=t.format(",.2f"),d=t.format(","),p=t.format(".2%"),u=f(l),h=f(d),m=f(p);function f(e){return t=>w(t)?y:e(t)}const x=e=>l(e/1e4),g=f(x),w=e=>null==e||""===e,y="——";function M(e,t="YYYY-MM-DD"){return r(new Date(e)).format(t)}const b=f(M),v={d:"天",m:"个月",y:"年"};function S(e){return e?`${parseInt(e,10)}${v[e.slice(-1).toLowerCase()]}`:e}const D=f(S);exports.DATE_FORMAT="YYYY/MM/DD",exports.FORMAT_DATE="YYYY-MM-DD",exports.FORMAT_TIME="YYYY-MM-DD HH:mm:ss",exports.NIL_STRING=y,exports.WS=class{constructor(e,t){this.socket=null,this.timer=null,this.ioUrl="",this.heartTime=1e4;this.ioUrl=e,this.socket=t?new WebSocket(e,t):new WebSocket(e)}init(e){const t=this;t.heartInfo=(null==e?void 0:e.heartInfo)?JSON.stringify(null==e?void 0:e.heartInfo):"ws HeartBeat!",t.socket.addEventListener("open",(()=>{s("ws connect!"),t.start(t.heartInfo),e.open&&e.open()}),!1),t.socket.addEventListener("disconnect",(()=>{console.info("[ws info]: disconnect and reconnect... "),e.disconnect&&e.disconnect(),t.socket=new WebSocket(t.ioUrl)}),!1),t.socket.addEventListener("error",(t=>{console.info("---------------"),console.info("[ws error]: "),console.info(t),console.info("---------------"),e.error&&e.error()}),!1),t.socket.addEventListener("close",e.close,!1),t.socket.addEventListener("message",(o=>{t.reset(),e.msg(o)}),!1)}close(){this.timer&&clearTimeout(this.timer),console.info("[ws close]: close!"),this.socket.close()}start(e){const t=this;t.timer=setTimeout((()=>{t.socket.send(e)}),t.heartTime)}send(e){this.socket.send(e)}reset(){const e=this;clearTimeout(e.timer),e.start(e.heartInfo)}getSocketState(){return this.socket.readyState}setHeartTime(e){this.heartTime=e,this.reset()}},exports.accAdd=(e,t)=>{let o,r,s;try{o=e.toString().split(".")[1].length}catch(n){o=0}try{r=t.toString().split(".")[1].length}catch(n){r=0}return s=Math.pow(10,Math.max(o,r)),(e*s+t*s)/s},exports.accDiv=(e,t)=>{let o,r,s=0,n=0;try{s=e.toString().split(".")[1].length}catch(a){}try{n=t.toString().split(".")[1].length}catch(a){}return o=Number(e.toString().replace(".","")),r=Number(t.toString().replace(".","")),o/r*Math.pow(10,n-s)},exports.accMul=(e,t)=>{let o=0,r=e.toString(),s=t.toString();try{o+=r.split(".")[1].length}catch(n){}try{o+=s.split(".")[1].length}catch(n){}return Number(r.replace(".",""))*Number(s.replace(".",""))/Math.pow(10,o)},exports.accSub=function(e,t){let o,r,s,n;try{o=e.toString().split(".")[1].length}catch(a){o=0}try{r=t.toString().split(".")[1].length}catch(a){r=0}return s=Math.pow(10,Math.max(o,r)),n=o>=r?o:r,((e*s-t*s)/s).toFixed(n)},exports.copyToClipboard=function(e){var t=document.createElement("textarea");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)},exports.cutTimeFn=e=>`00‘${0===e?"00":"0"+Math.floor(e/60)}’${0===e?"00":e%60>=10?e%60:"0"+e%60}`,exports.digitCnUppercase=function(e){var t=["角","分"],o=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],r=[["元","万","亿"],["","拾","佰","仟"]],s=e<0?"欠":"";e=Math.abs(e);for(var n="",a=0;a<t.length;a++)n+=(o[Math.floor(10*e*Math.pow(10,a))%10]+t[a]).replace(/零./,"");for(n=n||"整",e=Math.floor(e),a=0;a<r[0].length&&e>0;a++){for(var i="",c=0;c<r[1].length&&e>0;c++)i=o[e%10]+r[1][c]+i,e=Math.floor(e/10);n=i.replace(/(零.)*零$/,"").replace(/^$/,"零")+r[0][a]+n}return s+n.replace(/(零.)*零元/,"元").replace(/(零.)+/g,"零").replace(/^整$/,"零元整")},exports.disableBrowserZoom=function(){document.addEventListener("keydown",(function(e){!0!==e.ctrlKey&&!0!==e.metaKey||61!==e.which&&107!==e.which&&173!==e.which&&109!==e.which&&187!==e.which&&189!==e.which||e.preventDefault()}),!1),window.addEventListener("mousewheel",(function(e){(!0===e.ctrlKey||e.metaKey)&&e.preventDefault()}),{passive:!1}),window.addEventListener("DOMMouseScroll",(function(e){(!0===e.ctrlKey||e.metaKey)&&e.preventDefault()}),{passive:!1})},exports.download=(e,t="download",o="application/octet-stream",r)=>{const s=window;let n=o,a=e;const i=document,c=i.createElement("a"),l=e=>String(e),d=s.Blob||l(c),p=t;let u=null,h=null;const m=(t,o)=>{if("download"in c)return c.href=r?e:t,c.setAttribute("download",p),c.innerHTML="downloading...",i.body.appendChild(c),setTimeout((()=>{c.click(),i.body.removeChild(c),!0===o&&setTimeout((()=>{s.URL.revokeObjectURL(c.href)}),250)}),66),!0;const n=i.createElement("iframe");i.body.appendChild(n),o||(t="data:"+t.replace(/^data:([\w\/\-\+]+)/,"application/octet-stream")),n.src=t,setTimeout((()=>{i.body.removeChild(n)}),333)};if(String(a).match(/^data\:[\w+\-]+\/[\w+\-]+[,;]/))return m(a);try{u=a instanceof d?a:new d([a],{type:n})}catch(f){}if(s.URL)m(s.URL.createObjectURL(u),!0);else{if("string"==typeof u||u.constructor===l(c))try{return m("data:"+n+";base64,"+s.btoa(u))}catch(f){return m("data:"+n+","+encodeURIComponent(u))}h=new FileReader,h.onload=function(){m(this.result)},h.readAsDataURL(u)}return!0},exports.fileReaderToBase64=e=>t=>{const o=new FileReader;o.onload=e=>{t&&t(e.target.result)},o.readAsDataURL(e)},exports.format10k=x,exports.format10kNil=g,exports.formatCash=l,exports.formatCash2=e=>(Math.floor(100*e)/100).toFixed(2),exports.formatCashInt=d,exports.formatCashIntNil=h,exports.formatCashNil=u,exports.formatDate=M,exports.formatDateNil=b,exports.formatDuration=S,exports.formatDurationNil=D,exports.formatRatio=p,exports.formatRatioNil=m,exports.getBase64=e=>new Promise(((t,o)=>{const r=new FileReader;r.readAsDataURL(e),r.onload=()=>t(r.result),r.onerror=e=>o(e)})),exports.getItem=e=>((c[e]||i.getItem(""+e))&&(c[e]=JSON.parse(i.getItem(""+e)||"null")),c[e]),exports.getQueryObject=(t=window.location.href)=>{const o=t.split("?")[1];return e.parse(o||"")},exports.getSearchParams=e=>new URLSearchParams(e),exports.getValOfArr=e=>{const t=e.length,o=e.reduce(((e,t)=>e+t),0),r=e.reduce(((e,t)=>e*t),1);return{min:Math.min.apply(null,e),max:Math.max.apply(null,e),sum:o,average:o/t,mull:r}},exports.getValueWithNil=e=>w(e)?y:e,exports.inBrowser=n,exports.isArray=e=>Array.isArray(e),exports.isBlob=a,exports.isCardNo=e=>/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/.test(e),exports.isDate=e=>e instanceof Date,exports.isEmail=e=>/^(.+)@(.+)\.(.+)$/.test(e),exports.isFile=e=>a(e)&&"string"==typeof e.name&&("object"==typeof e.lastModifiedDate||"number"==typeof e.lastModified),exports.isMinigram=()=>!!(null===window||void 0===window?void 0:window.__wxjs_environment),exports.isNil=w,exports.isNull=e=>null===e,exports.isObject=e=>e===Object(e),exports.isPhone=e=>/^[1](\d{10})$/.test(e),exports.isSMSCode=e=>e.match(/^\d{6}$/),exports.isUndefined=e=>void 0===e,exports.isWX=()=>{const e=navigator.userAgent.toLowerCase();return/MicroMessenger/i.test(e)},exports.log=s,exports.os=()=>{if(!n)return{isTablet:!1,isPhone:!1,isAndroid:!1,isPc:!1};const e=navigator.userAgent,t=/(?:Windows Phone)/.test(e),o=/(?:SymbianOS)/.test(e)||t,r=/(?:Android)/.test(e),s=/(?:Firefox)/.test(e),a=/(?:iPad|PlayBook)/.test(e)||r&&!/(?:Mobile)/.test(e)||s&&/(?:Tablet)/.test(e),i=/(?:iPhone)/.test(e)&&!a;return{isTablet:a,isPhone:i,isAndroid:r,isPc:!i&&!r&&!o}},exports.playAudio=e=>{const t=document.querySelectorAll("audio");Array.from(t).forEach((e=>{e.pause(),e.currentTime=0})),document.querySelector(`#${e}`).play()},exports.random=(e,t)=>Math.round(Math.random()*(t-e)+e),exports.randomString=(e=32)=>{const t="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",o=t.length;let r="";for(let s=0;s<e;s++)r+=t.charAt(Math.floor(Math.random()*o));return r},exports.removeAll=()=>(c={},i.clear()),exports.removeItem=e=>(delete c[e],i.removeItem(""+e)),exports.setItem=(e,t)=>(c[e]=t,i.setItem(""+e,JSON.stringify(t))),exports.setProxyObj=(e,t,o)=>new Proxy(e,{get:(e,o)=>(t(),Reflect.get(e,o)),set:(e,t,r)=>(o(),Reflect.set(e,t,r))}),exports.sortObj=(e,t,o="asc")=>e.sort(((e,r)=>"asc"===o?e[t]-r[t]:r[t]-e[t])),exports.sumObj=(e,t)=>e.reduce(((e,o)=>o[t]+e),0),exports.trimString=e=>e.replace(/(^\s*)|(\s*$)/g,"");
@@ -1,6 +1,6 @@
1
1
  import { parse } from 'qs';
2
2
  import { format } from 'd3-format';
3
- import moment from 'moment';
3
+ import dayjs from 'dayjs';
4
4
 
5
5
  const log = (...rest) => {
6
6
  console.group('=====================');
@@ -28,7 +28,7 @@ const isSMSCode = (code) => {
28
28
  const random = (min, max) => Math.round(Math.random() * (max - min) + min);
29
29
  const playAudio = (mp3Id) => {
30
30
  const audioArr = document.querySelectorAll('audio');
31
- Array.from(audioArr).forEach(mp3 => {
31
+ Array.from(audioArr).forEach((mp3) => {
32
32
  mp3.pause();
33
33
  mp3.currentTime = 0;
34
34
  });
@@ -48,11 +48,11 @@ const getValOfArr = (_array) => {
48
48
  max: Math.max.apply(null, _array),
49
49
  sum,
50
50
  average: sum / len,
51
- mull
51
+ mull,
52
52
  };
53
53
  };
54
54
  const sumObj = (obj, key) => obj.reduce((prev, cur) => cur[key] + prev, 0);
55
- const sortObj = (obj, property, type = 'asc') => obj.sort((a, b) => type === 'asc' ? b[property] - a[property] : a[property] - b[property]);
55
+ const sortObj = (obj, property, type = 'asc') => obj.sort((a, b) => (type === 'asc' ? a[property] - b[property] : b[property] - a[property]));
56
56
  const isUndefined = (value) => value === undefined;
57
57
  const isNull = (value) => value === null;
58
58
  const isObject = (value) => value === Object(value);
@@ -64,8 +64,7 @@ const isBlob = (value) => value &&
64
64
  typeof value.slice === 'function';
65
65
  const isFile = (value) => isBlob(value) &&
66
66
  typeof value.name === 'string' &&
67
- (typeof value.lastModifiedDate === 'object' ||
68
- typeof value.lastModified === 'number');
67
+ (typeof value.lastModifiedDate === 'object' || typeof value.lastModified === 'number');
69
68
  const getQueryObject = (url = window.location.href) => {
70
69
  // const search = url.substring(url.lastIndexOf('?') + 1)
71
70
  // let obj: any = {}
@@ -96,7 +95,7 @@ const getBase64 = (file) => {
96
95
  const reader = new FileReader();
97
96
  reader.readAsDataURL(file);
98
97
  reader.onload = () => resolve(reader.result);
99
- reader.onerror = error => reject(error);
98
+ reader.onerror = (error) => reject(error);
100
99
  });
101
100
  };
102
101
  const os = () => {
@@ -105,7 +104,7 @@ const os = () => {
105
104
  isTablet: false,
106
105
  isPhone: false,
107
106
  isAndroid: false,
108
- isPc: false
107
+ isPc: false,
109
108
  };
110
109
  const ua = navigator.userAgent, isWindowsPhone = /(?:Windows Phone)/.test(ua), isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone, isAndroid = /(?:Android)/.test(ua), isFireFox = /(?:Firefox)/.test(ua),
111
110
  // isChrome = /(?:Chrome|CriOS)/.test(ua),
@@ -116,7 +115,7 @@ const os = () => {
116
115
  isTablet: isTablet,
117
116
  isPhone: isPhone,
118
117
  isAndroid: isAndroid,
119
- isPc: isPc
118
+ isPc: isPc,
120
119
  };
121
120
  };
122
121
  const accMul = (arg1, arg2) => {
@@ -129,8 +128,7 @@ const accMul = (arg1, arg2) => {
129
128
  m += s2.split('.')[1].length;
130
129
  }
131
130
  catch (e) { }
132
- return ((Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) /
133
- Math.pow(10, m));
131
+ return (Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) / Math.pow(10, m);
134
132
  };
135
133
  const accDiv = (arg1, arg2) => {
136
134
  let t1 = 0, t2 = 0, r1, r2;
@@ -190,6 +188,14 @@ const randomString = (len = 32) => {
190
188
  pwd += chars.charAt(Math.floor(Math.random() * maxPos));
191
189
  }
192
190
  return pwd;
191
+ };
192
+ const isWX = () => {
193
+ const ua = navigator.userAgent.toLowerCase();
194
+ return /MicroMessenger/i.test(ua);
195
+ };
196
+ const isMinigram = () => {
197
+ // @ts-ignore: 判断小程序环境
198
+ return (window === null || window === void 0 ? void 0 : window.__wxjs_environment) ? true : false;
193
199
  };
194
200
 
195
201
  const storage = inBrowser ? localStorage : {};
@@ -228,42 +234,6 @@ const SERVER_DATE_FROMAT = 'YYYY-MM-DD';
228
234
  const DATE_FORMAT = 'YYYY/MM/DD';
229
235
  const FORMAT_DATE = SERVER_DATE_FROMAT;
230
236
  const FORMAT_TIME = 'YYYY-MM-DD HH:mm:ss';
231
- // type IndexType = { [x: string]: any }
232
- // export function normalizeFormValues<T extends IndexType>(values: T) {
233
- // return Object.entries(values)
234
- // .filter(([key, value]) => value !== undefined && value !== 'all')
235
- // .reduce((mem: any, [key, value]) => {
236
- // // array for [moment, moment]
237
- // if (Array.isArray(value) && value.some((val) => moment.isMoment(val))) {
238
- // if (value[0]) {
239
- // mem.startDate = value[0].format(SERVER_DATE_FROMAT)
240
- // }
241
- // if (value[1]) {
242
- // mem.endDate = value[1].format(SERVER_DATE_FROMAT)
243
- // }
244
- // } else if (moment.isMoment(value)) {
245
- // mem[key] = value.format(SERVER_DATE_FROMAT)
246
- // } else mem[key] = value
247
- // return mem
248
- // }, {} as T)
249
- // }
250
- // export function normalizeSearchParams(params: IndexType) {
251
- // if (params.startDate || params.endDate) {
252
- // params = {
253
- // ...omit(params, ['startDate', 'endDate']),
254
- // dateRange: [
255
- // params.startDate && moment(params.startDate),
256
- // params.endDate && moment(params.endDate),
257
- // ],
258
- // }
259
- // }
260
- // Object.entries(params).forEach(([key, value]) => {
261
- // if (typeof value === 'string' && value.includes(',')) {
262
- // params[key] = 'all'
263
- // }
264
- // })
265
- // return params
266
- // }
267
237
  const format10k = (n) => formatCash(n / 10000);
268
238
  const format10kNil = withDefaultNil(format10k);
269
239
  // null == undefined
@@ -301,7 +271,7 @@ function digitCnUppercase(n) {
301
271
  .replace(/^整$/, '零元整'));
302
272
  }
303
273
  function formatDate(d, formatType = SERVER_DATE_FROMAT) {
304
- return moment(new Date(d)).format(formatType);
274
+ return dayjs(new Date(d)).format(formatType);
305
275
  }
306
276
  const formatDateNil = withDefaultNil(formatDate);
307
277
  const unit = {
@@ -554,4 +524,4 @@ function copyToClipboard(txt) {
554
524
  document.body.removeChild(textarea);
555
525
  }
556
526
 
557
- export { DATE_FORMAT, FORMAT_DATE, FORMAT_TIME, NIL_STRING, WS, accAdd, accDiv, accMul, accSub, copyToClipboard, cutTimeFn, digitCnUppercase, disableBrowserZoom, download, fileReaderToBase64, format10k, format10kNil, formatCash, formatCash2, formatCashInt, formatCashIntNil, formatCashNil, 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, os, playAudio, random, randomString, removeAll, removeItem, setItem, setProxyObj, sortObj, sumObj, trimString };
527
+ export { DATE_FORMAT, FORMAT_DATE, FORMAT_TIME, NIL_STRING, WS, accAdd, accDiv, accMul, accSub, copyToClipboard, cutTimeFn, digitCnUppercase, disableBrowserZoom, download, fileReaderToBase64, format10k, format10kNil, formatCash, formatCash2, formatCashInt, formatCashIntNil, formatCashNil, formatDate, formatDateNil, formatDuration, formatDurationNil, formatRatio, formatRatioNil, getBase64, getItem, getQueryObject, getSearchParams, getValOfArr, getValueWithNil, inBrowser, isArray, isBlob, isCardNo, isDate, isEmail, isFile, isMinigram, isNil, isNull, isObject, isPhone, isSMSCode, isUndefined, isWX, log, 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.3.14",
3
+ "version": "1.3.25",
4
4
  "description": "lgutils",
5
5
  "main": "index.js",
6
6
  "module": "lib/lgutils.cjs.prod.js",
@@ -25,15 +25,12 @@
25
25
  "homepage": "",
26
26
  "dependencies": {
27
27
  "d3-format": "^1.4.1",
28
- "lodash": "^4.17.15",
29
- "moment": "^2.24.0",
28
+ "dayjs": "^1.11.6",
30
29
  "qs": "^6.9.1"
31
30
  },
32
31
  "devDependencies": {
33
32
  "@types/d3-format": "^1.3.1",
34
- "@types/lodash": "^4.14.144",
35
- "@types/moment": "^2.13.0",
36
33
  "@types/qs": "^6.9.0"
37
34
  },
38
- "gitHead": "fbb1ea34dd1cea2f1261f1606b57f6ba63c6a0af"
35
+ "gitHead": "ba3e872e4ae5f6d98c572850350a8f56e07e1285"
39
36
  }