@spacego/turbo-utils 0.1.0 → 1.0.1
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/cjs/index.cjs +1 -1
- package/lib/cjs/utils/util.cjs +1 -1
- package/lib/es/index.js +40 -39
- package/lib/es/utils/util.js +48 -41
- package/lib/types/day/index.d.ts +2 -1
- package/lib/types/utils/util.d.ts +8 -0
- package/package.json +1 -1
package/lib/cjs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./calc/index.cjs");const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./calc/index.cjs");const l=require("./_virtual/dayjs.min.cjs"),a=require("./day/dayjs.cjs"),e=require("./is/is.cjs"),u=require("./is/is-empty.cjs"),t=require("./is/is-equals.cjs"),c=require("./utils/classnames.cjs"),d=require("./utils/deep-clone.cjs"),m=require("./utils/pick.cjs"),r=require("./utils/query2params.cjs"),s=require("./utils/util.cjs"),n=require("./utils/uuid.cjs"),o=require("./validator/validate.cjs"),i=require("./validator/validator.cjs"),p=require("./calc/calc.cjs"),y=require("./node_modules/.pnpm/decimal.js@10.6.0/node_modules/decimal.js/decimal.cjs");exports.dayjs=l.default;exports.WEEK_DAY=a.WEEK_DAY;exports.formatActivityTime=a.formatActivityTime;exports.formatDate=a.formatDate;exports.formatIosDate=a.formatIosDate;exports.getDateDiff=a.getDateDiff;exports.getDateParams=a.getDateParams;exports.isArray=e.isArray;exports.isBoolean=e.isBoolean;exports.isDate=e.isDate;exports.isFile=e.isFile;exports.isFunction=e.isFunction;exports.isMap=e.isMap;exports.isNull=e.isNull;exports.isNumber=e.isNumber;exports.isObject=e.isObject;exports.isPromise=e.isPromise;exports.isRegExp=e.isRegExp;exports.isSet=e.isSet;exports.isString=e.isString;exports.isUndefined=e.isUndefined;exports.isEmpty=u.isEmpty;exports.depsAreSame=t.depsAreSame;exports.isEquals=t.isEquals;exports.classnames=c.classnames;exports.deepClone=d.deepClone;exports.pick=m.pick;exports.filterParams=r.filterParams;exports.filterQuery=r.filterQuery;exports.filtrationEmpty=r.filtrationEmpty;exports.getUrlParam=r.getUrlParam;exports.json2params=r.json2params;exports.padQuery=r.padQuery;exports.params2json=r.params2json;exports.ObjectAssign=s.ObjectAssign;exports.browser=s.browser;exports.calculateDistance=s.calculateDistance;exports.dictEscape=s.dictEscape;exports.encryptString=s.encryptString;exports.isBrowser=s.isBrowser;exports.padZero=s.padZero;exports.thousands=s.thousands;exports.underlineToHump=s.underlineToHump;exports.randomString=n.randomString;exports.uuid=n.uuid;exports.validate=o.validate;exports.validateRequire=o.validateRequire;exports.isCard=i.isCard;exports.isCurrency=i.isCurrency;exports.isEmail=i.isEmail;exports.isIdCard=i.isIdCard;exports.isMobile=i.isMobile;exports.isPassport=i.isPassport;exports.isUrl=i.isUrl;exports.maxLength=i.maxLength;exports.minLength=i.minLength;exports.regs=i.regs;exports.required=i.required;exports.validateType=i.validateType;exports.validation=i.validation;exports.calc=p.default;exports.Decimal=y.Decimal;
|
package/lib/cjs/utils/util.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../calc/index.cjs");require("../_virtual/dayjs.min.cjs");const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../calc/index.cjs");require("../_virtual/dayjs.min.cjs");const a=require("../is/is.cjs"),u=require("../is/is-empty.cjs"),h=!!(typeof window<"u"&&window.document&&window.document.createElement);function S(t,n,e){return u.isEmpty(t)||u.isEmpty(n)||Object.keys(t).forEach(i=>{n[i]!==void 0&&!(e!=null&&e.includes(i))&&(t[i]=n[i])}),t}function M(){var e,i;const t=(i=(e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.toLowerCase)==null?void 0:i.call(e),n={ios:!!t.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/i),android:t.indexOf("android")>-1||t.indexOf("linux")>-1,iPad:t.indexOf("ipad")>-1,wechat:t.indexOf("micromessenger")>-1,aliPay:t.indexOf("alipay")>-1};return{...n,isMobile:n.android||n.ios||n.iPad}}function w(t,n=2){return t.toString().padStart(n,"0")}function E(t,n=[3,7],e="*",i){if(u.isEmpty(t))return"";if(typeof n=="number")return t.slice(0,n)+e.repeat(i||t.length-n);const[r,s]=n;return t.slice(0,r)+e.repeat(t.length-s)+t.slice(s)}const O=function(t,n=2,e=!0,i=","){const r=Number(t);if(a.isNumber(r)){let s="";if(a.isNumber(n))if(e)s=r.toFixed(n).toString();else{let o=String(r).split(".")[1];o=o?o.length:0,o>n&&(o=n),s=r.toFixed(o).toString()}else s=r.toString();const c=s.split(".");return c[0]=c[0].toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+(i||",")),c.join(".")}return t};function y(t,n){const i=m=>m*(Math.PI/180),r=i(t.latitude),s=i(t.longitude),c=i(n.latitude),o=i(n.longitude),f=c-r,p=o-s,d=Math.pow(Math.sin(f/2),2)+Math.cos(r)*Math.cos(c)*Math.pow(Math.sin(p/2),2),l=6371*(2*Math.atan2(Math.sqrt(d),Math.sqrt(1-d))),g=l*1e3;return{km:Number(l.toFixed(2)),m:Math.round(g)}}function A(t,n=!1){t.slice(0,1)==="_"&&(t=t.slice(1));const e=t.replace(/([^_])_+([^_])/g,function(i,r,s){return r+s.toUpperCase()});return n?e.charAt(0).toUpperCase()+e.slice(1):e}const b=(t,n,e="label",i="value")=>{if(t===""||a.isNull(t)||a.isUndefined(t))return t;const r=n.find(s=>s[i].toString()===t.toString());return r?r[e]:t};exports.ObjectAssign=S;exports.browser=M;exports.calculateDistance=y;exports.dictEscape=b;exports.encryptString=E;exports.isBrowser=h;exports.padZero=w;exports.thousands=O;exports.underlineToHump=A;
|
package/lib/es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./calc/index.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { default as t } from "./_virtual/dayjs.min.js";
|
|
3
|
+
import { WEEK_DAY as o, formatActivityTime as s, formatDate as m, formatIosDate as p, getDateDiff as f, getDateParams as l } from "./day/dayjs.js";
|
|
4
4
|
import { isArray as d, isBoolean as u, isDate as x, isFile as c, isFunction as g, isMap as y, isNull as D, isNumber as E, isObject as b, isPromise as j, isRegExp as v, isSet as A, isString as P, isUndefined as S } from "./is/is.js";
|
|
5
5
|
import { isEmpty as h } from "./is/is-empty.js";
|
|
6
6
|
import { depsAreSame as T, isEquals as U } from "./is/is-equals.js";
|
|
@@ -8,72 +8,73 @@ import { classnames as B } from "./utils/classnames.js";
|
|
|
8
8
|
import { deepClone as I } from "./utils/deep-clone.js";
|
|
9
9
|
import { pick as M } from "./utils/pick.js";
|
|
10
10
|
import { filterParams as O, filterQuery as Q, filtrationEmpty as R, getUrlParam as k, json2params as H, padQuery as K, params2json as W } from "./utils/query2params.js";
|
|
11
|
-
import { ObjectAssign as Z, browser as _, calculateDistance as z,
|
|
12
|
-
import { randomString as
|
|
13
|
-
import { validate as
|
|
14
|
-
import { isCard as
|
|
15
|
-
import { default as
|
|
16
|
-
import { Decimal as
|
|
11
|
+
import { ObjectAssign as Z, browser as _, calculateDistance as z, dictEscape as G, encryptString as J, isBrowser as V, padZero as X, thousands as $, underlineToHump as rr } from "./utils/util.js";
|
|
12
|
+
import { randomString as ir, uuid as tr } from "./utils/uuid.js";
|
|
13
|
+
import { validate as or, validateRequire as sr } from "./validator/validate.js";
|
|
14
|
+
import { isCard as pr, isCurrency as fr, isEmail as lr, isIdCard as nr, isMobile as dr, isPassport as ur, isUrl as xr, maxLength as cr, minLength as gr, regs as yr, required as Dr, validateType as Er, validation as br } from "./validator/validator.js";
|
|
15
|
+
import { default as vr } from "./calc/calc.js";
|
|
16
|
+
import { Decimal as Pr } from "./node_modules/.pnpm/decimal.js@10.6.0/node_modules/decimal.js/decimal.js";
|
|
17
17
|
export {
|
|
18
|
-
|
|
18
|
+
Pr as Decimal,
|
|
19
19
|
Z as ObjectAssign,
|
|
20
|
-
|
|
20
|
+
o as WEEK_DAY,
|
|
21
21
|
_ as browser,
|
|
22
|
-
|
|
22
|
+
vr as calc,
|
|
23
23
|
z as calculateDistance,
|
|
24
24
|
B as classnames,
|
|
25
|
-
|
|
25
|
+
t as dayjs,
|
|
26
26
|
I as deepClone,
|
|
27
27
|
T as depsAreSame,
|
|
28
|
-
G as
|
|
28
|
+
G as dictEscape,
|
|
29
|
+
J as encryptString,
|
|
29
30
|
O as filterParams,
|
|
30
31
|
Q as filterQuery,
|
|
31
32
|
R as filtrationEmpty,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
s as formatActivityTime,
|
|
34
|
+
m as formatDate,
|
|
35
|
+
p as formatIosDate,
|
|
36
|
+
f as getDateDiff,
|
|
37
|
+
l as getDateParams,
|
|
37
38
|
k as getUrlParam,
|
|
38
39
|
d as isArray,
|
|
39
40
|
u as isBoolean,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
V as isBrowser,
|
|
42
|
+
pr as isCard,
|
|
43
|
+
fr as isCurrency,
|
|
43
44
|
x as isDate,
|
|
44
|
-
|
|
45
|
+
lr as isEmail,
|
|
45
46
|
h as isEmpty,
|
|
46
47
|
U as isEquals,
|
|
47
48
|
c as isFile,
|
|
48
49
|
g as isFunction,
|
|
49
|
-
|
|
50
|
+
nr as isIdCard,
|
|
50
51
|
y as isMap,
|
|
51
|
-
|
|
52
|
+
dr as isMobile,
|
|
52
53
|
D as isNull,
|
|
53
54
|
E as isNumber,
|
|
54
55
|
b as isObject,
|
|
55
|
-
|
|
56
|
+
ur as isPassport,
|
|
56
57
|
j as isPromise,
|
|
57
58
|
v as isRegExp,
|
|
58
59
|
A as isSet,
|
|
59
60
|
P as isString,
|
|
60
61
|
S as isUndefined,
|
|
61
|
-
|
|
62
|
+
xr as isUrl,
|
|
62
63
|
H as json2params,
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
cr as maxLength,
|
|
65
|
+
gr as minLength,
|
|
65
66
|
K as padQuery,
|
|
66
|
-
|
|
67
|
+
X as padZero,
|
|
67
68
|
W as params2json,
|
|
68
69
|
M as pick,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
ir as randomString,
|
|
71
|
+
yr as regs,
|
|
72
|
+
Dr as required,
|
|
73
|
+
$ as thousands,
|
|
74
|
+
rr as underlineToHump,
|
|
75
|
+
tr as uuid,
|
|
76
|
+
or as validate,
|
|
77
|
+
sr as validateRequire,
|
|
78
|
+
Er as validateType,
|
|
79
|
+
br as validation
|
|
79
80
|
};
|
package/lib/es/utils/util.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import "../calc/index.js";
|
|
2
2
|
import "../_virtual/dayjs.min.js";
|
|
3
|
-
import { isNumber as f } from "../is/is.js";
|
|
4
|
-
import { isEmpty as
|
|
5
|
-
const
|
|
6
|
-
function
|
|
7
|
-
return
|
|
8
|
-
n[
|
|
3
|
+
import { isNull as h, isUndefined as M, isNumber as f } from "../is/is.js";
|
|
4
|
+
import { isEmpty as a } from "../is/is-empty.js";
|
|
5
|
+
const E = !!(typeof window < "u" && window.document && window.document.createElement);
|
|
6
|
+
function _(t, n, i) {
|
|
7
|
+
return a(t) || a(n) || Object.keys(t).forEach((e) => {
|
|
8
|
+
n[e] !== void 0 && !(i != null && i.includes(e)) && (t[e] = n[e]);
|
|
9
9
|
}), t;
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
var
|
|
13
|
-
const t = (
|
|
11
|
+
function C() {
|
|
12
|
+
var i, e;
|
|
13
|
+
const t = (e = (i = navigator == null ? void 0 : navigator.userAgent) == null ? void 0 : i.toLowerCase) == null ? void 0 : e.call(i), n = {
|
|
14
14
|
ios: !!t.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/i),
|
|
15
15
|
android: t.indexOf("android") > -1 || t.indexOf("linux") > -1,
|
|
16
16
|
iPad: t.indexOf("ipad") > -1,
|
|
@@ -22,57 +22,64 @@ function U() {
|
|
|
22
22
|
isMobile: n.android || n.ios || n.iPad
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function P(t, n = 2) {
|
|
26
26
|
return t.toString().padStart(n, "0");
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
if (
|
|
28
|
+
function R(t, n = [3, 7], i = "*", e) {
|
|
29
|
+
if (a(t)) return "";
|
|
30
30
|
if (typeof n == "number")
|
|
31
|
-
return t.slice(0, n) +
|
|
32
|
-
const [
|
|
33
|
-
return t.slice(0,
|
|
31
|
+
return t.slice(0, n) + i.repeat(e || t.length - n);
|
|
32
|
+
const [r, o] = n;
|
|
33
|
+
return t.slice(0, r) + i.repeat(t.length - o) + t.slice(o);
|
|
34
34
|
}
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
if (f(
|
|
38
|
-
let
|
|
35
|
+
const N = function(t, n = 2, i = !0, e = ",") {
|
|
36
|
+
const r = Number(t);
|
|
37
|
+
if (f(r)) {
|
|
38
|
+
let o = "";
|
|
39
39
|
if (f(n))
|
|
40
|
-
if (
|
|
41
|
-
|
|
40
|
+
if (i)
|
|
41
|
+
o = r.toFixed(n).toString();
|
|
42
42
|
else {
|
|
43
|
-
let
|
|
44
|
-
|
|
43
|
+
let s = String(r).split(".")[1];
|
|
44
|
+
s = s ? s.length : 0, s > n && (s = n), o = r.toFixed(s).toString();
|
|
45
45
|
}
|
|
46
46
|
else
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
return
|
|
47
|
+
o = r.toString();
|
|
48
|
+
const c = o.split(".");
|
|
49
|
+
return c[0] = c[0].toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1" + (e || ",")), c.join(".");
|
|
50
50
|
}
|
|
51
51
|
return t;
|
|
52
52
|
};
|
|
53
|
-
function
|
|
54
|
-
const
|
|
53
|
+
function T(t, n) {
|
|
54
|
+
const e = (g) => g * (Math.PI / 180), r = e(t.latitude), o = e(t.longitude), c = e(n.latitude), s = e(n.longitude), l = c - r, m = s - o, u = Math.pow(Math.sin(l / 2), 2) + Math.cos(r) * Math.cos(c) * Math.pow(Math.sin(m / 2), 2), d = 6371 * (2 * Math.atan2(Math.sqrt(u), Math.sqrt(1 - u))), p = d * 1e3;
|
|
55
55
|
return {
|
|
56
|
-
km: Number(
|
|
56
|
+
km: Number(d.toFixed(2)),
|
|
57
57
|
// 保留两位小数
|
|
58
58
|
m: Math.round(p)
|
|
59
59
|
// 四舍五入到整数
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
function
|
|
62
|
+
function y(t, n = !1) {
|
|
63
63
|
t.slice(0, 1) === "_" && (t = t.slice(1));
|
|
64
|
-
const
|
|
65
|
-
return
|
|
64
|
+
const i = t.replace(/([^_])_+([^_])/g, function(e, r, o) {
|
|
65
|
+
return r + o.toUpperCase();
|
|
66
66
|
});
|
|
67
|
-
return n ?
|
|
67
|
+
return n ? i.charAt(0).toUpperCase() + i.slice(1) : i;
|
|
68
68
|
}
|
|
69
|
+
const D = (t, n, i = "label", e = "value") => {
|
|
70
|
+
if (t === "" || h(t) || M(t))
|
|
71
|
+
return t;
|
|
72
|
+
const r = n.find((o) => o[e].toString() === t.toString());
|
|
73
|
+
return r ? r[i] : t;
|
|
74
|
+
};
|
|
69
75
|
export {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
_ as ObjectAssign,
|
|
77
|
+
C as browser,
|
|
78
|
+
T as calculateDistance,
|
|
79
|
+
D as dictEscape,
|
|
80
|
+
R as encryptString,
|
|
81
|
+
E as isBrowser,
|
|
82
|
+
P as padZero,
|
|
83
|
+
N as thousands,
|
|
84
|
+
y as underlineToHump
|
|
78
85
|
};
|
package/lib/types/day/index.d.ts
CHANGED
|
@@ -71,3 +71,11 @@ export declare function calculateDistance(dot1: IDistance, dot2: IDistance): IDi
|
|
|
71
71
|
* @param {boolean} isBig 是否为大驼峰
|
|
72
72
|
*/
|
|
73
73
|
export declare function underlineToHump(str: string, isBig?: boolean): string;
|
|
74
|
+
/**
|
|
75
|
+
* 通用状态字典过滤器,将键值转换为 label 显示
|
|
76
|
+
* @param dataIndex 待转换的键值
|
|
77
|
+
* @param dictList 字典数组
|
|
78
|
+
* @param dictLabelKey 字典 label 的 key
|
|
79
|
+
* @param dictCodeKey 字典 code 的 key
|
|
80
|
+
*/
|
|
81
|
+
export declare const dictEscape: (dataIndex: string | number, dictList: any[], dictLabelKey?: string, dictCodeKey?: string) => string;
|
package/package.json
CHANGED