You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
6.4 KiB

"use strict";const u=require("../../common/vendor.js"),a=require("./test.js"),b=require("./digit.js");function S(e=0,n=0,t=0){return Math.max(e,Math.min(n,Number(t)))}function I(e,n=!1){return a.test.number(e)?n?`${e}px`:Number(e):/(rpx|upx)$/.test(e)?n?`${u.index.upx2px(parseInt(e))}px`:Number(u.index.upx2px(parseInt(e))):n?`${parseInt(e)}px`:parseInt(e)}function $(e=30){return new Promise(n=>{setTimeout(()=>{n()},e)})}function M(){return u.index.getSystemInfoSync().platform.toLowerCase()}function k(){return u.index.getSystemInfoSync()}function D(e,n){if(e>=0&&n>0&&n>=e){const t=n-e+1;return Math.floor(Math.random()*t+e)}return 0}function N(e=32,n=!0,t=null){const i="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),r=[];if(t=t||i.length,e)for(let s=0;s<e;s++)r[s]=i[0|Math.random()*t];else{let s;r[8]=r[13]=r[18]=r[23]="-",r[14]="4";for(let o=0;o<36;o++)r[o]||(s=0|Math.random()*16,r[o]=i[o==19?s&3|8:s])}return n?(r.shift(),`u${r.join("")}`):r.join("")}function y(e=void 0){let n=this.$parent;for(;n;)if(n.$options&&n.$options.name!==e)n=n.$parent;else return n;return!1}function w(e,n="object"){if(a.test.empty(e)||typeof e=="object"&&n==="object"||n==="string"&&typeof e=="string")return e;if(n==="object"){e=p(e);const i=e.split(";"),r={};for(let s=0;s<i.length;s++)if(i[s]){const o=i[s].split(":");r[p(o[0])]=p(o[1])}return r}let t="";for(const i in e){const r=i.replace(/([A-Z])/g,"-$1").toLowerCase();t+=`${r}:${e[i]};`}return p(t)}function O(e="auto",n="px"){return e=String(e),a.test.number(e)?`${e}${n}`:e}function h(e){if([null,void 0,NaN,!1].includes(e)||typeof e!="object"&&typeof e!="function")return e;const n=a.test.array(e)?[]:{};for(const t in e)e.hasOwnProperty(t)&&(n[t]=typeof e[t]=="object"?h(e[t]):e[t]);return n}function g(e={},n={}){if(e=h(e),typeof e!="object"||typeof n!="object")return!1;for(const t in n)n.hasOwnProperty(t)&&(t in e?typeof e[t]!="object"||typeof n[t]!="object"?e[t]=n[t]:e[t].concat&&n[t].concat?e[t]=e[t].concat(n[t]):e[t]=g(e[t],n[t]):e[t]=n[t]);return e}function P(e){console.error(`SheepJS:${e}`)}function m(e=[]){return e.sort(()=>Math.random()-.5)}String.prototype.padStart||(String.prototype.padStart=function(e,n=" "){if(Object.prototype.toString.call(n)!=="[object String]")throw new TypeError("fillString must be String");const t=this;if(t.length>=e)return String(t);const i=e-t.length;let r=Math.ceil(i/n.length);for(;r>>=1;)n+=n,r===1&&(n+=n);return n.slice(0,i)+t});function x(e=null,n="yyyy-mm-dd"){let t;e?/^\d{10}$/.test(e==null?void 0:e.toString().trim())?t=new Date(e*1e3):typeof e=="string"&&/^\d+$/.test(e.trim())?t=new Date(Number(e)):t=new Date(typeof e=="string"?e.replace(/-/g,"/"):e):t=new Date;const i={y:t.getFullYear().toString(),m:(t.getMonth()+1).toString().padStart(2,"0"),d:t.getDate().toString().padStart(2,"0"),h:t.getHours().toString().padStart(2,"0"),M:t.getMinutes().toString().padStart(2,"0"),s:t.getSeconds().toString().padStart(2,"0")};for(const r in i){const[s]=new RegExp(`${r}+`).exec(n)||[];if(s){const o=r==="y"&&s.length===2?2:0;n=n.replace(s,i[r].slice(o))}}return n}function E(e=null,n="yyyy-mm-dd"){e==null&&(e=Number(new Date)),e=parseInt(e),e.toString().length==10&&(e*=1e3);let t=new Date().getTime()-e;t=parseInt(t/1e3);let i="";switch(!0){case t<300:i="刚刚";break;case(t>=300&&t<3600):i=`${parseInt(t/60)}分钟前`;break;case(t>=3600&&t<86400):i=`${parseInt(t/3600)}小时前`;break;case(t>=86400&&t<2592e3):i=`${parseInt(t/86400)}天前`;break;default:n===!1?t>=2592e3&&t<365*86400?i=`${parseInt(t/(86400*30))}个月前`:i=`${parseInt(t/(86400*365))}年前`:i=x(e,n)}return i}function p(e,n="both"){return e=String(e),n=="both"?e.replace(/^\s+|\s+$/g,""):n=="left"?e.replace(/^\s*/,""):n=="right"?e.replace(/(\s*$)/g,""):n=="all"?e.replace(/\s+/g,""):e}function C(e={},n=!0,t="brackets"){const i=n?"?":"",r=[];["indices","brackets","repeat","comma"].indexOf(t)==-1&&(t="brackets");for(const s in e){const o=e[s];if(!(["",void 0,null].indexOf(o)>=0))if(o.constructor===Array)switch(t){case"indices":for(let c=0;c<o.length;c++)r.push(`${s}[${c}]=${o[c]}`);break;case"brackets":o.forEach(c=>{r.push(`${s}[]=${c}`)});break;case"repeat":o.forEach(c=>{r.push(`${s}=${c}`)});break;case"comma":let f="";o.forEach(c=>{f+=(f?",":"")+c}),r.push(`${s}=${f}`);break;default:o.forEach(c=>{r.push(`${s}[]=${c}`)})}else r.push(`${s}=${o}`)}return r.length?i+r.join("&"):""}function l(e,n=2e3){u.index.showToast({title:String(e),icon:"none",duration:n})}function A(e="success",n=!1){["primary","info","error","warning","success"].indexOf(e)==-1&&(e="success");let t="";switch(e){case"primary":t="info-circle";break;case"info":t="info-circle";break;case"error":t="close-circle";break;case"warning":t="error-circle";break;case"success":t="checkmark-circle";break;default:t="checkmark-circle"}return n&&(t+="-fill"),t}function F(e,n=0,t=".",i=","){e=`${e}`.replace(/[^0-9+-Ee.]/g,"");const r=isFinite(+e)?+e:0,s=isFinite(+n)?Math.abs(n):0,o=typeof i>"u"?",":i,f=typeof t>"u"?".":t;let c="";c=(s?b.round(r,s)+"":`${Math.round(r)}`).split(".");const d=/(-?\d+)(\d{3})/;for(;d.test(c[0]);)c[0]=c[0].replace(d,`$1${o}$2`);return(c[1]||"").length<s&&(c[1]=c[1]||"",c[1]+=new Array(s-c[1].length+1).join("0")),c.join(f)}function q(e,n=!0){const t=parseInt(e);return n?/s$/.test(e)?e:e>30?`${e}ms`:`${e}s`:/ms$/.test(e)?t:/s$/.test(e)?t>30?t:t*1e3:t}function L(e){return`00${e}`.slice(-2)}function R(e,n){if(e){if(typeof n!="string"||n==="")return"";if(n.indexOf(".")!==-1){const t=n.split(".");let i=e[t[0]]||{};for(let r=1;r<t.length;r++)i&&(i=i[t[r]]);return i}return e[n]}}function U(e,n,t){if(!e)return;const i=function(r,s,o){if(s.length===1){r[s[0]]=o;return}for(;s.length>1;){const f=s[0];(!r[f]||typeof r[f]!="object")&&(r[f]={}),s.shift(),i(r[f],s,o)}};if(!(typeof n!="string"||n===""))if(n.indexOf(".")!==-1){const r=n.split(".");i(e,r,t)}else e[n]=t}function Z(){var n;const e=getCurrentPages();return`/${((n=e[e.length-1])==null?void 0:n.route)??""}`}function j(){return getCurrentPages()}function H(){return""}function J(e){u.index.setClipboardData({data:e,success:function(){l("复制成功!")},fail:function(){l("复制失败!")}})}const Y={range:S,getPx:I,sleep:$,os:M,sys:k,random:D,guid:N,$parent:y,addStyle:w,addUnit:O,deepClone:h,deepMerge:g,error:P,randomArray:m,timeFormat:x,timeFrom:E,trim:p,queryParams:C,toast:l,type2icon:A,priceFormat:F,getDuration:q,padZero:L,getProperty:R,setProperty:U,page:Z,pages:j,test:a.test,getRootUrl:H,copyText:J};exports.$helper=Y;exports.$parent=y;exports.addStyle=w;exports.deepMerge=g;exports.sleep=$;