@nano-lib/util 1.0.5 → 1.0.6
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/lib/index.d.ts +6 -6
- package/lib/index.js +1 -1
- package/lib/index.mjs +68 -82
- package/lib/types/index.d.ts +0 -6
- package/lib/utils/cache.d.ts +4 -5
- package/lib/utils/date.d.ts +3 -2
- package/lib/utils/to.d.ts +2 -2
- package/lib/utils/valid.d.ts +1 -2
- package/package.json +7 -3
package/lib/index.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { parseTime, getTimeDistance, getDayRange } from './utils/date';
|
|
|
6
6
|
import { addClass, removeClass, hasClass, toggleClass, noContextmenu, useRafThrottle } from './utils/element';
|
|
7
7
|
import { encodeURIToParams, paramsToQueryString, queryStringToParams, errorCodeToString, YNToString, HNToString, valueToLabel, chargeToLabel, cascaderToLabel, multipleSelectToLabel } from './utils/to';
|
|
8
8
|
import { validHttp, validExternal, validString, validNumberStr, validEmptyObject, validURL, validPassword, validEmail, validIdNumber, validPhone, validTel } from './utils/valid';
|
|
9
|
-
export declare const
|
|
10
|
-
DATE_VALUE_FORMAT: Map<string, "YYYY-MM-DD
|
|
9
|
+
export declare const CONSTANTS: {
|
|
10
|
+
DATE_VALUE_FORMAT: Map<string, "YYYY-MM-DD" | "YYYY-MM-DD HH:mm:ss" | "YYYY-MM" | "YYYY" | "HH:mm:ss">;
|
|
11
11
|
IMAGE_TYPE: string[];
|
|
12
12
|
MEDIA_TYPE: string[];
|
|
13
13
|
DOC_TYPE: string[];
|
|
@@ -62,16 +62,16 @@ export declare const cacheUtil: {
|
|
|
62
62
|
local: {
|
|
63
63
|
set(key: string, value: string): void;
|
|
64
64
|
get(key: string): string | null;
|
|
65
|
-
setJSON(key: string, jsonValue:
|
|
66
|
-
getJSON(key: string):
|
|
65
|
+
setJSON(key: string, jsonValue: object): void;
|
|
66
|
+
getJSON(key: string): object | null;
|
|
67
67
|
remove(key: string): void;
|
|
68
68
|
clear(): void;
|
|
69
69
|
};
|
|
70
70
|
session: {
|
|
71
71
|
set(key: string, value: string): void;
|
|
72
72
|
get(key: string): string | null;
|
|
73
|
-
setJSON(key: string, jsonValue:
|
|
74
|
-
getJSON(key: string):
|
|
73
|
+
setJSON(key: string, jsonValue: object): void;
|
|
74
|
+
getJSON(key: string): object | null;
|
|
75
75
|
remove(key: string): void;
|
|
76
76
|
clear(): void;
|
|
77
77
|
};
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=(t,e,n,r)=>(t/=r/2,t<1?n/2*t*t+e:(t--,-n/2*(t*(t-2)-1)+e)),$=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||(t=>window.setTimeout(t,1e3/60));function I(t,e){if(e){document.querySelector(e).scrollTop=t;return}document.documentElement.scrollTop=t,document.body.parentNode.scrollTop=t,document.body.scrollTop=t}function M(t){return t?document.querySelector(t).scrollTop:document.documentElement.scrollTop||document.body.parentNode.scrollTop||document.body.scrollTop}function D(t){const{target:e,to:n=0,duration:r=500,callback:o}=t??{},s=M(e),i=n-s,c=20;let a=0;const u=function(){a+=c;const l=A(a,s,i,r);I(l,e),a<r?$(u):o&&o()};u()}function E(t){return/^(http(s)?:\/\/)/.test(t)}function O(t){return/^(https?:|mailto:|tel:)/.test(t)}function R(t){return Object.prototype.toString.call(t)==="[object String]"}function x(t){return/^[+-]?(0|([1-9]\d*))(\.\d+)?$/g.test(t)}function C(t){return!Object.keys(t).length}function U(t){return/^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/.test(t)}function N(t,e=8){return new RegExp(`^S*(?=S{${e}},})(?=S*d)(?=S*[A-Z])(?=S*[a-z])(?=S*[!@#$%^&*?])S*$`).test(t)}function P(t){return/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(t)}function g(t){return/^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/.test(t)}function H(t){return/^0\d{2,3}-?\d{7,8}$/.test(t)}function z(t){return/^1[3-9]\d{9}$/.test(t)}const d=()=>{};function F(t,e){let n=null;return function(...r){n!==null&&clearTimeout(n),n=setTimeout(()=>{t.apply(this,r),n=null},e)}}function L(t){if(!g(t))throw new Error("Please provide a valid ID number!");const e=t.length,n=e===15?t[e-1]:t[e-2];return parseInt(n)%2===1?"1":"2"}function q(t){if(!g(t))throw new Error("Please provide a valid ID number!");return t.substring(6,10)+"-"+t.substring(10,12)+"-"+t.substring(12,14)}const h=(t,e="")=>{e||(e=location.origin);const n=new RegExp(/^http(s)?:\/\//),r=new RegExp(/^((?:[a-z]+:)?\/\/|data:image\/)(.*)/i);return n.test(t)||r.test(t)?t:e+t},Z=(t,e="")=>{typeof t=="string"&&(t=t===""?[]:t.split(","));for(const n in t)t[n]=h(t[n],e);return t};function j(t){let e=d;return(...n)=>new Promise((r,o)=>{e(),e=()=>{r=o=d},t(...n).then(s=>r(s),s=>o(s))})}function k(t,e){const n=document.createElement("a");n.download=e,n.href=t,n.click()}function S(t){const e=[];for(let n=0;n<t.length;n++)t[n]&&e.push(t[n]);return e}function J(t,e){switch(arguments.length){case 1:return parseInt((Math.random()*t+1).toString(),10);case 2:return parseInt((Math.random()*(e-t+1)+t).toString(),10);default:return 0}}function v(){let t="";const e=[];for(let n=0;n<=15;n++)e[n]=n.toString(16);for(let n=1;n<=36;n++)n===9||n===14||n===19||n===24?t+="-":n===15?t+=4:n===20?t+=e[Math.random()*4|8]:t+=e[Math.random()*16|0];return t}function _(t){return t?t.replace(/(\d{3})\d{4}(\d{4})/,"$1****$2"):""}function B(t,e,n){if(e??(e=4),n??(n=4),t){const r=t.length;return t.substring(0,e)+"*".repeat(r-e-n)+t.substring(r-n)}return""}function G(t){return t.replace(/( |^)[a-z]/g,e=>e.toUpperCase())}function Q(t){return t.replace(/( |^)[A-Z]/g,e=>e.toLowerCase())}function f(t,e){if(!t)return"-";t.toString().length===10&&(t=+t*1e3),e??(e="YYYY-MM-DD HH:mm:ss");const n=new Date(t),r=(i,c,a=" ")=>{if(i.length>=c)return i;const u=c-i.length;let l=Math.ceil(u/a.length);for(;l>>=1;)a+=a,l===1&&(a+=a);return a.slice(0,u)+i};let o;const s={"Y+":n.getFullYear().toString(),"M+":(n.getMonth()+1).toString(),"D+":n.getDate().toString(),"H+":n.getHours().toString(),"m+":n.getMinutes().toString(),"s+":n.getSeconds().toString()};for(const i in s)o=new RegExp("("+i+")").exec(e),o&&(e=e.replace(o[1],o[1].length==1?s[i]:r(s[i],o[1].length,"0")));return e}function X(t,e){`${t}`.length===10?t=parseInt(t+"")*1e3:t=+t;const n=new Date(t),o=(Date.now()-Number(n))/1e3;return o<30?"刚刚":o<3600?`${Math.ceil(o/60)}分钟前`:o<3600*24?`${Math.ceil(o/3600)}小时前`:o<3600*24*2?"1天前":e?f(t,e):`${n.getMonth()+1}月${n.getDate()}日${n.getHours()}时${n.getMinutes()}分`}function K(t){const e=t||new Date,n=new Date(e),r=new Date(e);return n.setHours(0,0,0),r.setHours(23,59,59),{dateRange:[f(n),f(r)],timestampRange:[n.getTime(),r.getTime()]}}const V={set(t,e){sessionStorage&&t&&e&&sessionStorage.setItem(t,e)},get(t){return!sessionStorage||!t?null:sessionStorage.getItem(t)},setJSON(t,e){e&&this.set(t,JSON.stringify(e))},getJSON(t){const e=this.get(t);return e?JSON.parse(e):null},remove(t){sessionStorage.removeItem(t)},clear(){sessionStorage.clear()}},W={set(t,e){localStorage&&t&&e&&localStorage.setItem(t,e)},get(t){return!localStorage||!t?null:localStorage.getItem(t)},setJSON(t,e){e&&this.set(t,JSON.stringify(e))},getJSON(t){const e=this.get(t);return e?JSON.parse(e):null},remove(t){localStorage.removeItem(t)},clear(){localStorage.clear()}};function tt(t,e){if(!t||!e)return;let n=t.className;const r=n.indexOf(e);r===-1?n+=`${e}`:n=n.substring(0,r)+n.substring(r+e.length),t.className=n}function p(t,e){return t.className.match(new RegExp("(?:\\s|^)"+e+"(?:\\s|$)"))}function et(t,e){p(t,e)||(t.className+=` ${e}`)}function nt(t,e){if(p(t,e)){const n=new RegExp("(?:\\s|^)"+e+"(?:\\s|$)");t.className=t.className.replace(n," ")}}function rt(t){let e=!1;return function(...n){e||(e=!0,window.requestAnimationFrame(()=>{t.apply(this,n),e=!1}))}}function ot(t){t&&(t.oncontextmenu=()=>!1)}function st(t){switch(t){case 400:return"请求失败!请您稍后重试";case 401:return"认证失败,无法访问系统资源";case 403:return"当前操作没有权限!";case 404:return"你所访问的资源不存在!";case 405:return"请求方式错误!请您稍后重试";case 408:return"请求超时!请您稍后重试";case 500:return"服务异常!";case 502:return"网关错误!";case 503:return"服务不可用!";case 504:return"网关超时!";default:return"系统未知错误,请反馈给管理员"}}function ct(t){return t==null?"未填写":(t=typeof t=="number"?`${t}`:t,t==="1"?"是":"否")}function it(t){return t==null?"未填写":(t=typeof t=="number"?`${t}`:t,t==="1"?"有":"无")}function at(t,e){const n=t.find(r=>r.value===e);return n?n.label:""}function ut(t,e,n){const r=[],o=e.split(","),s=n.split(",");return Array.from(new Set(o)).forEach(c=>{const a=t.find(u=>u.value===c);a&&s.forEach(u=>{var m;const l=(m=a.children)==null?void 0:m.find(y=>y.value===u);l&&r.push(l)})}),r.map(c=>c.label).join()}function w(t,e,n){var s;if(!e)return"";const r=e.split(","),o=n.find(i=>i.value===r[t]);return o?((s=o.children)!=null&&s.length&&w(t+1,e,o.children),o.label):""}function lt(t,e,n){if(!t)return"";const r=t.split(","),o=[],s=r.length-1,i=r.findIndex(c=>c===n);if(i!==-1){const c=r[s]===n;r.splice(c?0:i,c?s:1)}return r.forEach(c=>{const a=e.find(u=>u.value===c);a&&o.push(a)}),o.map(c=>c.label).join()}function ft(t){let e="";for(const n of Object.keys(t)){const r=t[n],o=`${encodeURIComponent(n)}=`;if(r!==null&&typeof r<"u")if(typeof r=="object"){for(const s of Object.keys(r))if(r[s]!==null&&typeof r[s]<"u"){const i=`${n}[${s}]`,c=`${encodeURIComponent(i)}=`;e+=`${c+encodeURIComponent(r[s])}&`}}else e+=`${o+encodeURIComponent(r)}&`}return e}function dt(t){return t?S(Object.keys(t).map(e=>t[e]===void 0?"":`${encodeURIComponent(e)}=${encodeURIComponent(t[e])}`)).join("&"):""}function gt(t){const e=decodeURIComponent(t.split("?")[1]).replace(/\+/g," ");if(!e)return{};const n={};return e.split("&").forEach(o=>{const s=o.indexOf("=");if(s!==-1){const i=o.substring(0,s),c=o.substring(s+1,o.length);n[i]=c}}),n}const pt=[["date","YYYY-MM-DD"],["daterange","YYYY-MM-DD"],["datetime","YYYY-MM-DD HH:mm:ss"],["datetimerange","YYYY-MM-DD HH:mm:ss"],["month","YYYY-MM"],["monthrange","YYYY-MM"],["year","YYYY"],["yearrange","YYYY"],["time","HH:mm:ss"]],mt=new Map(pt),T=["jpg","jpeg","png","bmp","gif"],Y=["mp3","mp4","webm","ogg","3gp"],b=["doc","docx","xls","xlsx","ppt","txt","pdf","zip"],ht=[...T,...Y,...b],St={DATE_VALUE_FORMAT:mt,IMAGE_TYPE:T,MEDIA_TYPE:Y,DOC_TYPE:b,FILE_TYPE:ht},wt={NOOP:d,debounce:F,creatCancelTask:j,downloadFile:k,trimArray:S,getFullUrl:h,getArrayFullUrl:Z,getGenderByIdNumber:L,getBirthdayByIdNumber:q},Tt={encodeURIToParams:ft,paramsToQueryString:dt,queryStringToParams:gt,errorCodeToString:st,YNToString:ct,HNToString:it,valueToLabel:at,chargeToLabel:ut,cascaderToLabel:w,multipleSelectToLabel:lt},Yt={validHttp:E,validExternal:O,validString:R,validNumberStr:x,validEmptyObject:C,validURL:U,validPassword:N,validEmail:P,validIdNumber:g,validPhone:z,validTel:H},bt={scrollTo:D,addClass:et,removeClass:nt,hasClass:p,toggleClass:tt,noContextmenu:ot,useRafThrottle:rt},yt={local:W,session:V},At={uuid:v,randomNum:J},$t={phoneToAsterisk:_,idNumberToAsterisk:B,firstLetterToUpperCase:G,firstLetterToLowerCase:Q},It={parseTime:f,getTimeDistance:X,getDayRange:K};exports.CONSTANTS=St;exports.cacheUtil=yt;exports.commonUtil=wt;exports.dateUtil=It;exports.elementUtil=bt;exports.randomUtil=At;exports.stringUtil=$t;exports.toUtil=Tt;exports.validUtil=Yt;
|
package/lib/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
1
|
+
const $ = (t, e, n, r) => (t /= r / 2, t < 1 ? n / 2 * t * t + e : (t--, -n / 2 * (t * (t - 2) - 1) + e)), A = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame || ((t) => window.setTimeout(t, 16.666666666666668));
|
|
2
|
+
function I(t, e) {
|
|
3
3
|
if (e) {
|
|
4
4
|
document.querySelector(e).scrollTop = t;
|
|
5
5
|
return;
|
|
@@ -11,21 +11,21 @@ function M(t) {
|
|
|
11
11
|
}
|
|
12
12
|
function D(t) {
|
|
13
13
|
const { target: e, to: n = 0, duration: r = 500, callback: o } = t ?? {}, s = M(e), i = n - s, c = 20;
|
|
14
|
-
let
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const l =
|
|
18
|
-
|
|
14
|
+
let u = 0;
|
|
15
|
+
const a = function() {
|
|
16
|
+
u += c;
|
|
17
|
+
const l = $(u, s, i, r);
|
|
18
|
+
I(l, e), u < r ? A(a) : o && o();
|
|
19
19
|
};
|
|
20
|
-
|
|
20
|
+
a();
|
|
21
21
|
}
|
|
22
22
|
function E(t) {
|
|
23
23
|
return /^(http(s)?:\/\/)/.test(t);
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function O(t) {
|
|
26
26
|
return /^(https?:|mailto:|tel:)/.test(t);
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function x(t) {
|
|
29
29
|
return Object.prototype.toString.call(t) === "[object String]";
|
|
30
30
|
}
|
|
31
31
|
function R(t) {
|
|
@@ -34,27 +34,27 @@ function R(t) {
|
|
|
34
34
|
function C(t) {
|
|
35
35
|
return !Object.keys(t).length;
|
|
36
36
|
}
|
|
37
|
-
function
|
|
37
|
+
function N(t) {
|
|
38
38
|
return /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/.test(t);
|
|
39
39
|
}
|
|
40
40
|
function H(t, e = 8) {
|
|
41
41
|
return new RegExp(`^S*(?=S{${e}},})(?=S*d)(?=S*[A-Z])(?=S*[a-z])(?=S*[!@#$%^&*?])S*$`).test(t);
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function P(t) {
|
|
44
44
|
return /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(t);
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function g(t) {
|
|
47
47
|
return /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/.test(t);
|
|
48
48
|
}
|
|
49
|
-
function
|
|
49
|
+
function z(t) {
|
|
50
50
|
return /^0\d{2,3}-?\d{7,8}$/.test(t);
|
|
51
51
|
}
|
|
52
|
-
function
|
|
52
|
+
function U(t) {
|
|
53
53
|
return /^1[3-9]\d{9}$/.test(t);
|
|
54
54
|
}
|
|
55
|
-
const
|
|
55
|
+
const d = () => {
|
|
56
56
|
};
|
|
57
|
-
function
|
|
57
|
+
function F(t, e) {
|
|
58
58
|
let n = null;
|
|
59
59
|
return function(...r) {
|
|
60
60
|
n !== null && clearTimeout(n), n = setTimeout(() => {
|
|
@@ -62,39 +62,39 @@ function U(t, e) {
|
|
|
62
62
|
}, e);
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
function
|
|
66
|
-
if (!
|
|
65
|
+
function L(t) {
|
|
66
|
+
if (!g(t))
|
|
67
67
|
throw new Error("Please provide a valid ID number!");
|
|
68
68
|
const e = t.length, n = e === 15 ? t[e - 1] : t[e - 2];
|
|
69
69
|
return parseInt(n) % 2 === 1 ? "1" : "2";
|
|
70
70
|
}
|
|
71
|
-
function
|
|
72
|
-
if (!
|
|
71
|
+
function q(t) {
|
|
72
|
+
if (!g(t))
|
|
73
73
|
throw new Error("Please provide a valid ID number!");
|
|
74
74
|
return t.substring(6, 10) + "-" + t.substring(10, 12) + "-" + t.substring(12, 14);
|
|
75
75
|
}
|
|
76
76
|
const h = (t, e = "") => {
|
|
77
|
-
e || (e =
|
|
77
|
+
e || (e = location.origin);
|
|
78
78
|
const n = new RegExp(/^http(s)?:\/\//), r = new RegExp(/^((?:[a-z]+:)?\/\/|data:image\/)(.*)/i);
|
|
79
79
|
return n.test(t) || r.test(t) ? t : e + t;
|
|
80
|
-
},
|
|
80
|
+
}, Z = (t, e = "") => {
|
|
81
81
|
typeof t == "string" && (t = t === "" ? [] : t.split(","));
|
|
82
82
|
for (const n in t)
|
|
83
83
|
t[n] = h(t[n], e);
|
|
84
84
|
return t;
|
|
85
85
|
};
|
|
86
|
-
function
|
|
87
|
-
let e =
|
|
86
|
+
function j(t) {
|
|
87
|
+
let e = d;
|
|
88
88
|
return (...n) => new Promise((r, o) => {
|
|
89
89
|
e(), e = () => {
|
|
90
|
-
r = o =
|
|
90
|
+
r = o = d;
|
|
91
91
|
}, t(...n).then(
|
|
92
92
|
(s) => r(s),
|
|
93
93
|
(s) => o(s)
|
|
94
94
|
);
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
|
-
function
|
|
97
|
+
function k(t, e) {
|
|
98
98
|
const n = document.createElement("a");
|
|
99
99
|
n.download = e, n.href = t, n.click();
|
|
100
100
|
}
|
|
@@ -104,7 +104,7 @@ function S(t) {
|
|
|
104
104
|
t[n] && e.push(t[n]);
|
|
105
105
|
return e;
|
|
106
106
|
}
|
|
107
|
-
function
|
|
107
|
+
function J(t, e) {
|
|
108
108
|
switch (arguments.length) {
|
|
109
109
|
case 1:
|
|
110
110
|
return parseInt((Math.random() * t + 1).toString(), 10);
|
|
@@ -114,7 +114,7 @@ function k(t, e) {
|
|
|
114
114
|
return 0;
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
function
|
|
117
|
+
function _() {
|
|
118
118
|
let t = "";
|
|
119
119
|
const e = [];
|
|
120
120
|
for (let n = 0; n <= 15; n++)
|
|
@@ -123,7 +123,7 @@ function J() {
|
|
|
123
123
|
n === 9 || n === 14 || n === 19 || n === 24 ? t += "-" : n === 15 ? t += 4 : n === 20 ? t += e[Math.random() * 4 | 8] : t += e[Math.random() * 16 | 0];
|
|
124
124
|
return t;
|
|
125
125
|
}
|
|
126
|
-
function
|
|
126
|
+
function v(t) {
|
|
127
127
|
return t ? t.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2") : "";
|
|
128
128
|
}
|
|
129
129
|
function B(t, e, n) {
|
|
@@ -142,13 +142,13 @@ function Q(t) {
|
|
|
142
142
|
function f(t, e) {
|
|
143
143
|
if (!t) return "-";
|
|
144
144
|
t.toString().length === 10 && (t = +t * 1e3), e ?? (e = "YYYY-MM-DD HH:mm:ss");
|
|
145
|
-
const n = new Date(t), r = (i, c,
|
|
145
|
+
const n = new Date(t), r = (i, c, u = " ") => {
|
|
146
146
|
if (i.length >= c) return i;
|
|
147
|
-
const
|
|
148
|
-
let l = Math.ceil(
|
|
147
|
+
const a = c - i.length;
|
|
148
|
+
let l = Math.ceil(a / u.length);
|
|
149
149
|
for (; l >>= 1; )
|
|
150
|
-
|
|
151
|
-
return
|
|
150
|
+
u += u, l === 1 && (u += u);
|
|
151
|
+
return u.slice(0, a) + i;
|
|
152
152
|
};
|
|
153
153
|
let o;
|
|
154
154
|
const s = {
|
|
@@ -273,36 +273,22 @@ function st(t) {
|
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
function ct(t) {
|
|
276
|
-
|
|
277
|
-
case "1":
|
|
278
|
-
return "是";
|
|
279
|
-
case "0":
|
|
280
|
-
return "否";
|
|
281
|
-
default:
|
|
282
|
-
return "未填写";
|
|
283
|
-
}
|
|
276
|
+
return t == null ? "未填写" : (t = typeof t == "number" ? `${t}` : t, t === "1" ? "是" : "否");
|
|
284
277
|
}
|
|
285
278
|
function it(t) {
|
|
286
|
-
|
|
287
|
-
case "1":
|
|
288
|
-
return "有";
|
|
289
|
-
case "0":
|
|
290
|
-
return "无";
|
|
291
|
-
default:
|
|
292
|
-
return "未填写";
|
|
293
|
-
}
|
|
279
|
+
return t == null ? "未填写" : (t = typeof t == "number" ? `${t}` : t, t === "1" ? "有" : "无");
|
|
294
280
|
}
|
|
295
|
-
function
|
|
281
|
+
function ut(t, e) {
|
|
296
282
|
const n = t.find((r) => r.value === e);
|
|
297
283
|
return n ? n.label : "";
|
|
298
284
|
}
|
|
299
|
-
function
|
|
285
|
+
function at(t, e, n) {
|
|
300
286
|
const r = [], o = e.split(","), s = n.split(",");
|
|
301
287
|
return Array.from(new Set(o)).forEach((c) => {
|
|
302
|
-
const
|
|
303
|
-
|
|
288
|
+
const u = t.find((a) => a.value === c);
|
|
289
|
+
u && s.forEach((a) => {
|
|
304
290
|
var m;
|
|
305
|
-
const l = (m =
|
|
291
|
+
const l = (m = u.children) == null ? void 0 : m.find((y) => y.value === a);
|
|
306
292
|
l && r.push(l);
|
|
307
293
|
});
|
|
308
294
|
}), r.map((c) => c.label).join();
|
|
@@ -321,8 +307,8 @@ function lt(t, e, n) {
|
|
|
321
307
|
r.splice(c ? 0 : i, c ? s : 1);
|
|
322
308
|
}
|
|
323
309
|
return r.forEach((c) => {
|
|
324
|
-
const
|
|
325
|
-
|
|
310
|
+
const u = e.find((a) => a.value === c);
|
|
311
|
+
u && o.push(u);
|
|
326
312
|
}), o.map((c) => c.label).join();
|
|
327
313
|
}
|
|
328
314
|
function ft(t) {
|
|
@@ -341,12 +327,12 @@ function ft(t) {
|
|
|
341
327
|
}
|
|
342
328
|
return e;
|
|
343
329
|
}
|
|
344
|
-
function
|
|
330
|
+
function dt(t) {
|
|
345
331
|
return t ? S(
|
|
346
332
|
Object.keys(t).map((e) => t[e] === void 0 ? "" : `${encodeURIComponent(e)}=${encodeURIComponent(t[e])}`)
|
|
347
333
|
).join("&") : "";
|
|
348
334
|
}
|
|
349
|
-
function
|
|
335
|
+
function gt(t) {
|
|
350
336
|
const e = decodeURIComponent(t.split("?")[1]).replace(/\+/g, " ");
|
|
351
337
|
if (!e)
|
|
352
338
|
return {};
|
|
@@ -370,46 +356,46 @@ const pt = [
|
|
|
370
356
|
["yearrange", "YYYY"],
|
|
371
357
|
["time", "HH:mm:ss"]
|
|
372
358
|
], mt = new Map(pt), Y = ["jpg", "jpeg", "png", "bmp", "gif"], T = ["mp3", "mp4", "webm", "ogg", "3gp"], b = ["doc", "docx", "xls", "xlsx", "ppt", "txt", "pdf", "zip"], ht = [...Y, ...T, ...b], St = { DATE_VALUE_FORMAT: mt, IMAGE_TYPE: Y, MEDIA_TYPE: T, DOC_TYPE: b, FILE_TYPE: ht }, wt = {
|
|
373
|
-
NOOP:
|
|
374
|
-
debounce:
|
|
375
|
-
creatCancelTask:
|
|
376
|
-
downloadFile:
|
|
359
|
+
NOOP: d,
|
|
360
|
+
debounce: F,
|
|
361
|
+
creatCancelTask: j,
|
|
362
|
+
downloadFile: k,
|
|
377
363
|
trimArray: S,
|
|
378
364
|
getFullUrl: h,
|
|
379
|
-
getArrayFullUrl:
|
|
380
|
-
getGenderByIdNumber:
|
|
381
|
-
getBirthdayByIdNumber:
|
|
365
|
+
getArrayFullUrl: Z,
|
|
366
|
+
getGenderByIdNumber: L,
|
|
367
|
+
getBirthdayByIdNumber: q
|
|
382
368
|
}, Yt = {
|
|
383
369
|
encodeURIToParams: ft,
|
|
384
|
-
paramsToQueryString:
|
|
385
|
-
queryStringToParams:
|
|
370
|
+
paramsToQueryString: dt,
|
|
371
|
+
queryStringToParams: gt,
|
|
386
372
|
errorCodeToString: st,
|
|
387
373
|
YNToString: ct,
|
|
388
374
|
HNToString: it,
|
|
389
|
-
valueToLabel:
|
|
390
|
-
chargeToLabel:
|
|
375
|
+
valueToLabel: ut,
|
|
376
|
+
chargeToLabel: at,
|
|
391
377
|
cascaderToLabel: w,
|
|
392
378
|
multipleSelectToLabel: lt
|
|
393
379
|
}, Tt = {
|
|
394
380
|
validHttp: E,
|
|
395
|
-
validExternal:
|
|
396
|
-
validString:
|
|
381
|
+
validExternal: O,
|
|
382
|
+
validString: x,
|
|
397
383
|
validNumberStr: R,
|
|
398
384
|
validEmptyObject: C,
|
|
399
|
-
validURL:
|
|
385
|
+
validURL: N,
|
|
400
386
|
validPassword: H,
|
|
401
|
-
validEmail:
|
|
402
|
-
validIdNumber:
|
|
403
|
-
validPhone:
|
|
404
|
-
validTel:
|
|
405
|
-
}, bt = { scrollTo: D, addClass: et, removeClass: nt, hasClass: p, toggleClass: tt, noContextmenu: ot, useRafThrottle: rt }, yt = { local: W, session: V },
|
|
387
|
+
validEmail: P,
|
|
388
|
+
validIdNumber: g,
|
|
389
|
+
validPhone: U,
|
|
390
|
+
validTel: z
|
|
391
|
+
}, bt = { scrollTo: D, addClass: et, removeClass: nt, hasClass: p, toggleClass: tt, noContextmenu: ot, useRafThrottle: rt }, yt = { local: W, session: V }, $t = { uuid: _, randomNum: J }, At = { phoneToAsterisk: v, idNumberToAsterisk: B, firstLetterToUpperCase: G, firstLetterToLowerCase: Q }, It = { parseTime: f, getTimeDistance: X, getDayRange: K };
|
|
406
392
|
export {
|
|
393
|
+
St as CONSTANTS,
|
|
407
394
|
yt as cacheUtil,
|
|
408
395
|
wt as commonUtil,
|
|
409
|
-
|
|
410
|
-
$t as dateUtil,
|
|
396
|
+
It as dateUtil,
|
|
411
397
|
bt as elementUtil,
|
|
412
|
-
|
|
398
|
+
$t as randomUtil,
|
|
413
399
|
At as stringUtil,
|
|
414
400
|
Yt as toUtil,
|
|
415
401
|
Tt as validUtil
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
export type Fn<T = any, R = T> = {
|
|
2
|
-
(...arg: T[]): R;
|
|
3
|
-
};
|
|
4
1
|
export type PromiseFn<T = any, R = T> = {
|
|
5
2
|
(...arg: T[]): Promise<R>;
|
|
6
3
|
};
|
|
@@ -8,9 +5,6 @@ export type AnyObj<T = any> = {
|
|
|
8
5
|
[key: string]: T;
|
|
9
6
|
};
|
|
10
7
|
export type Nullable<T> = T | null;
|
|
11
|
-
export type Writable<T> = {
|
|
12
|
-
-readonly [P in keyof T]: T[P];
|
|
13
|
-
};
|
|
14
8
|
export type TimeoutHandle = ReturnType<typeof setTimeout>;
|
|
15
9
|
export type IntervalHandle = ReturnType<typeof setInterval>;
|
|
16
10
|
export type OptionType = {
|
package/lib/utils/cache.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { AnyObj } from '../types';
|
|
2
1
|
export declare const session: {
|
|
3
2
|
set(key: string, value: string): void;
|
|
4
3
|
get(key: string): string | null;
|
|
5
|
-
setJSON(key: string, jsonValue:
|
|
6
|
-
getJSON(key: string):
|
|
4
|
+
setJSON(key: string, jsonValue: object): void;
|
|
5
|
+
getJSON(key: string): object | null;
|
|
7
6
|
remove(key: string): void;
|
|
8
7
|
clear(): void;
|
|
9
8
|
};
|
|
10
9
|
export declare const local: {
|
|
11
10
|
set(key: string, value: string): void;
|
|
12
11
|
get(key: string): string | null;
|
|
13
|
-
setJSON(key: string, jsonValue:
|
|
14
|
-
getJSON(key: string):
|
|
12
|
+
setJSON(key: string, jsonValue: object): void;
|
|
13
|
+
getJSON(key: string): object | null;
|
|
15
14
|
remove(key: string): void;
|
|
16
15
|
clear(): void;
|
|
17
16
|
};
|
package/lib/utils/date.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
1
|
+
import { DateFormat } from '../constant';
|
|
2
|
+
export declare function parseTime(dateTime?: string | number | Date | null, format?: DateFormat): "-" | "YYYY-MM-DD" | "YYYY-MM-DD HH:mm:ss" | "YYYY-MM" | "YYYY" | "HH:mm:ss";
|
|
3
|
+
export declare function getTimeDistance(time: number, format?: DateFormat): string;
|
|
3
4
|
export declare function getDayRange(date?: string | number | Date): {
|
|
4
5
|
dateRange: [string, string];
|
|
5
6
|
timestampRange: [number, number];
|
package/lib/utils/to.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AnyObj, CategoryType } from '../types';
|
|
2
2
|
export declare function errorCodeToString(code: number): string;
|
|
3
|
-
export declare function YNToString(value?: string | null): "
|
|
4
|
-
export declare function HNToString(value?: string | null): "未填写" | "有" | "无";
|
|
3
|
+
export declare function YNToString(value?: string | number | null): "未填写" | "是" | "否";
|
|
4
|
+
export declare function HNToString(value?: string | number | null): "未填写" | "有" | "无";
|
|
5
5
|
export declare function valueToLabel(data: CategoryType[], value?: string): string;
|
|
6
6
|
export declare function chargeToLabel(data: CategoryType[], type: string, charge: string): string;
|
|
7
7
|
export declare function cascaderToLabel(index: number, value: string | undefined, data: CategoryType[]): string;
|
package/lib/utils/valid.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { AnyObj } from '../types';
|
|
2
1
|
export declare function validHttp(http: string): boolean;
|
|
3
2
|
export declare function validExternal(str: string): boolean;
|
|
4
3
|
export declare function validString(str: string): boolean;
|
|
5
4
|
export declare function validNumberStr(str: string): boolean;
|
|
6
|
-
export declare function validEmptyObject(object:
|
|
5
|
+
export declare function validEmptyObject(object: object): boolean;
|
|
7
6
|
export declare function validURL(url: string): boolean;
|
|
8
7
|
/**
|
|
9
8
|
* Validate the password strength
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nano-lib/util",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Custom utility functions for the nano library",
|
|
5
5
|
"author": "kevin chen",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"types": "./lib/index.d.ts",
|
|
13
13
|
"import": "./lib/index.mjs",
|
|
14
14
|
"require": "./lib/index.js"
|
|
15
|
-
}
|
|
15
|
+
},
|
|
16
|
+
"./*": "./*"
|
|
16
17
|
},
|
|
17
18
|
"files": [
|
|
18
19
|
"package.json",
|
|
@@ -20,6 +21,7 @@
|
|
|
20
21
|
"LICENSE",
|
|
21
22
|
"lib"
|
|
22
23
|
],
|
|
24
|
+
"sideEffects": false,
|
|
23
25
|
"scripts": {
|
|
24
26
|
"lib": "rimraf lib && vite build"
|
|
25
27
|
},
|
|
@@ -36,6 +38,8 @@
|
|
|
36
38
|
},
|
|
37
39
|
"packageManager": "pnpm@9.1.3",
|
|
38
40
|
"keywords": [
|
|
39
|
-
"nano-lib"
|
|
41
|
+
"nano-lib",
|
|
42
|
+
"@nano-lib/component",
|
|
43
|
+
"@nano-lib/util"
|
|
40
44
|
]
|
|
41
45
|
}
|