UNPKG

native-lodash

Version:
2 lines (1 loc) 8.46 kB
const t=t=>navigator.clipboard.writeText(t),e=t=>{if(!O(t))return t;if(Array.isArray(t))return t.map((t=>e(t)));if(P(t)){const n={};return Object.keys(t).forEach((r=>{n[r]=e(t[r])})),n}return t},n=(t,e=0,n=!1)=>{let r,o=!1;return function(...i){r&&clearTimeout(r),n&&!o?(Reflect.apply(t,this,i),o=!0):r=setTimeout((()=>{Reflect.apply(t,this,i),o=!1}),e)}};function r(t,e=0,...n){if(!H(t))throw new TypeError("Expected a function");return setTimeout(t,e,...n)}function o(t=0){return new Promise((e=>{setTimeout(e,t)}))}function i(t,e=3,n=4,r="*"){if(!t)return t;const o=new RegExp(`^(.{${e}})(.*)(.{${n}})$`);return String(t).replace(o,((t,e,n,o)=>e+r.repeat(n.length)+o))}function c(t,e){const n=document.createElement("a");n.style.display="none",n.setAttribute("href",t),n.setAttribute("download",e||"");const r=Math.random().toString(36).slice(2);n.id=r,document.body.append(n),n.click(),n.remove()}function s(t,e){const n=new Image;n.setAttribute("crossOrigin","anonymous"),n.addEventListener("load",(()=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const r=t.getContext("2d");null==r||r.drawImage(n,0,0,n.width,n.height);const o=t.toDataURL("image/png"),i=document.createElement("a"),c=new MouseEvent("click");i.download=e||"photo",i.href=o,i.dispatchEvent(c)})),n.src=t}function a(t,e){return t===e||t!=t&&e!=e}const u=t=>t.flatMap((t=>Array.isArray(t)?u(t):t));function l(){const t=window.navigator.userAgent.toLowerCase();return/iphone|ipod|ipad/i.test(t)?"ios":/android/i.test(t)?"android":/micromessenger/i.test(t)?"wechat":/micromessenger/i.test(t)&&/wxwork/i.test(t)?"wxwork":/micromessenger/i.test(t)&&/miniprogram/i.test(t)?"wxmini":/dingtalk/i.test(t)?"dingding":/lark/i.test(t)?"feishu":/applewebkit.*mobile.*/gi.test(t)?"mobile":void 0}function f(t){const e=(t=t||decodeURIComponent(window.location.href)).slice(Math.max(0,t.indexOf("?")+1)).split("&"),n={};for(let t=0,r=e.length;t<r;t++){const r=e[t].indexOf("=");if(-1===r)continue;const o=e[t].slice(0,Math.max(0,r)),i=window.decodeURIComponent(e[t].slice(Math.max(0,r+1)));n[o]=i}return n}function d(t,e){const n=new RegExp(`(^|&)${t}=([^&]*)(&|$)`);let r=null;return r=e?e.split("?")[1].match(n):window.location.search.slice(1).match(n),null!=r?decodeURIComponent(r[2]):null}function p(t,e){return t.reduce(((t,n)=>{const r=n[e];return t[r]||(t[r]=[]),t[r].push(n),t}),{})}function g(t=32,e="u",n=62){const r="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),o=[];if(t)for(let e=0;e<t;e++)o[e]=r[0|Math.random()*n];else{let t;o[8]=o[13]=o[18]=o[23]="-",o[14]="4";for(let e=0;e<36;e++)o[e]||(t=0|16*Math.random(),o[e]=r[19===e?3&t|8:t])}return e?(o.shift(),`${e}${o.join("")}`):o.join("")}const h=Object.prototype.hasOwnProperty,m=(t,e)=>{const n=e.split(".");return!!t&&(n.length>1?m(t[e.split(".")[0]],n.slice(1).join(".")):h.call(t,e))};function w(t){return T(t)||P(t)}function b(t,e){if(!w(t)||!w(e))return t===e;if(t===e)return!0;const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(const n in t){if(!b(t[n],e[n]))return!1}return!0}function y(t,e=15){return+parseFloat(Number(t).toPrecision(e))}function $(t){const e=t.toString().split(/[Ee]/),n=(e[0].split(".")[1]||"").length-+(e[1]||0);return n>0?n:0}function S(t){if(!t.toString().includes("e"))return Number(t.toString().replace(".",""));const e=$(t);return e>0?y(Number(t)*10**e):Number(t)}function A(t){(Number(t)>Number.MAX_SAFE_INTEGER||Number(t)<Number.MIN_SAFE_INTEGER)&&console.warn(`${t} 超出了精度限制,结果可能不正确`)}function E(t,e){const[n,r,...o]=t;let i=e(n,r);return o.forEach((t=>{i=e(i,t)})),i}function k(...t){if(t.length>2)return E(t,k);const[e,n]=t,r=S(e),o=S(n),i=$(e)+$(n),c=r*o;return A(c),c/10**i}function j(...t){if(t.length>2)return E(t,j);const[e,n]=t,r=S(e),o=S(n);return A(r),A(o),k(r/o,y(10**($(n)-$(e))))}function x(t,e=0){t=`${t}`.replace(/[^\d+-Ee]/g,"");const n=isFinite(+t)?+t:0,r=isFinite(+e)?Math.abs(e):0;let o=[];o=(r?`${function(t,e){const n=10**e;let r=j(Math.round(Math.abs(k(t,n))),n);return t<0&&0!==r&&(r=k(r,-1)),r}(n,r)}`:`${Math.round(n)}`).split(".");const i=/(-?\d+)(\d{3})/;for(;i.test(o[0]);)o[0]=o[0].replace(i,"$1,$2");return(o[1]||"").length<r&&(o[1]=o[1]||"",o[1]+=Array.from({length:r-o[1].length+1}).join("0")),o.join(".")}function M(t,e){if(!P(t))return{};R(e)&&(e=[e]);const n=Object.keys(t),r={};for(const o of n){const n=t[o];e&&e.includes(o)||(r[o]=n)}return r}function N(t={},e=!0,n="brackets"){const r=e?"?":"",o=[];["indices","brackets","repeat","comma"].includes(n)||(n="brackets");for(const e in t){const r=t[e];if(O(r))if(Array.isArray(r))switch(n){case"indices":for(const[t,n]of r.entries())o.push(`${e}[${t}]=${n}`);break;case"brackets":r.forEach((t=>{o.push(`${e}[]=${t}`)}));break;case"repeat":r.forEach((t=>{o.push(`${e}=${t}`)}));break;case"comma":let t="";r.forEach((e=>{t+=(t?",":"")+e})),o.push(`${e}=${t}`)}else o.push(`${e}=${r}`)}return o.length>0?r+o.join("&"):""}const O=t=>null!=t;function I(t){return/^\w+((-\w+)|(\.\w+))*@[\dA-Za-z]+(([.-])[\dA-Za-z]+)*\.[\dA-Za-z]+$/.test(t)}function D(t){return/^1[3-9]\d{9}$/.test(String(t))}function R(t){return null!=t&&"string"==typeof t.valueOf()}function v(t){return/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0-2|]\d)|3[01])\d{3}(\d|X)$/.test(t)}function Z(t){const e=/^[A-Z云京使冀吉宁川新晋桂沪津浙渝湘琼甘皖粤苏蒙藏豫贵赣辽鄂闽陕青领鲁黑][A-Z]((\d{5}[DF]$)|([DF][\dA-HJ-NP-Z]\d{4}$))/,n=/^[A-Z云京使冀吉宁川新晋桂沪津浙渝湘琼甘皖粤苏蒙藏豫贵赣辽鄂闽陕青领鲁黑][A-Z][\dA-HJ-NP-Z]{4}[\dA-HJ-NP-Z学挂港澳警]$/;return 7===t.length?n.test(t):8===t.length&&e.test(t)}function F(t){return""===t||t.constructor===Object&&0===Object.keys(t).length||Array.isArray(t)&&0===t.length}function T(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)}function P(t){return"[object Object]"===Object.prototype.toString.call(t)}function C(t,e=6){return new RegExp(`^\\d{${e}}$`).test(t)}const H=t=>"function"==typeof t,U=t=>!0===t||"true"===t,z=t=>/^((ht|f)tps?):\/\/?/.test(t),J="undefined"!=typeof window,L=(t,e=0)=>{let n=0;return function(...r){Date.now()-n>e&&(Reflect.apply(t,this,r),n=Date.now())}};function _(t,e="yyyy-mm-dd"){let n;n=t?/^\d{10}$/.test(null==t?void 0:t.toString().trim())?new Date(1e3*+t):"string"==typeof t&&/^\d+$/.test(t.trim())?new Date(Number(t)):"string"==typeof t&&t.includes("-")&&!t.includes("T")?new Date(t.replace(/-/g,"/")):new Date(t):new Date;const r={y:n.getFullYear().toString(),m:(n.getMonth()+1).toString().padStart(2,"0"),d:n.getDate().toString().padStart(2,"0"),h:n.getHours().toString().padStart(2,"0"),M:n.getMinutes().toString().padStart(2,"0"),s:n.getSeconds().toString().padStart(2,"0")};return Object.keys(r).forEach((t=>{const[n]=new RegExp(`${t}+`).exec(e)||[];if(n){const o="y"===t&&2===n.length?2:0;e=e.replace(n,r[t].slice(o))}})),e}function G(t,e=""){t||(t=Date.now()),10===(t=parseInt(String(t))).toString().length&&(t*=1e3);let n=Date.now()-t;n=parseInt(String(n/1e3));let r="";switch(!0){case n<60:r="刚刚";break;case n>=60&&n<3600:r=`${parseInt(String(n/60))}分钟前`;break;case n>=3600&&n<86400:r=`${parseInt(String(n/3600))}小时前`;break;case n>=86400&&n<172800:r="昨天";break;case n>=172800&&n<2592e3:r=`${parseInt(String(n/86400))}天前`;break;default:r=e?_(t,e):n>=2592e3&&n<31536e3?`${parseInt(String(n/2592e3))}个月前`:`${parseInt(String(n/31536e3))}年前`}return r}function X(t,e=2){const n=10**e;return(Math.round(Number(t)*n)/n).toFixed(e)}function Y(t,e="both"){return t=String(t),"both"===e?t.replace(/^\s+|\s+$/g,""):"left"===e?t.replace(/^\s*/,""):"right"===e?t.replace(/(\s*$)/g,""):"all"===e?t.replace(/\s+/g,""):t}function q(t,e){if(!e)return[...new Set(t)];const n=R(e)?t=>t[e]:e;return t.reduce(((t,e)=>(t.some((t=>n(t)===n(e)))||t.push(e),t)),[])}export{t as clipboard,e as cloneDeep,n as debounce,r as delay,i as desensitize,c as download,s as downloadImage,a as eq,u as flattenDeep,l as getUa,f as getUrlAllParams,d as getUrlParams,p as groupBy,g as guid,m as has,J as inBrowser,T as isArray,Z as isCarNo,C as isCode,O as isDef,I as isEmail,F as isEmpty,b as isEqual,H as isFunction,v as isIdCard,D as isMobile,P as isObject,R as isString,U as isTrue,z as isURL,o as later,x as moneyFormat,M as omit,N as queryParams,L as throttle,_ as timeFormat,G as timeFrom,X as toFixed,Y as trim,q as uniqBy};