lgutils 1.3.29 → 1.3.30

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
@@ -35,6 +35,8 @@ export declare const FORMAT_DATE = 'YYYY-MM-DD'
35
35
 
36
36
  export declare const FORMAT_TIME = 'YYYY-MM-DD HH:mm:ss'
37
37
 
38
+ export declare const formatBillion: (num: number) => string
39
+
38
40
  export declare const formatCash: (
39
41
  n:
40
42
  | number
@@ -75,6 +75,7 @@ const isFile = (value) => isBlob(value) &&
75
75
  typeof value.name === 'string' &&
76
76
  (typeof value.lastModifiedDate === 'object' || typeof value.lastModified === 'number');
77
77
  const getQueryObject = (url = window.location.href) => {
78
+ var _a;
78
79
  // const search = url.substring(url.lastIndexOf('?') + 1)
79
80
  // let obj: any = {}
80
81
  // const reg = /([^?&=]+)=([^?&=]*)/g
@@ -87,8 +88,8 @@ const getQueryObject = (url = window.location.href) => {
87
88
  // obj[name] = val
88
89
  // return rs
89
90
  // })
90
- const search = url.split('?')[1];
91
- return qs.parse(search || '');
91
+ const search = (_a = url.split('?')) === null || _a === void 0 ? void 0 : _a[1];
92
+ return qs.parse(search || '', { decoder: str => str });
92
93
  };
93
94
  const getSearchParams = (search) => new URLSearchParams(search);
94
95
  const fileReaderToBase64 = (target) => (cb) => {
@@ -131,6 +132,7 @@ const os = () => {
131
132
  isIos: isPhone || isPad,
132
133
  };
133
134
  };
135
+ // 乘
134
136
  const accMul = (arg1, arg2) => {
135
137
  let m = 0, s1 = arg1.toString(), s2 = arg2.toString();
136
138
  try {
@@ -143,6 +145,7 @@ const accMul = (arg1, arg2) => {
143
145
  catch (e) { }
144
146
  return (Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) / Math.pow(10, m);
145
147
  };
148
+ // 除
146
149
  const accDiv = (arg1, arg2) => {
147
150
  let t1 = 0, t2 = 0, r1, r2;
148
151
  try {
@@ -157,6 +160,7 @@ const accDiv = (arg1, arg2) => {
157
160
  r2 = Number(arg2.toString().replace('.', ''));
158
161
  return (r1 / r2) * Math.pow(10, t2 - t1);
159
162
  };
163
+ // 加
160
164
  const accAdd = (arg1, arg2) => {
161
165
  let r1, r2, m;
162
166
  try {
@@ -174,6 +178,7 @@ const accAdd = (arg1, arg2) => {
174
178
  m = Math.pow(10, Math.max(r1, r2));
175
179
  return (arg1 * m + arg2 * m) / m;
176
180
  };
181
+ // 减
177
182
  const accSub = function (arg1, arg2) {
178
183
  let r1, r2, m, n;
179
184
  try {
@@ -271,6 +276,11 @@ const FORMAT_DATE = SERVER_DATE_FROMAT;
271
276
  const FORMAT_TIME = 'YYYY-MM-DD HH:mm:ss';
272
277
  const format10k = (n) => formatCash(n / 10000);
273
278
  const format10kNil = withDefaultNil(format10k);
279
+ const formatBillion = (num) => {
280
+ const isBillion = num / (10000 * 10000) >= 1;
281
+ const unit = isBillion ? '亿' : '万';
282
+ return `${isBillion ? formatCash(num / (10000 * 10000)) : formatCash(num / 10000)}${unit}`;
283
+ };
274
284
  // null == undefined
275
285
  const isNil = (val) => val == null || val === '';
276
286
  const NIL_STRING = '——';
@@ -577,6 +587,7 @@ exports.fileReaderToBase64 = fileReaderToBase64;
577
587
  exports.filterNil = filterNil;
578
588
  exports.format10k = format10k;
579
589
  exports.format10kNil = format10kNil;
590
+ exports.formatBillion = formatBillion;
580
591
  exports.formatCash = formatCash;
581
592
  exports.formatCash2 = formatCash2;
582
593
  exports.formatCashInt = formatCashInt;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("qs"),t=require("dayjs"),o=require("d3-format");function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var s=r(t);const n=(...e)=>{console.group("====================="),console.info(...e),console.groupEnd()},a="undefined"!=typeof window,i=e=>Array.isArray(e),c=e=>e&&"number"==typeof e.size&&"string"==typeof e.type&&"function"==typeof e.slice,l=(e,t="children")=>{if(!i(e))return[];for(const o of e)o[t]&&o[t].length&&(o.children=[...o[t]],null==o||delete o.childList,l(o.children,t));return e},d=a?localStorage:{};let p={};const u=o.format(",.2f"),h=o.format(","),m=o.format(".2%"),f=w(u),x=w(h),g=w(m);function w(e){return t=>b(t)?v:e(t)}const y=e=>u(e/1e4),M=w(y),b=e=>null==e||""===e,v="——";function S(e,t="YYYY-MM-DD"){return s(new Date(e)).format(t)}const D=w(S),T={d:"天",m:"个月",y:"年"};function A(e){return e?`${parseInt(e,10)}${T[e.slice(-1).toLowerCase()]}`:e}const k=w(A);exports.DATE_FORMAT="YYYY/MM/DD",exports.FORMAT_DATE="YYYY-MM-DD",exports.FORMAT_TIME="YYYY-MM-DD HH:mm:ss",exports.NIL_STRING=v,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",(()=>{n("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.filterNil=e=>{const t={};return Object.entries(e).forEach((([e,o])=>{o&&0!==o&&(t[e]=o)})),t},exports.format10k=y,exports.format10kNil=M,exports.formatCash=u,exports.formatCash2=e=>(Math.floor(100*e)/100).toFixed(2),exports.formatCashInt=h,exports.formatCashIntNil=x,exports.formatCashNil=f,exports.formatDate=S,exports.formatDateNil=D,exports.formatDuration=A,exports.formatDurationNil=k,exports.formatRatio=m,exports.formatRatioNil=g,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=>((p[e]||d.getItem(""+e))&&(p[e]=d.getItem(""+e)?JSON.parse(d.getItem(""+e)||"null"):""),p[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=>b(e)?v:e,exports.inBrowser=a,exports.isArray=i,exports.isBlob=c,exports.isCardNo=e=>/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/.test(e),exports.isDate=e=>!!e&&s(e).isValid(),exports.isEmail=e=>/^(.+)@(.+)\.(.+)$/.test(e),exports.isFile=e=>c(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=b,exports.isNull=e=>null===e,exports.isNumber=e=>/^[0-9]*(.[0-9]*)?$/.test(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=n,exports.loopData=l,exports.os=()=>{if(!a)return{isTablet:!1,isPhone:!1,isAndroid:!1,isPc:!1,isIos:!1,isPad:!1};const e=navigator.userAgent,t=/(?:Windows Phone)/.test(e),o=/(?:SymbianOS)/.test(e)||t,r=/(?:Android)/.test(e),s=/(?:Firefox)/.test(e),n=/(?:iPad|PlayBook)/.test(e)||r&&!/(?:Mobile)/.test(e)||s&&/(?:Tablet)/.test(e),i=/(?:iPhone)/.test(e)&&!n,c=/(?:iPad)/.test(e)&&!n;return{isTablet:n,isPhone:i,isAndroid:r,isPc:!i&&!r&&!o,isPad:c,isIos:i||c}},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=()=>(p={},d.clear()),exports.removeItem=e=>(delete p[e],d.removeItem(""+e)),exports.setItem=(e,t)=>(p[e]=t,d.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
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("qs"),t=require("dayjs"),o=require("d3-format");function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var s=r(t);const n=(...e)=>{console.group("====================="),console.info(...e),console.groupEnd()},i="undefined"!=typeof window,a=e=>Array.isArray(e),c=e=>e&&"number"==typeof e.size&&"string"==typeof e.type&&"function"==typeof e.slice,l=(e,t="children")=>{if(!a(e))return[];for(const o of e)o[t]&&o[t].length&&(o.children=[...o[t]],null==o||delete o.childList,l(o.children,t));return e},d=i?localStorage:{};let p={};const u=o.format(",.2f"),h=o.format(","),m=o.format(".2%"),f=w(u),x=w(h),g=w(m);function w(e){return t=>b(t)?v:e(t)}const y=e=>u(e/1e4),M=w(y),b=e=>null==e||""===e,v="——";function S(e,t="YYYY-MM-DD"){return s(new Date(e)).format(t)}const D=w(S),T={d:"天",m:"个月",y:"年"};function A(e){return e?`${parseInt(e,10)}${T[e.slice(-1).toLowerCase()]}`:e}const k=w(A);exports.DATE_FORMAT="YYYY/MM/DD",exports.FORMAT_DATE="YYYY-MM-DD",exports.FORMAT_TIME="YYYY-MM-DD HH:mm:ss",exports.NIL_STRING=v,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",(()=>{n("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(i){}try{n=t.toString().split(".")[1].length}catch(i){}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(i){o=0}try{r=t.toString().split(".")[1].length}catch(i){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="",i=0;i<t.length;i++)n+=(o[Math.floor(10*e*Math.pow(10,i))%10]+t[i]).replace(/零./,"");for(n=n||"整",e=Math.floor(e),i=0;i<r[0].length&&e>0;i++){for(var a="",c=0;c<r[1].length&&e>0;c++)a=o[e%10]+r[1][c]+a,e=Math.floor(e/10);n=a.replace(/(零.)*零$/,"").replace(/^$/,"零")+r[0][i]+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,i=e;const a=document,c=a.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...",a.body.appendChild(c),setTimeout((()=>{c.click(),a.body.removeChild(c),!0===o&&setTimeout((()=>{s.URL.revokeObjectURL(c.href)}),250)}),66),!0;const n=a.createElement("iframe");a.body.appendChild(n),o||(t="data:"+t.replace(/^data:([\w\/\-\+]+)/,"application/octet-stream")),n.src=t,setTimeout((()=>{a.body.removeChild(n)}),333)};if(String(i).match(/^data\:[\w+\-]+\/[\w+\-]+[,;]/))return m(i);try{u=i instanceof d?i:new d([i],{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.filterNil=e=>{const t={};return Object.entries(e).forEach((([e,o])=>{o&&0!==o&&(t[e]=o)})),t},exports.format10k=y,exports.format10kNil=M,exports.formatBillion=e=>{const t=e/1e8>=1,o=t?"亿":"万";return`${u(t?e/1e8:e/1e4)}${o}`},exports.formatCash=u,exports.formatCash2=e=>(Math.floor(100*e)/100).toFixed(2),exports.formatCashInt=h,exports.formatCashIntNil=x,exports.formatCashNil=f,exports.formatDate=S,exports.formatDateNil=D,exports.formatDuration=A,exports.formatDurationNil=k,exports.formatRatio=m,exports.formatRatioNil=g,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=>((p[e]||d.getItem(""+e))&&(p[e]=d.getItem(""+e)?JSON.parse(d.getItem(""+e)||"null"):""),p[e]),exports.getQueryObject=(t=window.location.href)=>{var o;const r=null===(o=t.split("?"))||void 0===o?void 0:o[1];return e.parse(r||"",{decoder:e=>e})},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=>b(e)?v:e,exports.inBrowser=i,exports.isArray=a,exports.isBlob=c,exports.isCardNo=e=>/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/.test(e),exports.isDate=e=>!!e&&s(e).isValid(),exports.isEmail=e=>/^(.+)@(.+)\.(.+)$/.test(e),exports.isFile=e=>c(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=b,exports.isNull=e=>null===e,exports.isNumber=e=>/^[0-9]*(.[0-9]*)?$/.test(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=n,exports.loopData=l,exports.os=()=>{if(!i)return{isTablet:!1,isPhone:!1,isAndroid:!1,isPc:!1,isIos:!1,isPad:!1};const e=navigator.userAgent,t=/(?:Windows Phone)/.test(e),o=/(?:SymbianOS)/.test(e)||t,r=/(?:Android)/.test(e),s=/(?:Firefox)/.test(e),n=/(?:iPad|PlayBook)/.test(e)||r&&!/(?:Mobile)/.test(e)||s&&/(?:Tablet)/.test(e),a=/(?:iPhone)/.test(e)&&!n,c=/(?:iPad)/.test(e)&&!n;return{isTablet:n,isPhone:a,isAndroid:r,isPc:!a&&!r&&!o,isPad:c,isIos:a||c}},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=()=>(p={},d.clear()),exports.removeItem=e=>(delete p[e],d.removeItem(""+e)),exports.setItem=(e,t)=>(p[e]=t,d.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,"");
@@ -67,6 +67,7 @@ const isFile = (value) => isBlob(value) &&
67
67
  typeof value.name === 'string' &&
68
68
  (typeof value.lastModifiedDate === 'object' || typeof value.lastModified === 'number');
69
69
  const getQueryObject = (url = window.location.href) => {
70
+ var _a;
70
71
  // const search = url.substring(url.lastIndexOf('?') + 1)
71
72
  // let obj: any = {}
72
73
  // const reg = /([^?&=]+)=([^?&=]*)/g
@@ -79,8 +80,8 @@ const getQueryObject = (url = window.location.href) => {
79
80
  // obj[name] = val
80
81
  // return rs
81
82
  // })
82
- const search = url.split('?')[1];
83
- return parse(search || '');
83
+ const search = (_a = url.split('?')) === null || _a === void 0 ? void 0 : _a[1];
84
+ return parse(search || '', { decoder: str => str });
84
85
  };
85
86
  const getSearchParams = (search) => new URLSearchParams(search);
86
87
  const fileReaderToBase64 = (target) => (cb) => {
@@ -123,6 +124,7 @@ const os = () => {
123
124
  isIos: isPhone || isPad,
124
125
  };
125
126
  };
127
+ // 乘
126
128
  const accMul = (arg1, arg2) => {
127
129
  let m = 0, s1 = arg1.toString(), s2 = arg2.toString();
128
130
  try {
@@ -135,6 +137,7 @@ const accMul = (arg1, arg2) => {
135
137
  catch (e) { }
136
138
  return (Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) / Math.pow(10, m);
137
139
  };
140
+ // 除
138
141
  const accDiv = (arg1, arg2) => {
139
142
  let t1 = 0, t2 = 0, r1, r2;
140
143
  try {
@@ -149,6 +152,7 @@ const accDiv = (arg1, arg2) => {
149
152
  r2 = Number(arg2.toString().replace('.', ''));
150
153
  return (r1 / r2) * Math.pow(10, t2 - t1);
151
154
  };
155
+ // 加
152
156
  const accAdd = (arg1, arg2) => {
153
157
  let r1, r2, m;
154
158
  try {
@@ -166,6 +170,7 @@ const accAdd = (arg1, arg2) => {
166
170
  m = Math.pow(10, Math.max(r1, r2));
167
171
  return (arg1 * m + arg2 * m) / m;
168
172
  };
173
+ // 减
169
174
  const accSub = function (arg1, arg2) {
170
175
  let r1, r2, m, n;
171
176
  try {
@@ -263,6 +268,11 @@ const FORMAT_DATE = SERVER_DATE_FROMAT;
263
268
  const FORMAT_TIME = 'YYYY-MM-DD HH:mm:ss';
264
269
  const format10k = (n) => formatCash(n / 10000);
265
270
  const format10kNil = withDefaultNil(format10k);
271
+ const formatBillion = (num) => {
272
+ const isBillion = num / (10000 * 10000) >= 1;
273
+ const unit = isBillion ? '亿' : '万';
274
+ return `${isBillion ? formatCash(num / (10000 * 10000)) : formatCash(num / 10000)}${unit}`;
275
+ };
266
276
  // null == undefined
267
277
  const isNil = (val) => val == null || val === '';
268
278
  const NIL_STRING = '——';
@@ -551,4 +561,4 @@ function copyToClipboard(txt) {
551
561
  document.body.removeChild(textarea);
552
562
  }
553
563
 
554
- export { DATE_FORMAT, FORMAT_DATE, FORMAT_TIME, NIL_STRING, WS, accAdd, accDiv, accMul, accSub, copyToClipboard, cutTimeFn, digitCnUppercase, disableBrowserZoom, download, fileReaderToBase64, filterNil, 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, isNumber, isObject, isPhone, isSMSCode, isUndefined, isWX, log, loopData, os, playAudio, random, randomString, removeAll, removeItem, setItem, setProxyObj, sortObj, sumObj, trimString };
564
+ export { DATE_FORMAT, FORMAT_DATE, FORMAT_TIME, NIL_STRING, WS, accAdd, accDiv, accMul, accSub, copyToClipboard, cutTimeFn, digitCnUppercase, disableBrowserZoom, download, fileReaderToBase64, filterNil, format10k, format10kNil, formatBillion, 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, isNumber, isObject, isPhone, isSMSCode, isUndefined, isWX, log, loopData, 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.29",
3
+ "version": "1.3.30",
4
4
  "description": "lgutils",
5
5
  "main": "index.js",
6
6
  "module": "lib/lgutils.cjs.prod.js",
@@ -32,5 +32,5 @@
32
32
  "@types/d3-format": "^1.3.1",
33
33
  "@types/qs": "^6.9.0"
34
34
  },
35
- "gitHead": "7b527315e697c56fbf69533983df0a643b3dfa4f"
35
+ "gitHead": "fcb0bd0756b9444889983a51a85037156822c507"
36
36
  }