@spacego/turbo-utils 0.0.1-alpha

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.
Files changed (59) hide show
  1. package/README.md +30 -0
  2. package/lib/cjs/_virtual/_commonjsHelpers.js +1 -0
  3. package/lib/cjs/_virtual/dayjs.min.js +1 -0
  4. package/lib/cjs/_virtual/dayjs.min2.js +1 -0
  5. package/lib/cjs/calc/calc.js +1 -0
  6. package/lib/cjs/calc/index.js +1 -0
  7. package/lib/cjs/day/dayjs.js +1 -0
  8. package/lib/cjs/index.js +1 -0
  9. package/lib/cjs/is/is-empty.js +1 -0
  10. package/lib/cjs/is/is-equals.js +1 -0
  11. package/lib/cjs/is/is.js +1 -0
  12. package/lib/cjs/node_modules/.pnpm/dayjs@1.11.19/node_modules/dayjs/dayjs.min.js +1 -0
  13. package/lib/cjs/node_modules/.pnpm/decimal.js@10.6.0/node_modules/decimal.js/decimal.js +7 -0
  14. package/lib/cjs/utils/deep-clone.js +1 -0
  15. package/lib/cjs/utils/pick.js +1 -0
  16. package/lib/cjs/utils/query2params.js +1 -0
  17. package/lib/cjs/utils/util.js +1 -0
  18. package/lib/cjs/utils/uuid.js +1 -0
  19. package/lib/cjs/validator/validate.js +1 -0
  20. package/lib/cjs/validator/validator.js +1 -0
  21. package/lib/es/_virtual/_commonjsHelpers.js +6 -0
  22. package/lib/es/_virtual/dayjs.min.js +7 -0
  23. package/lib/es/_virtual/dayjs.min2.js +4 -0
  24. package/lib/es/calc/calc.js +49 -0
  25. package/lib/es/calc/index.js +13 -0
  26. package/lib/es/day/dayjs.js +105 -0
  27. package/lib/es/index.js +76 -0
  28. package/lib/es/is/is-empty.js +6 -0
  29. package/lib/es/is/is-equals.js +28 -0
  30. package/lib/es/is/is.js +58 -0
  31. package/lib/es/node_modules/.pnpm/dayjs@1.11.19/node_modules/dayjs/dayjs.min.js +282 -0
  32. package/lib/es/node_modules/.pnpm/decimal.js@10.6.0/node_modules/decimal.js/decimal.js +1024 -0
  33. package/lib/es/utils/deep-clone.js +11 -0
  34. package/lib/es/utils/pick.js +11 -0
  35. package/lib/es/utils/query2params.js +58 -0
  36. package/lib/es/utils/util.js +71 -0
  37. package/lib/es/utils/uuid.js +15 -0
  38. package/lib/es/validator/validate.js +22 -0
  39. package/lib/es/validator/validator.js +84 -0
  40. package/lib/types/calc/calc.d.ts +38 -0
  41. package/lib/types/calc/index.d.ts +18 -0
  42. package/lib/types/day/dayjs.d.ts +62 -0
  43. package/lib/types/day/index.d.ts +2 -0
  44. package/lib/types/index.d.ts +5 -0
  45. package/lib/types/is/index.d.ts +3 -0
  46. package/lib/types/is/is-empty.d.ts +14 -0
  47. package/lib/types/is/is-equals.d.ts +11 -0
  48. package/lib/types/is/is.d.ts +14 -0
  49. package/lib/types/utils/classnames.d.ts +19 -0
  50. package/lib/types/utils/deep-clone.d.ts +9 -0
  51. package/lib/types/utils/index.d.ts +6 -0
  52. package/lib/types/utils/pick.d.ts +11 -0
  53. package/lib/types/utils/query2params.d.ts +56 -0
  54. package/lib/types/utils/util.d.ts +71 -0
  55. package/lib/types/utils/uuid.d.ts +13 -0
  56. package/lib/types/validator/index.d.ts +2 -0
  57. package/lib/types/validator/validate.d.ts +46 -0
  58. package/lib/types/validator/validator.d.ts +71 -0
  59. package/package.json +53 -0
