UNPKG

fuyao-web-utils

Version:
2 lines (1 loc) 4.86 kB
var r=function(){return r=Object.assign||function(r){for(var t,n=1,e=arguments.length;n<e;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o]);return r},r.apply(this,arguments)};function t(r,t){var n={};for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&t.indexOf(e)<0&&(n[e]=r[e]);if(null!=r&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(e=Object.getOwnPropertySymbols(r);o<e.length;o++)t.indexOf(e[o])<0&&Object.prototype.propertyIsEnumerable.call(r,e[o])&&(n[e[o]]=r[e[o]])}return n}"function"==typeof SuppressedError&&SuppressedError;var n=Object.prototype.toString,e=function(r,t){return function(r){return n.call(r).slice(8,-1).toLowerCase()}(r)===t},o={isNull:function(r){return null===r},isEmpty:function(r,t){void 0===t&&(t=!1);var n=function(r,t,n){if(n||2===arguments.length)for(var e,o=0,i=t.length;o<i;o++)!e&&o in t||(e||(e=Array.prototype.slice.call(t,0,o)),e[o]=t[o]);return r.concat(e||Array.prototype.slice.call(t))}([null,void 0,"",NaN],t?["null","undefined","NaN"]:[],!0);return n.includes(r)},isEmptyObject:function(r){return o.isEmpty(r)||o.isArray(r)&&!r.length||o.isPlainObject(r)&&!Object.keys(r).length},isArray:function(r){return Array.isArray(r)},isPlainObject:function(r){return e(r,"object")}},i=function(r,t,n){return r>=Math.pow(10,t)&&Math.round(r/Math.pow(10,t-n))/Math.pow(10,n)},c={isNumber:function(r){return"number"==typeof r&&!isNaN(r)},toNumber:function(r,t){void 0===t&&(t=0);var n=Number(r);return isNaN(n)?t:n},fixedNumber:function(r,t){return void 0===t&&(t=0),(Math.round(Number(r)*Math.pow(10,t))/Math.pow(10,t)).toFixed(t)},parseThousands:function(r){if(o.isEmpty(r))return"";var t="".concat(r).split("."),n=t[0],e=void 0===n?"0":n,i=t[1];return[e.replace(/(\d)(?=(?:\d{3})+$)/g,"$1,"),i].filter((function(r){return!o.isEmpty(r)})).join(".")},format:function(r,t,n){void 0===t&&(t=2),void 0===n&&(n=!1);var e=i(r,8,t);return e?(n?e.toFixed(t):e)+"亿":(e=i(r,4,t))?(n?e.toFixed(t):e)+"万":"".concat(r)},cn:function(r,t){if(Number(r)!=Number(r))return"".concat(null!=r?r:"");var n,e=!0===t?{traditional:!0,money:!0}:t||{},o=e.traditional,i=void 0!==o&&o,c=e.money,u=void 0!==c&&c,a="".concat(r).split("."),p=a[0],f=a[1],l=void 0===f?"":f,s=p.replace(/(\d)(?=(?:\d{4})+$)/g,"$1_").split("_"),y=(void 0===(n=i)&&(n=!1),{units:["","万","亿","万亿","亿亿"],decimalisms:n?["","拾","佰","仟"]:["","十","百","千"],integers:n?"零壹贰叁肆伍陆柒捌玖":"零一二三四五六七八九"}),d=y.units,v=y.integers,m=y.decimalisms,b=function(r){return v.charAt(Number(r))},h=s.reverse().map((function(r,t){var n=r.split("").map((function(t,n){return"0"===t?"零":b(t)+m[r.length-n-1]})).join("").replace(/\u96f6+$/,"").replace(/\u96f6+/g,"零");return n.length?n+d[t]:d[t]?"零":""})).reverse().join("").replace(/\u96f6+$/,"").replace(/\u96f6+/g,"零");if(u){if(!l.length||/^0+$/.test(l))return"".concat(h,"圆整");var g=l.split(""),O=g[0],j=void 0===O?"0":O,N=g[1],K=void 0===N?"0":N;return"".concat(h,"圆").concat("0"===j?"零":b(j)+"角").concat("0"===K?"":b(K)+"分")}var E=/^0+$/.test(l)?"":l.split("").map((function(r){return v.charAt(Number(r))})).join("");return E?"".concat(h,"点").concat(E):h}},u={transToTree:function(n,e,i){var c,u=e||{},a=u.key,p=void 0===a?"key":a,f=u.pKey,l=void 0===f?"pKey":f,s=u.rootKey,y=u.childrenKey,d=void 0===y?"children":y,v=u.parentKey,m=void 0===v?"parent":v,b=u.copy,h=void 0===b||b,g=u.assign,O=void 0===g||g,j=u.transKey,N=void 0!==j&&j,K=t(u,["key","pKey","rootKey","childrenKey","parentKey","copy","assign","transKey"]),E=function(){var t,n=h?function(t){return r({},t)}:function(r){return r};return N&&"key"!==p&&(K.key=p),N&&"pKey"!==l&&(K.pKey=p),o.isEmptyObject(K)?n:(t=Object.keys(K),function(r){return t.forEach((function(t,n){r[t]=r[K[t]]})),n(r)})}(),A=O?"function"==typeof Object.defineProperty?function(r,t){Object.defineProperty(r,m,{get:function(){return t},configurable:!1,enumerable:!1})}:function(r,t){r.getParent=function(){return t}}:function(r,t){},P="__root__",w=((c={})[P]=[],c),k={},M={},$=function(r){return!r&&0!==r};(Array.isArray(n)?n:[]).map((function(t){var n=E(t),e=n[l],o=n[p];return k[o]=r({},n),M[o]=n,$(e)?w[P].push(n):w[e]?w[e].push(n):w[e]=[n],n})).forEach((function(r){r[d]=w[r[p]],delete w[r[p]];var t=r[l];A(r,$(t)?null:M[t])}));var x=w,_=P,S=x[_],F=t(x,[_+""]),I="function"==typeof e?e:"function"==typeof i?i:void 0;return I&&I(M,k),o.isEmpty(s)?S.concat.apply(S,Object.values(F)):w[s]||[]},transItemProps:function(r,t){var n=t.keyMap,e=t.recursive,i=void 0===e||e,c=t.childrenKey,a=void 0===c?"children":c,p=t.delOriginalKey,f=void 0===p||p;return r.map((function(r){Object.keys(n).forEach((function(t){r[t]=r[n[t]],f&&delete r[n[t]]}));var e=r[a];return i&&o.isArray(e)&&(r[a]=u.transItemProps(e,t)),r}))}};export{u as ArrayUtil,c as NumberUtil,o as TypeUtil};