@@ -0,0 +1,11 @@
1
+ function e(t) {
2
+ if (!t && typeof t != "object")
3
+ throw new Error("error arguments deepClone");
4
+ const n = t.constructor === Array ? [] : {};
5
+ return Object.keys(t).forEach((r) => {
6
+ t[r] && typeof t[r] == "object" ? n[r] = e(t[r]) : n[r] = t[r];
7
+ }), n;
8
+ }
9
+ export {
10
+ e as deepClone
11
+ };
@@ -0,0 +1,11 @@
1
+ function i(o, ...c) {
2
+ const t = {}, e = c.reduce((n, r) => Array.isArray(r) ? n.concat(r) : n.concat([r]), []);
3
+ for (const n of e) {
4
+ const r = n;
5
+ r in o && (t[r] = o[r]);
6
+ }
7
+ return t;
8
+ }
9
+ export {
10
+ i as pick
11
+ };
@@ -0,0 +1,58 @@
1
+ import { isClient as l } from "./util.js";
2
+ import "../calc/index.js";
3
+ import "../_virtual/dayjs.min.js";
4
+ import { isString as d } from "../is/is.js";
5
+ import s from "../is/is-empty.js";
6
+ function f(t, n = "&") {
7
+ return s(t) ? {} : decodeURIComponent(t).replace(/^\?/, "").split(n).reduce((r, m) => {
8
+ const [o, c] = m.split("=");
9
+ if (o) {
10
+ const u = c ?? "";
11
+ r[o] && typeof r[o] == "string" ? r[o] = [r[o], u] : r[o] ? r[o].push(u) : r[o] = u;
12
+ }
13
+ return r;
14
+ }, {});
15
+ }
16
+ function p(t, n = "&") {
17
+ return s(t) ? "" : Object.keys(t).map((e) => {
18
+ const i = t[e];
19
+ return Array.isArray(i) ? i.map((r) => `${e}=${r}`).join(n) : `${e}=${i}`;
20
+ }).join(n);
21
+ }
22
+ function q(t, n) {
23
+ const e = l ? window : { location: { search: "" } }, i = new RegExp("(^|&)" + t + "=([^&]*)(&|$)"), r = (n || e.location.search).substr(1).match(i);
24
+ return r != null ? unescape(r[2]) : null;
25
+ }
26
+ function a(t) {
27
+ return Object.keys(t).forEach((n) => {
28
+ (s(t[n]) || t[n] === "undefined") && t[n] !== 0 && delete t[n];
29
+ }), t;
30
+ }
31
+ function h(t, n = []) {
32
+ const e = d(t);
33
+ if (s(t)) return e ? "" : {};
34
+ const i = e ? f(t) : t;
35
+ return n.forEach((r) => {
36
+ delete i[r];
37
+ }), e ? p(i) : i;
38
+ }
39
+ function y(t, n) {
40
+ if (s(t)) return "";
41
+ t = decodeURIComponent(t);
42
+ const [e, i] = t.split("?"), r = a(Object.assign({}, f(i), a(Object.assign({}, n || {}))));
43
+ return `${e}?${p(r)}`;
44
+ }
45
+ function O(t, n = []) {
46
+ if (s(t)) return "";
47
+ const [e, i = ""] = t.split("?");
48
+ return y(e, f(h(i, n)));
49
+ }
50
+ export {
51
+ h as filterParams,
52
+ O as filterQuery,
53
+ a as filtrationEmpty,
54
+ q as getUrlParam,
55
+ p as json2params,
56
+ y as padQuery,
57
+ f as params2json
58
+ };
@@ -0,0 +1,71 @@
1
+ import "../calc/index.js";
2
+ import "../_virtual/dayjs.min.js";
3
+ import { isNumber as f } from "../is/is.js";
4
+ import c from "../is/is-empty.js";
5
+ const x = typeof window > "u", A = typeof window < "u";
6
+ function R(t, n, e) {
7
+ return c(t) || c(n) || Object.keys(t).forEach((i) => {
8
+ n[i] !== void 0 && !(e != null && e.includes(i)) && (t[i] = n[i]);
9
+ }), t;
10
+ }
11
+ function P() {
12
+ var e, i;
13
+ const t = (i = (e = navigator == null ? void 0 : navigator.userAgent) == null ? void 0 : e.toLowerCase) == null ? void 0 : i.call(e), n = {
14
+ ios: !!t.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/i),
15
+ android: t.indexOf("android") > -1 || t.indexOf("linux") > -1,
16
+ iPad: t.indexOf("ipad") > -1,
17
+ wechat: t.indexOf("micromessenger") > -1,
18
+ aliPay: t.indexOf("alipay") > -1
19
+ };
20
+ return {
21
+ ...n,
22
+ isMobile: n.android || n.ios || n.iPad
23
+ };
24
+ }
25
+ function y(t, n = 2) {
26
+ return t.toString().padStart(n, "0");
27
+ }
28
+ function E(t, n = [3, 7], e = "*", i) {
29
+ if (c(t)) return "";
30
+ if (typeof n == "number")
31
+ return t.slice(0, n) + e.repeat(i || t.length - n);
32
+ const [o, r] = n;
33
+ return t.slice(0, o) + e.repeat(t.length - r) + t.slice(r);
34
+ }
35
+ const U = function(t, n = 2, e = !0, i = ",") {
36
+ const o = Number(t);
37
+ if (f(o)) {
38
+ let r = "";
39
+ if (f(n))
40
+ if (e)
41
+ r = o.toFixed(n).toString();
42
+ else {
43
+ let a = String(o).split(".")[1];
44
+ a = a ? a.length : 0, a > n && (a = n), r = o.toFixed(a).toString();
45
+ }
46
+ else
47
+ r = o.toString();
48
+ const s = r.split(".");
49
+ return s[0] = s[0].toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1" + (i || ",")), s.join(".");
50
+ }
51
+ return t;
52
+ };
53
+ function C(t, n) {
54
+ const i = (g) => g * (Math.PI / 180), o = i(t.latitude), r = i(t.longitude), s = i(n.latitude), a = i(n.longitude), l = s - o, m = a - r, d = Math.pow(Math.sin(l / 2), 2) + Math.cos(o) * Math.cos(s) * Math.pow(Math.sin(m / 2), 2), u = 6371 * (2 * Math.atan2(Math.sqrt(d), Math.sqrt(1 - d))), p = u * 1e3;
55
+ return {
56
+ km: Number(u.toFixed(2)),
57
+ // 保留两位小数
58
+ m: Math.round(p)
59
+ // 四舍五入到整数
60
+ };
61
+ }
62
+ export {
63
+ R as ObjectAssign,
64
+ P as browser,
65
+ C as calculateDistance,
66
+ E as encryptString,
67
+ A as isClient,
68
+ x as isSSR,
69
+ y as padZero,
70
+ U as thousands
71
+ };
@@ -0,0 +1,15 @@
1
+ function e() {
2
+ const t = [], n = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
3
+ for (let r = 0; r < 36; r++) t[r] = n.substr(Math.floor(Math.random() * n.length), 1);
4
+ return t[14] = "4", t[19] = n.substr(t[19] | 8, 1), t[8] = t[13] = t[18] = t[23] = "-", t.join("");
5
+ }
6
+ function i(t = 32) {
7
+ const n = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz0123456789", r = n.length;
8
+ let o = "";
9
+ for (let a = 0; a < t; a++) o += n.charAt(Math.floor(Math.random() * r));
10
+ return o;
11
+ }
12
+ export {
13
+ i as randomString,
14
+ e as uuid
15
+ };
@@ -0,0 +1,22 @@
1
+ import { validateType as v } from "./validator.js";
2
+ function d(n, o) {
3
+ return new Promise((t) => {
4
+ const s = [];
5
+ n.some((e) => {
6
+ e.type = e.type ?? "required";
7
+ const i = o[e.key], r = !v[e.type](i, e.len);
8
+ return r && s.push(e), r;
9
+ }) && t({ valid: !1, ...s[0] }), t({ valid: !0, msg: void 0, key: void 0 });
10
+ });
11
+ }
12
+ function l(n, o) {
13
+ const t = [];
14
+ return n.some((u) => {
15
+ const e = o[u.key], i = (!e || e === "undefined") && e !== 0;
16
+ return i && t.push(u), i;
17
+ }) ? { valid: !1, ...t[0] } : { valid: !0 };
18
+ }
19
+ export {
20
+ d as validate,
21
+ l as validateRequire
22
+ };
@@ -0,0 +1,84 @@
1
+ const i = {
2
+ url: "^(http|https|ftp)://[a-zA-Z0-9-.]+.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9-._?,'/\\+&amp;%$#=~])*[^.,)(s]$",
3
+ email: "^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$",
4
+ mobile: /^1[^12][0-9]{9}$/,
5
+ tel: "^0\\d{2,3}-?\\d{7,8}$",
6
+ // 固话
7
+ idCard: /^\d{15}(\d{2}[A-Za-z0-9])?$/,
8
+ card: /^\d{13,19}$/,
9
+ // 银行卡
10
+ passport: /(^[EeKkGgDdSsPpHh]\d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa])|(1[45]))\d{7}$)/,
11
+ // 护照(包括香港和澳门)
12
+ currency: "^\\d+(\\.\\d+)?$",
13
+ qq: "^[1-9]d{4,8}$",
14
+ number: "^[0-9]*$",
15
+ positiveInt: "^[1-9]d*$",
16
+ zip: "^[1-9]d{5}$",
17
+ double: "^[-+]?d+(.d+)?$",
18
+ english: "^[A-Za-z]+$",
19
+ chinese: "^[Α-¥]+$",
20
+ unSafe: "^(.{0,5})$|s",
21
+ date: "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)",
22
+ name: /^[\u4e00-\u9fa5\ a-zA-Z]+$/
23
+ };
24
+ function n(r) {
25
+ return (t) => typeof t == "string" ? new RegExp(i[r]).test(t) : !1;
26
+ }
27
+ const o = (r) => n("currency")(r), d = (r) => n("url")(r), f = (r) => n("email")(r), c = (r) => n("mobile")(r), p = (r) => n("number")(r), a = (r) => n("idCard")(r), u = (r) => n("card")(r), g = (r) => n("passport")(r), l = (r) => {
28
+ if (typeof r > "u")
29
+ return !1;
30
+ if (typeof r == "string")
31
+ return !!s(r);
32
+ if (Array.isArray(r)) {
33
+ if (r.length === 0)
34
+ return !1;
35
+ for (const t of r)
36
+ if (typeof t != "number" && !s(t))
37
+ return !1;
38
+ }
39
+ return !0;
40
+ }, $ = (r, t) => {
41
+ let e = 0;
42
+ return typeof r == "number" ? e = String(r).length : (r instanceof Array || typeof r == "string") && (e = r.length), t > 0 && e <= t;
43
+ }, m = (r, t) => {
44
+ let e = 0;
45
+ return typeof r == "number" ? e = String(r).length : (r instanceof Array || typeof r == "string") && (e = r.length), t > 0 && e >= t;
46
+ }, s = (r) => r === null ? "" : String.prototype.trim.call(r), y = {
47
+ /** 必填 */
48
+ required: l,
49
+ /** 最大长度 */
50
+ maxLength: $,
51
+ /** 最小长度 */
52
+ minLength: m,
53
+ /** 金额校验 */
54
+ isCurrency: o,
55
+ /** URL验证 */
56
+ isUrl: d,
57
+ /** 邮箱验证 */
58
+ isEmail: f,
59
+ /** 手机号码验证 */
60
+ isMobile: c,
61
+ /** 正整数验证 */
62
+ isNumber: p,
63
+ /** 身份证验证 */
64
+ isIdCard: a,
65
+ /** 银行卡号验证 */
66
+ isCard: u,
67
+ /** 护照验证 */
68
+ isPassport: g
69
+ };
70
+ export {
71
+ u as isCard,
72
+ o as isCurrency,
73
+ f as isEmail,
74
+ a as isIdCard,
75
+ c as isMobile,
76
+ g as isPassport,
77
+ d as isUrl,
78
+ $ as maxLength,
79
+ m as minLength,
80
+ i as regs,
81
+ l as required,
82
+ y as validateType,
83
+ n as validation
84
+ };
@@ -0,0 +1,38 @@
1
+ declare const calc: {
2
+ /**
3
+ * 加法运算
4
+ * @param a 运算数1
5
+ * @param b 运算数2
6
+ * @example calc.add(0.1, 0.2) // 0.3
7
+ */
8
+ add: (a: number | string, b: number | string) => number;
9
+ /**
10
+ * 减法运算
11
+ * @param a 运算数1
12
+ * @param b 运算数2
13
+ * @example calc.subtract(0.3, 0.2) // 0.1
14
+ */
15
+ subtract: (a: number | string, b: number | string) => number;
16
+ /**
17
+ * 乘法运算
18
+ * @param a 运算数1
19
+ * @param b 运算数2
20
+ * @example calc.multiply(0.1, 0.2) // 0.02
21
+ */
22
+ multiply: (a: number | string, b: number | string) => number;
23
+ /**
24
+ * 除法运算
25
+ * @param a 运算数1
26
+ * @param b 运算数2
27
+ * @example calc.divide(0.1, 0.2) // 0.5
28
+ */
29
+ divide: (a: number | string, b: number | string) => number;
30
+ /**
31
+ * 向上保留小数
32
+ * @param value 数据
33
+ * @param num 保留小数位数 默认2位
34
+ * @example calc.ceilFloat(0.123456, 3) // 0.124
35
+ */
36
+ saveCeilFloat: (value: number | string, num?: number) => string;
37
+ };
38
+ export default calc;
@@ -0,0 +1,18 @@
1
+ import { default as calc } from './calc';
2
+ export * from 'decimal.js';
3
+ declare global {
4
+ interface Number {
5
+ /**
6
+ * 扩展Number对象 实现传统的四舍五入,解决例如parseFloat(123.675).toFixed(2) = 123.67 的问题
7
+ * @param len 保留几位小数
8
+ * @returns string
9
+ */
10
+ toFixedNew: (len: number) => string;
11
+ /**
12
+ * 扩展Number对象 获取小数位位数
13
+ * @returns number
14
+ */
15
+ countDecimals: () => number;
16
+ }
17
+ }
18
+ export { calc };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Handle ios time formats
3
+ * @param {string} date
4
+ * @returns string
5
+ */
6
+ export declare function formatIosDate(date: string): string;
7
+ /**
8
+ * 格式化时间 Date 转化为指定格式的String
9
+ * 年(y)可以用 1-4 个占位符、月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、毫秒(S)只能用 1 个占位符(是 1-3 位的数字)、周(E)、季度(q)可以用 1-2 个占位符
10
+ * @param {string | number | Date} [date] 时间 可选,默认为当前时间
11
+ * @param {string} [fmt] 格式 可选,默认为 yyyy-MM-dd HH:mm:ss
12
+ * @returns 时间date as fmt
13
+ * @example
14
+ * formatDate('2023-03-23 15:30:59:60', 'yyyy-MM-dd HH:mm:ss:S EEE qq')
15
+ *
16
+ * => 2023-03-23 15:30:59:60 星期四 01
17
+ */
18
+ export declare function formatDate(date?: string | number | Date, fmt?: string): string;
19
+ /**
20
+ * week day
21
+ * @reutrn 0: '日', 1: '一', 2: '二', 3: '三', 4: '四', 5: '五', 6: '六'
22
+ */
23
+ export declare const WEEK_DAY: string[];
24
+ /**
25
+ * Get time parameter
26
+ * @param date
27
+ * @returns
28
+ * @example getDateParams('2023-03-23 15:30:59') => { y: '2023', m: '03', d: '23', h: '15', mm: '30', ss: '59', w: '四' }
29
+ */
30
+ export declare function getDateParams(date?: string | number | Date): {
31
+ y: string;
32
+ /** 月 */
33
+ m: string;
34
+ /** 日 */
35
+ d: string;
36
+ /** 时 */
37
+ h: string;
38
+ /** 分 */
39
+ mm: string;
40
+ /** 秒 */
41
+ ss: string;
42
+ /** 周 */
43
+ w: string;
44
+ };
45
+ /**
46
+ * Get the difference between the current time and the specified time
47
+ * @param dateTimeStamp string | number | Date
48
+ * @returns string
49
+ * @example getDateDiff('2023-03-23 15:30:59') => '1天前'
50
+ */
51
+ export declare function getDateDiff(dateTimeStamp: string | number | Date): string;
52
+ /**
53
+ * 特殊活动开始结束时间格式化
54
+ * @param startTime number | string 开始时间
55
+ * @param endTime number | string 结束时间
56
+ * @returns string
57
+ * @example
58
+ * formatActivityTime('2023-03-23 15:30:59', '2023-03-23 16:30:59') => '3月23日 周四 15:30-16:30'
59
+ * formatActivityTime('2023-03-23 15:30:59', '2023-03-24 15:30:59') => '03月23日 15:30 - 03月24日 15:30'
60
+ * formatActivityTime('2023-03-23 15:30:59') => '3月23日 周四 15:30'
61
+ */
62
+ export declare function formatActivityTime(startTime: number | string, endTime?: number | string): string;
@@ -0,0 +1,2 @@
1
+ export * from './dayjs';
2
+ export { default as dayjs } from 'dayjs';
@@ -0,0 +1,5 @@
1
+ export * from './calc';
2
+ export * from './day';
3
+ export * from './is';
4
+ export * from './utils';
5
+ export * from './validator';
@@ -0,0 +1,3 @@
1
+ export * from './is';
2
+ export { default as isEmpty } from './is-empty';
3
+ export { default as isEquals } from './is-equals';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Checks if value is empty.
3
+ *
4
+ * Checks if value is empty. A value is considered empty unless it’s an arguments object, array, string, or
5
+ * jQuery-like collection with a length greater than 0 or an object with own enumerable properties.
6
+ *
7
+ * @param value The value to inspect.
8
+ * @return Returns true if value is empty, else false.
9
+ * @example
10
+ * const a = {};
11
+ * isEmpty(a) => true;
12
+ */
13
+ declare function isEmpty(value: unknown): value is null;
14
+ export default isEmpty;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Checks if two values are equal.
3
+ * @param value1 The first value.
4
+ * @param value2 The second value.
5
+ * @returns True if the values are equal, false otherwise.
6
+ * @example
7
+ * const a = { a: 1 }; const b = { a: 1 };
8
+ * isEquals(a) => true
9
+ */
10
+ declare function isEquals(value1: any, value2: any): boolean;
11
+ export default isEquals;
@@ -0,0 +1,14 @@
1
+ export declare function isNumber<T extends number>(value: T | unknown): value is number;
2
+ export declare function isString<T extends string>(value: T | unknown): value is string;
3
+ export declare function isBoolean<T extends boolean>(value: T | unknown): value is boolean;
4
+ export declare function isNull<T extends null>(value: T | unknown): value is null;
5
+ export declare function isUndefined<T extends undefined>(value: T | unknown): value is undefined;
6
+ export declare function isObject<T extends object>(value: T | unknown): value is object;
7
+ export declare function isArray<T extends any[]>(value: T | unknown): value is T;
8
+ export declare function isFunction<T extends (...args: any[]) => any | void | never>(value: T | unknown): value is T;
9
+ export declare function isDate<T extends Date>(value: T | unknown): value is T;
10
+ export declare function isRegExp<T extends RegExp>(value: T | unknown): value is T;
11
+ export declare function isPromise<T extends Promise<any>>(value: T | unknown): value is T;
12
+ export declare function isSet<T extends Set<any>>(value: T | unknown): value is T;
13
+ export declare function isMap<T extends Map<any, any>>(value: T | unknown): value is T;
14
+ export declare function isFile<T extends File>(value: T | unknown): value is T;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * 拼接classname,用法与 classnames 库一致, 更推荐使用 classnames 库
3
+ *
4
+ * classnames('foo', 'bar'); // => 'foo bar'
5
+ *
6
+ classnames('foo', { bar: true }); // => 'foo bar'
7
+
8
+ classnames({ 'foo-bar': true }); // => 'foo-bar'
9
+
10
+ classnames({ 'foo-bar': false }); // => ''
11
+
12
+ classnames({ foo: true }, { bar: true }); // => 'foo bar'
13
+
14
+ classnames({ foo: true, bar: true }); // => 'foo bar'
15
+ *
16
+ * @param {...any} args
17
+ */
18
+ declare function classnames(...args: any[]): string;
19
+ export default classnames;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * This is just a simple version of deep copy
3
+ * Has a lot of edge cases bug
4
+ * If you want to use a perfect deep copy, use lodash's _.cloneDeep
5
+ * @param {T} source
6
+ * @returns object
7
+ * @example const obj1 = deepClone(obj)
8
+ */
9
+ export declare function deepClone<T>(source: T): T;
@@ -0,0 +1,6 @@
1
+ export * from './classnames';
2
+ export * from './deep-clone';
3
+ export * from './pick';
4
+ export * from './query2params';
5
+ export * from './util';
6
+ export * from './uuid';
@@ -0,0 +1,11 @@
1
+ export type TPickMany<T> = T | readonly T[];
2
+ /**
3
+ * Creates an object composed of the picked `object` properties.
4
+ * @param object The source object.
5
+ * @param paths The property names to pick, specified individually or in arrays.
6
+ * @returns Returns the new object.
7
+ * @example
8
+ * var object = { 'a': 1, 'b': 2, 'c': 3 };
9
+ * pick(object, ['a', 'c']) => { 'a': 1, 'c': 3 }
10
+ */
11
+ export declare function pick<T extends object, U extends keyof T>(object: T, ...props: TPickMany<U>[]): Pick<T, U>;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Convert query parameters to json
3
+ * @param search query string
4
+ * @param slice query separator
5
+ * @returns object
6
+ * @example params2json('?a=1&b=2&c=3') => {a:1,b:2,c:3}
7
+ */
8
+ export declare function params2json<T extends object>(search: string, slice?: string): T;
9
+ /**
10
+ * Convert json to query parameters
11
+ * @param params query parameters
12
+ * @param slice query separator
13
+ * @returns string
14
+ * @example json2params({a:1,b:2,c:3}) => 'a=1&b=2&c=3'
15
+ */
16
+ export declare function json2params<T extends object>(params: T, slice?: string): string;
17
+ /**
18
+ * Gets the field inside the url
19
+ * @param param field name
20
+ * @param search You can specify the url, default window.location.search => ?a=1&b=2
21
+ * @returns
22
+ * @example getUrlParam('a', '?a=1&b=2') => 1
23
+ */
24
+ export declare function getUrlParam(param: string, search?: string): string | null;
25
+ /**
26
+ * Filter empty values
27
+ * @param obj object
28
+ * @returns object
29
+ * @example filtrationEmpty({a:1,b:0,c:null}) => {a:1,b:0}
30
+ */
31
+ export declare function filtrationEmpty<T extends object>(obj: T): T;
32
+ /**
33
+ * Filter query parameters
34
+ * @param params query parameters
35
+ * @param filters filter fields
36
+ * @returns
37
+ * @example filterParams({a:1,b:2}, ['a']) => {b:2}
38
+ * filterParams("a=1&b=2", ['a']) => "b=2"
39
+ */
40
+ export declare function filterParams<T extends object | string>(params: T, filters?: (T extends object ? keyof T : string)[]): T;
41
+ /**
42
+ * Merge jump link
43
+ * @param url url
44
+ * @param params query parameters
45
+ * @returns string
46
+ * @example padQuery('https://www.spacego.top', {a:1,b:2}) => 'https://www.spacego.top?a=1&b=2'
47
+ */
48
+ export declare function padQuery<T extends object>(url: string, params?: T): string;
49
+ /**
50
+ * Filter query parameters
51
+ * @param url Must be a url
52
+ * @param filters filter fields
53
+ * @returns string
54
+ * @example filterQuery('https://www.spacego.top?a=1&b=2', ['a']) => 'https://www.spacego.top?b=2'
55
+ */
56
+ export declare function filterQuery(url: string, filters?: string[]): string;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * 当前是否是服务端环境
3
+ */
4
+ export declare const isSSR: boolean;
5
+ /**
6
+ * 当前是否是客户端环境
7
+ */
8
+ export declare const isClient: boolean;
9
+ /**
10
+ * Copy object data
11
+ * @param obj1 target
12
+ * @param obj2 source data
13
+ * @param exclude exclude keys
14
+ * @example ObjectCopy({a:1,b:3},{a:0,b:2,d:4}, ['a']) => {a:1,b:2}
15
+ */
16
+ export declare function ObjectAssign<T extends object, ExcludeKey extends keyof T = never>(obj1: T, obj2: Partial<T> | any, exclude?: ExcludeKey[]): T;
17
+ /**
18
+ * Get browser environment
19
+ * @returns object
20
+ */
21
+ export declare function browser(): {
22
+ isMobile: boolean;
23
+ ios: boolean;
24
+ android: boolean;
25
+ iPad: boolean;
26
+ wechat: boolean;
27
+ aliPay: boolean;
28
+ };
29
+ /**
30
+ * Fill the short digit with 0
31
+ * @param num number
32
+ * @param len length
33
+ * @returns 0**
34
+ * @example padZero(1) => '01'
35
+ */
36
+ export declare function padZero(num: number | string, len?: number): string;
37
+ /**
38
+ * Encryption character string, used by default to encrypt mobile phone numbers
39
+ * @param str string
40
+ * @param len length
41
+ * @param symbol symbol
42
+ * @param quantity * Quantity is valid only if len is number
43
+ * @returns string
44
+ * @example encryptString('12345678901', [3, 8]) => 123****8901
45
+ * @example encryptString('12345678901', 3, '*', 4) => 123****
46
+ */
47
+ export declare function encryptString(str: string, len?: number | number[], symbol?: string, quantity?: number): string;
48
+ /**
49
+ * 千分位 过滤器
50
+ * @param value key
51
+ * @param precision 保留几位小数
52
+ * @param fillZero 实际小数位小于precision时 是否补零
53
+ * @param separator 分隔符
54
+ * @example thousands(1234567.89) => 1,234,567.89
55
+ */
56
+ export declare const thousands: (value: number | string, precision?: number, fillZero?: boolean, separator?: string) => string;
57
+ export interface IDistance {
58
+ latitude: number;
59
+ longitude: number;
60
+ }
61
+ export interface IDistanceResult {
62
+ km: number;
63
+ m: number;
64
+ }
65
+ /**
66
+ * 计算两点之间的距离
67
+ * @param dot1 起点坐标{latitude: number, longitude: number}
68
+ * @param dot2 终点坐标{latitude: number, longitude: number}
69
+ * @returns 距离{km: number, m: number}
70
+ */
71
+ export declare function calculateDistance(dot1: IDistance, dot2: IDistance): IDistanceResult;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Generate a unique id
3
+ * @returns string
4
+ * @example const uid = uuid();
5
+ */
6
+ export declare function uuid(): string;
7
+ /**
8
+ * Generate random string
9
+ * @param len length
10
+ * @returns string
11
+ * @example const random = randomString(16);
12
+ */
13
+ export declare function randomString(len?: number): string;
@@ -0,0 +1,2 @@
1
+ export * from './validate';
2
+ export * from './validator';