@xfe-repo/web-utils 1.0.0
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/README.md +3 -0
- package/dist/chunk-WDFZ2WQK.mjs +24 -0
- package/dist/env.d.mts +15 -0
- package/dist/env.d.ts +15 -0
- package/dist/env.js +83 -0
- package/dist/env.mjs +50 -0
- package/dist/loadScript.d.mts +11 -0
- package/dist/loadScript.d.ts +11 -0
- package/dist/loadScript.js +101 -0
- package/dist/loadScript.mjs +60 -0
- package/dist/token.d.mts +10 -0
- package/dist/token.d.ts +10 -0
- package/dist/token.js +114 -0
- package/dist/token.mjs +76 -0
- package/dist/tools.d.mts +16 -0
- package/dist/tools.d.ts +16 -0
- package/dist/tools.js +149 -0
- package/dist/tools.mjs +117 -0
- package/dist/valid.d.mts +8 -0
- package/dist/valid.d.ts +8 -0
- package/dist/valid.js +45 -0
- package/dist/valid.mjs +17 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
__async
|
|
24
|
+
};
|
package/dist/env.d.mts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type ApiEnv = 'dev' | 'beta' | 'prod' | 'test';
|
|
2
|
+
type Business = 'erp_pc' | 'saas_pc' | 'platform_pc';
|
|
3
|
+
declare const isServer: boolean;
|
|
4
|
+
declare const isClient: boolean;
|
|
5
|
+
declare const isSSR: boolean;
|
|
6
|
+
declare const isIos: boolean;
|
|
7
|
+
declare const isAndroid: boolean;
|
|
8
|
+
declare const isWeiXin: boolean;
|
|
9
|
+
declare const isProd: boolean;
|
|
10
|
+
declare const apiEnv: ApiEnv;
|
|
11
|
+
declare const business: Business;
|
|
12
|
+
declare const getBffApi: (apiEnvFormPayload?: ApiEnv) => string;
|
|
13
|
+
declare function getEnvDomain(hostname: string): string;
|
|
14
|
+
|
|
15
|
+
export { type ApiEnv, type Business, apiEnv, business, getBffApi, getEnvDomain, isAndroid, isClient, isIos, isProd, isSSR, isServer, isWeiXin };
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type ApiEnv = 'dev' | 'beta' | 'prod' | 'test';
|
|
2
|
+
type Business = 'erp_pc' | 'saas_pc' | 'platform_pc';
|
|
3
|
+
declare const isServer: boolean;
|
|
4
|
+
declare const isClient: boolean;
|
|
5
|
+
declare const isSSR: boolean;
|
|
6
|
+
declare const isIos: boolean;
|
|
7
|
+
declare const isAndroid: boolean;
|
|
8
|
+
declare const isWeiXin: boolean;
|
|
9
|
+
declare const isProd: boolean;
|
|
10
|
+
declare const apiEnv: ApiEnv;
|
|
11
|
+
declare const business: Business;
|
|
12
|
+
declare const getBffApi: (apiEnvFormPayload?: ApiEnv) => string;
|
|
13
|
+
declare function getEnvDomain(hostname: string): string;
|
|
14
|
+
|
|
15
|
+
export { type ApiEnv, type Business, apiEnv, business, getBffApi, getEnvDomain, isAndroid, isClient, isIos, isProd, isSSR, isServer, isWeiXin };
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/env.ts
|
|
21
|
+
var env_exports = {};
|
|
22
|
+
__export(env_exports, {
|
|
23
|
+
apiEnv: () => apiEnv,
|
|
24
|
+
business: () => business,
|
|
25
|
+
getBffApi: () => getBffApi,
|
|
26
|
+
getEnvDomain: () => getEnvDomain,
|
|
27
|
+
isAndroid: () => isAndroid,
|
|
28
|
+
isClient: () => isClient,
|
|
29
|
+
isIos: () => isIos,
|
|
30
|
+
isProd: () => isProd,
|
|
31
|
+
isSSR: () => isSSR,
|
|
32
|
+
isServer: () => isServer,
|
|
33
|
+
isWeiXin: () => isWeiXin
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(env_exports);
|
|
36
|
+
var isServer = typeof window === "undefined";
|
|
37
|
+
var isClient = !isServer;
|
|
38
|
+
var isSSR = isClient && Boolean(window.__SSR_RESULT__);
|
|
39
|
+
var navigator;
|
|
40
|
+
try {
|
|
41
|
+
navigator = window.navigator;
|
|
42
|
+
} catch (e) {
|
|
43
|
+
navigator = { userAgent: "" };
|
|
44
|
+
}
|
|
45
|
+
var isIos = /ios/i.test(navigator.userAgent);
|
|
46
|
+
var isAndroid = /android/i.test(navigator.userAgent);
|
|
47
|
+
var isWeiXin = /MicroMessenger/i.test(navigator.userAgent);
|
|
48
|
+
var isProd = process.env.NODE_ENV === "production";
|
|
49
|
+
var apiEnv = process.env.REACT_APP_API_ENV;
|
|
50
|
+
var business = process.env.REACT_APP_BUSINESS;
|
|
51
|
+
var bffApiList = {
|
|
52
|
+
dev: "http://192.168.1.65:8010",
|
|
53
|
+
test: `http://test.jarvis.t.eshetang.com`,
|
|
54
|
+
beta: "https://jarvis.beta.eshetang.com",
|
|
55
|
+
prod: "https://jarvis.eshetang.com"
|
|
56
|
+
};
|
|
57
|
+
var getBffApi = (apiEnvFormPayload = apiEnv) => {
|
|
58
|
+
let matchKey = apiEnvFormPayload;
|
|
59
|
+
if (apiEnvFormPayload.startsWith("test")) {
|
|
60
|
+
return bffApiList["test"].replace("test", matchKey);
|
|
61
|
+
} else {
|
|
62
|
+
return bffApiList[apiEnvFormPayload];
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
function getEnvDomain(hostname) {
|
|
66
|
+
var _a;
|
|
67
|
+
const isTest = hostname.startsWith("test");
|
|
68
|
+
return isTest ? ((_a = hostname.match(/[^(\w*)]+.*/)) == null ? void 0 : _a[0]) || hostname : hostname;
|
|
69
|
+
}
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
apiEnv,
|
|
73
|
+
business,
|
|
74
|
+
getBffApi,
|
|
75
|
+
getEnvDomain,
|
|
76
|
+
isAndroid,
|
|
77
|
+
isClient,
|
|
78
|
+
isIos,
|
|
79
|
+
isProd,
|
|
80
|
+
isSSR,
|
|
81
|
+
isServer,
|
|
82
|
+
isWeiXin
|
|
83
|
+
});
|
package/dist/env.mjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import "./chunk-WDFZ2WQK.mjs";
|
|
2
|
+
|
|
3
|
+
// src/env.ts
|
|
4
|
+
var isServer = typeof window === "undefined";
|
|
5
|
+
var isClient = !isServer;
|
|
6
|
+
var isSSR = isClient && Boolean(window.__SSR_RESULT__);
|
|
7
|
+
var navigator;
|
|
8
|
+
try {
|
|
9
|
+
navigator = window.navigator;
|
|
10
|
+
} catch (e) {
|
|
11
|
+
navigator = { userAgent: "" };
|
|
12
|
+
}
|
|
13
|
+
var isIos = /ios/i.test(navigator.userAgent);
|
|
14
|
+
var isAndroid = /android/i.test(navigator.userAgent);
|
|
15
|
+
var isWeiXin = /MicroMessenger/i.test(navigator.userAgent);
|
|
16
|
+
var isProd = process.env.NODE_ENV === "production";
|
|
17
|
+
var apiEnv = process.env.REACT_APP_API_ENV;
|
|
18
|
+
var business = process.env.REACT_APP_BUSINESS;
|
|
19
|
+
var bffApiList = {
|
|
20
|
+
dev: "http://192.168.1.65:8010",
|
|
21
|
+
test: `http://test.jarvis.t.eshetang.com`,
|
|
22
|
+
beta: "https://jarvis.beta.eshetang.com",
|
|
23
|
+
prod: "https://jarvis.eshetang.com"
|
|
24
|
+
};
|
|
25
|
+
var getBffApi = (apiEnvFormPayload = apiEnv) => {
|
|
26
|
+
let matchKey = apiEnvFormPayload;
|
|
27
|
+
if (apiEnvFormPayload.startsWith("test")) {
|
|
28
|
+
return bffApiList["test"].replace("test", matchKey);
|
|
29
|
+
} else {
|
|
30
|
+
return bffApiList[apiEnvFormPayload];
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
function getEnvDomain(hostname) {
|
|
34
|
+
var _a;
|
|
35
|
+
const isTest = hostname.startsWith("test");
|
|
36
|
+
return isTest ? ((_a = hostname.match(/[^(\w*)]+.*/)) == null ? void 0 : _a[0]) || hostname : hostname;
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
apiEnv,
|
|
40
|
+
business,
|
|
41
|
+
getBffApi,
|
|
42
|
+
getEnvDomain,
|
|
43
|
+
isAndroid,
|
|
44
|
+
isClient,
|
|
45
|
+
isIos,
|
|
46
|
+
isProd,
|
|
47
|
+
isSSR,
|
|
48
|
+
isServer,
|
|
49
|
+
isWeiXin
|
|
50
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare class LoadScript {
|
|
2
|
+
url: string;
|
|
3
|
+
name: string;
|
|
4
|
+
static script: HTMLScriptElement;
|
|
5
|
+
isLoaded: boolean;
|
|
6
|
+
constructor(url: string, name: string);
|
|
7
|
+
load(): Promise<unknown>;
|
|
8
|
+
}
|
|
9
|
+
declare function loadSensors(): Promise<any>;
|
|
10
|
+
|
|
11
|
+
export { LoadScript as default, loadSensors };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare class LoadScript {
|
|
2
|
+
url: string;
|
|
3
|
+
name: string;
|
|
4
|
+
static script: HTMLScriptElement;
|
|
5
|
+
isLoaded: boolean;
|
|
6
|
+
constructor(url: string, name: string);
|
|
7
|
+
load(): Promise<unknown>;
|
|
8
|
+
}
|
|
9
|
+
declare function loadSensors(): Promise<any>;
|
|
10
|
+
|
|
11
|
+
export { LoadScript as default, loadSensors };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __async = (__this, __arguments, generator) => {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
var fulfilled = (value) => {
|
|
22
|
+
try {
|
|
23
|
+
step(generator.next(value));
|
|
24
|
+
} catch (e) {
|
|
25
|
+
reject(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var rejected = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
step(generator.throw(value));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/loadScript.ts
|
|
41
|
+
var loadScript_exports = {};
|
|
42
|
+
__export(loadScript_exports, {
|
|
43
|
+
default: () => LoadScript,
|
|
44
|
+
loadSensors: () => loadSensors
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(loadScript_exports);
|
|
47
|
+
var LoadScript = class _LoadScript {
|
|
48
|
+
constructor(url, name) {
|
|
49
|
+
this.url = url;
|
|
50
|
+
this.name = name;
|
|
51
|
+
this.isLoaded = false;
|
|
52
|
+
this.url = url;
|
|
53
|
+
this.name = name;
|
|
54
|
+
if (!window)
|
|
55
|
+
throw new Error("must init in client");
|
|
56
|
+
if (window[name]) {
|
|
57
|
+
this.isLoaded = true;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
_LoadScript.script = document.createElement("script");
|
|
61
|
+
_LoadScript.script.type = "text/javascript";
|
|
62
|
+
_LoadScript.script.src = url;
|
|
63
|
+
_LoadScript.script.async = true;
|
|
64
|
+
const el = document.getElementsByTagName("script")[0];
|
|
65
|
+
if (!el)
|
|
66
|
+
throw new Error("script tag not found");
|
|
67
|
+
el.parentNode.insertBefore(_LoadScript.script, el);
|
|
68
|
+
}
|
|
69
|
+
load() {
|
|
70
|
+
return new Promise((resolve) => {
|
|
71
|
+
if (window[this.name]) {
|
|
72
|
+
this.isLoaded = true;
|
|
73
|
+
resolve(true);
|
|
74
|
+
} else {
|
|
75
|
+
_LoadScript.script.addEventListener("load", () => {
|
|
76
|
+
this.isLoaded = true;
|
|
77
|
+
resolve(true);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
function loadSensors() {
|
|
84
|
+
return __async(this, null, function* () {
|
|
85
|
+
const sensorsSDK = new LoadScript("https://img.eshetang.com/sensorsdata/sensorsdata.min.js", "sensorsDataAnalytic201505");
|
|
86
|
+
yield sensorsSDK.load();
|
|
87
|
+
const sensors = window["sensorsDataAnalytic201505"];
|
|
88
|
+
sensors.init({
|
|
89
|
+
server_url: "https://bibp.xiangyaoys.com/xhj_bi/bi.gif",
|
|
90
|
+
heatmap: { clickmap: "default", scroll_notice_map: "default" },
|
|
91
|
+
show_log: false,
|
|
92
|
+
is_track_single_page: true
|
|
93
|
+
});
|
|
94
|
+
sensors.quick("autoTrack");
|
|
95
|
+
return sensors;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
loadSensors
|
|
101
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__async
|
|
3
|
+
} from "./chunk-WDFZ2WQK.mjs";
|
|
4
|
+
|
|
5
|
+
// src/loadScript.ts
|
|
6
|
+
var LoadScript = class _LoadScript {
|
|
7
|
+
constructor(url, name) {
|
|
8
|
+
this.url = url;
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.isLoaded = false;
|
|
11
|
+
this.url = url;
|
|
12
|
+
this.name = name;
|
|
13
|
+
if (!window)
|
|
14
|
+
throw new Error("must init in client");
|
|
15
|
+
if (window[name]) {
|
|
16
|
+
this.isLoaded = true;
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
_LoadScript.script = document.createElement("script");
|
|
20
|
+
_LoadScript.script.type = "text/javascript";
|
|
21
|
+
_LoadScript.script.src = url;
|
|
22
|
+
_LoadScript.script.async = true;
|
|
23
|
+
const el = document.getElementsByTagName("script")[0];
|
|
24
|
+
if (!el)
|
|
25
|
+
throw new Error("script tag not found");
|
|
26
|
+
el.parentNode.insertBefore(_LoadScript.script, el);
|
|
27
|
+
}
|
|
28
|
+
load() {
|
|
29
|
+
return new Promise((resolve) => {
|
|
30
|
+
if (window[this.name]) {
|
|
31
|
+
this.isLoaded = true;
|
|
32
|
+
resolve(true);
|
|
33
|
+
} else {
|
|
34
|
+
_LoadScript.script.addEventListener("load", () => {
|
|
35
|
+
this.isLoaded = true;
|
|
36
|
+
resolve(true);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
function loadSensors() {
|
|
43
|
+
return __async(this, null, function* () {
|
|
44
|
+
const sensorsSDK = new LoadScript("https://img.eshetang.com/sensorsdata/sensorsdata.min.js", "sensorsDataAnalytic201505");
|
|
45
|
+
yield sensorsSDK.load();
|
|
46
|
+
const sensors = window["sensorsDataAnalytic201505"];
|
|
47
|
+
sensors.init({
|
|
48
|
+
server_url: "https://bibp.xiangyaoys.com/xhj_bi/bi.gif",
|
|
49
|
+
heatmap: { clickmap: "default", scroll_notice_map: "default" },
|
|
50
|
+
show_log: false,
|
|
51
|
+
is_track_single_page: true
|
|
52
|
+
});
|
|
53
|
+
sensors.quick("autoTrack");
|
|
54
|
+
return sensors;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
LoadScript as default,
|
|
59
|
+
loadSensors
|
|
60
|
+
};
|
package/dist/token.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import cookie from 'js-cookie';
|
|
2
|
+
|
|
3
|
+
declare const cookies: cookie.CookiesStatic<string>;
|
|
4
|
+
declare function uuid(): string;
|
|
5
|
+
declare function getFingerPrint(): string;
|
|
6
|
+
declare function parseUrlQuery(): Record<string, string>;
|
|
7
|
+
declare function getUrlQuery(key: string): string | undefined;
|
|
8
|
+
declare function setUrlQuery(key: string, value: string | number, isDelete?: boolean): void;
|
|
9
|
+
|
|
10
|
+
export { cookies, getFingerPrint, getUrlQuery, parseUrlQuery, setUrlQuery, uuid };
|
package/dist/token.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import cookie from 'js-cookie';
|
|
2
|
+
|
|
3
|
+
declare const cookies: cookie.CookiesStatic<string>;
|
|
4
|
+
declare function uuid(): string;
|
|
5
|
+
declare function getFingerPrint(): string;
|
|
6
|
+
declare function parseUrlQuery(): Record<string, string>;
|
|
7
|
+
declare function getUrlQuery(key: string): string | undefined;
|
|
8
|
+
declare function setUrlQuery(key: string, value: string | number, isDelete?: boolean): void;
|
|
9
|
+
|
|
10
|
+
export { cookies, getFingerPrint, getUrlQuery, parseUrlQuery, setUrlQuery, uuid };
|
package/dist/token.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/token.ts
|
|
31
|
+
var token_exports = {};
|
|
32
|
+
__export(token_exports, {
|
|
33
|
+
cookies: () => cookies,
|
|
34
|
+
getFingerPrint: () => getFingerPrint,
|
|
35
|
+
getUrlQuery: () => getUrlQuery,
|
|
36
|
+
parseUrlQuery: () => parseUrlQuery,
|
|
37
|
+
setUrlQuery: () => setUrlQuery,
|
|
38
|
+
uuid: () => uuid
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(token_exports);
|
|
41
|
+
var import_js_cookie = __toESM(require("js-cookie"));
|
|
42
|
+
var cookies = import_js_cookie.default.withConverter({
|
|
43
|
+
read(value) {
|
|
44
|
+
return value;
|
|
45
|
+
},
|
|
46
|
+
write(value) {
|
|
47
|
+
return encodeURIComponent(`${value}`);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
function uuid() {
|
|
51
|
+
let s = [];
|
|
52
|
+
let hexDigits = "0123456789abcdef";
|
|
53
|
+
for (let i = 0; i < 36; i++) {
|
|
54
|
+
s[i] = hexDigits.substr(Math.floor(Math.random() * 16), 1);
|
|
55
|
+
}
|
|
56
|
+
s[14] = "4";
|
|
57
|
+
s[19] = hexDigits.substr(s[19] & 3 | 8, 1);
|
|
58
|
+
s[8] = s[13] = s[18] = s[23] = "-";
|
|
59
|
+
return s.join("");
|
|
60
|
+
}
|
|
61
|
+
function getFingerPrint() {
|
|
62
|
+
let fp = import_js_cookie.default.get("fp");
|
|
63
|
+
if (!fp) {
|
|
64
|
+
fp = uuid();
|
|
65
|
+
import_js_cookie.default.set("fp", fp, {
|
|
66
|
+
expires: 3650
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return fp;
|
|
70
|
+
}
|
|
71
|
+
function parseUrlQuery() {
|
|
72
|
+
let { search, hash } = window.location;
|
|
73
|
+
const queryJson = {};
|
|
74
|
+
if (!search && hash.indexOf("?") !== -1) {
|
|
75
|
+
search = `?${hash.split("?")[1]}`;
|
|
76
|
+
}
|
|
77
|
+
let query = search.match(/([?&])[^&]+/gi);
|
|
78
|
+
if (query) {
|
|
79
|
+
query.forEach((str) => {
|
|
80
|
+
let arr;
|
|
81
|
+
str = str.substring(1);
|
|
82
|
+
str = str.replace(/=/, "==");
|
|
83
|
+
arr = str.split("==");
|
|
84
|
+
queryJson[arr[0] || ""] = arr[1] ? decodeURIComponent(arr[1]) : "";
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return queryJson;
|
|
88
|
+
}
|
|
89
|
+
function getUrlQuery(key) {
|
|
90
|
+
const queryJson = parseUrlQuery();
|
|
91
|
+
return queryJson[key];
|
|
92
|
+
}
|
|
93
|
+
function setUrlQuery(key, value, isDelete) {
|
|
94
|
+
const queryJson = parseUrlQuery();
|
|
95
|
+
let { hash, origin, pathname } = window.location;
|
|
96
|
+
if (isDelete) {
|
|
97
|
+
delete queryJson[key];
|
|
98
|
+
} else {
|
|
99
|
+
queryJson[key] = String(value);
|
|
100
|
+
}
|
|
101
|
+
let newSearch = Object.entries(queryJson).map(([key2, value2]) => `${key2}=${value2}`).join("&");
|
|
102
|
+
if (newSearch)
|
|
103
|
+
newSearch = `?${newSearch}`;
|
|
104
|
+
window.history.replaceState({}, "", origin + pathname + newSearch + hash.split("?")[0]);
|
|
105
|
+
}
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
cookies,
|
|
109
|
+
getFingerPrint,
|
|
110
|
+
getUrlQuery,
|
|
111
|
+
parseUrlQuery,
|
|
112
|
+
setUrlQuery,
|
|
113
|
+
uuid
|
|
114
|
+
});
|
package/dist/token.mjs
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import "./chunk-WDFZ2WQK.mjs";
|
|
2
|
+
|
|
3
|
+
// src/token.ts
|
|
4
|
+
import cookie from "js-cookie";
|
|
5
|
+
var cookies = cookie.withConverter({
|
|
6
|
+
read(value) {
|
|
7
|
+
return value;
|
|
8
|
+
},
|
|
9
|
+
write(value) {
|
|
10
|
+
return encodeURIComponent(`${value}`);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
function uuid() {
|
|
14
|
+
let s = [];
|
|
15
|
+
let hexDigits = "0123456789abcdef";
|
|
16
|
+
for (let i = 0; i < 36; i++) {
|
|
17
|
+
s[i] = hexDigits.substr(Math.floor(Math.random() * 16), 1);
|
|
18
|
+
}
|
|
19
|
+
s[14] = "4";
|
|
20
|
+
s[19] = hexDigits.substr(s[19] & 3 | 8, 1);
|
|
21
|
+
s[8] = s[13] = s[18] = s[23] = "-";
|
|
22
|
+
return s.join("");
|
|
23
|
+
}
|
|
24
|
+
function getFingerPrint() {
|
|
25
|
+
let fp = cookie.get("fp");
|
|
26
|
+
if (!fp) {
|
|
27
|
+
fp = uuid();
|
|
28
|
+
cookie.set("fp", fp, {
|
|
29
|
+
expires: 3650
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return fp;
|
|
33
|
+
}
|
|
34
|
+
function parseUrlQuery() {
|
|
35
|
+
let { search, hash } = window.location;
|
|
36
|
+
const queryJson = {};
|
|
37
|
+
if (!search && hash.indexOf("?") !== -1) {
|
|
38
|
+
search = `?${hash.split("?")[1]}`;
|
|
39
|
+
}
|
|
40
|
+
let query = search.match(/([?&])[^&]+/gi);
|
|
41
|
+
if (query) {
|
|
42
|
+
query.forEach((str) => {
|
|
43
|
+
let arr;
|
|
44
|
+
str = str.substring(1);
|
|
45
|
+
str = str.replace(/=/, "==");
|
|
46
|
+
arr = str.split("==");
|
|
47
|
+
queryJson[arr[0] || ""] = arr[1] ? decodeURIComponent(arr[1]) : "";
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return queryJson;
|
|
51
|
+
}
|
|
52
|
+
function getUrlQuery(key) {
|
|
53
|
+
const queryJson = parseUrlQuery();
|
|
54
|
+
return queryJson[key];
|
|
55
|
+
}
|
|
56
|
+
function setUrlQuery(key, value, isDelete) {
|
|
57
|
+
const queryJson = parseUrlQuery();
|
|
58
|
+
let { hash, origin, pathname } = window.location;
|
|
59
|
+
if (isDelete) {
|
|
60
|
+
delete queryJson[key];
|
|
61
|
+
} else {
|
|
62
|
+
queryJson[key] = String(value);
|
|
63
|
+
}
|
|
64
|
+
let newSearch = Object.entries(queryJson).map(([key2, value2]) => `${key2}=${value2}`).join("&");
|
|
65
|
+
if (newSearch)
|
|
66
|
+
newSearch = `?${newSearch}`;
|
|
67
|
+
window.history.replaceState({}, "", origin + pathname + newSearch + hash.split("?")[0]);
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
cookies,
|
|
71
|
+
getFingerPrint,
|
|
72
|
+
getUrlQuery,
|
|
73
|
+
parseUrlQuery,
|
|
74
|
+
setUrlQuery,
|
|
75
|
+
uuid
|
|
76
|
+
};
|
package/dist/tools.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** mock 骨架屏数据 */
|
|
2
|
+
declare const mockSkeletons: <T>(length: number, fn?: ((id: number) => Partial<T>) | undefined) => T[];
|
|
3
|
+
declare const delayHandle: (tick: number) => Promise<void>;
|
|
4
|
+
declare function getBase64(file: File | Blob): Promise<any>;
|
|
5
|
+
declare function getObjectURL(file: File | Blob): string;
|
|
6
|
+
declare function formatterPrice(value?: string | number | undefined): string;
|
|
7
|
+
declare function formatterTax(percentTax: string): string;
|
|
8
|
+
declare const throttle: (delay: number, callback: any) => {
|
|
9
|
+
(this: any, ...args: any[]): void;
|
|
10
|
+
cancel: () => void;
|
|
11
|
+
};
|
|
12
|
+
declare const widthThrottle: (delay: number) => (target: any, _name: string, descriptor: PropertyDescriptor) => void;
|
|
13
|
+
declare const debounce: <T extends (...args: any) => any>(delay: number, callback: T) => T;
|
|
14
|
+
declare const resizeAliYun: (imgUrl?: string, width?: number) => string;
|
|
15
|
+
|
|
16
|
+
export { debounce, delayHandle, formatterPrice, formatterTax, getBase64, getObjectURL, mockSkeletons, resizeAliYun, throttle, widthThrottle };
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** mock 骨架屏数据 */
|
|
2
|
+
declare const mockSkeletons: <T>(length: number, fn?: ((id: number) => Partial<T>) | undefined) => T[];
|
|
3
|
+
declare const delayHandle: (tick: number) => Promise<void>;
|
|
4
|
+
declare function getBase64(file: File | Blob): Promise<any>;
|
|
5
|
+
declare function getObjectURL(file: File | Blob): string;
|
|
6
|
+
declare function formatterPrice(value?: string | number | undefined): string;
|
|
7
|
+
declare function formatterTax(percentTax: string): string;
|
|
8
|
+
declare const throttle: (delay: number, callback: any) => {
|
|
9
|
+
(this: any, ...args: any[]): void;
|
|
10
|
+
cancel: () => void;
|
|
11
|
+
};
|
|
12
|
+
declare const widthThrottle: (delay: number) => (target: any, _name: string, descriptor: PropertyDescriptor) => void;
|
|
13
|
+
declare const debounce: <T extends (...args: any) => any>(delay: number, callback: T) => T;
|
|
14
|
+
declare const resizeAliYun: (imgUrl?: string, width?: number) => string;
|
|
15
|
+
|
|
16
|
+
export { debounce, delayHandle, formatterPrice, formatterTax, getBase64, getObjectURL, mockSkeletons, resizeAliYun, throttle, widthThrottle };
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/tools.ts
|
|
21
|
+
var tools_exports = {};
|
|
22
|
+
__export(tools_exports, {
|
|
23
|
+
debounce: () => debounce,
|
|
24
|
+
delayHandle: () => delayHandle,
|
|
25
|
+
formatterPrice: () => formatterPrice,
|
|
26
|
+
formatterTax: () => formatterTax,
|
|
27
|
+
getBase64: () => getBase64,
|
|
28
|
+
getObjectURL: () => getObjectURL,
|
|
29
|
+
mockSkeletons: () => mockSkeletons,
|
|
30
|
+
resizeAliYun: () => resizeAliYun,
|
|
31
|
+
throttle: () => throttle,
|
|
32
|
+
widthThrottle: () => widthThrottle
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(tools_exports);
|
|
35
|
+
var mockSkeletons = (length, fn) => {
|
|
36
|
+
const mockList = [];
|
|
37
|
+
fn = fn || ((id) => ({ id }));
|
|
38
|
+
for (let i = -1; i >= -length; i--) {
|
|
39
|
+
mockList.push(fn(i));
|
|
40
|
+
}
|
|
41
|
+
return mockList;
|
|
42
|
+
};
|
|
43
|
+
var delayHandle = (tick) => {
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
if (tick > 0) {
|
|
46
|
+
setTimeout(() => resolve(), tick * 1e3);
|
|
47
|
+
} else {
|
|
48
|
+
resolve();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
function getBase64(file) {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
const reader = new FileReader();
|
|
55
|
+
reader.readAsDataURL(file);
|
|
56
|
+
reader.onload = () => resolve(reader.result);
|
|
57
|
+
reader.onerror = (error) => reject(error);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function getObjectURL(file) {
|
|
61
|
+
let url = "";
|
|
62
|
+
if (window.URL !== void 0) {
|
|
63
|
+
url = window.URL.createObjectURL(file);
|
|
64
|
+
} else if (window.webkitURL !== void 0) {
|
|
65
|
+
url = window.webkitURL.createObjectURL(file);
|
|
66
|
+
}
|
|
67
|
+
return url;
|
|
68
|
+
}
|
|
69
|
+
function formatterPrice(value = "") {
|
|
70
|
+
return parseFloat(`${value}`).toFixed(2);
|
|
71
|
+
}
|
|
72
|
+
function formatterTax(percentTax) {
|
|
73
|
+
const numberTax = parseInt(percentTax);
|
|
74
|
+
return ["0", "100"].includes(percentTax) || isNaN(numberTax) ? "" : `${numberTax}%`;
|
|
75
|
+
}
|
|
76
|
+
var throttle = (delay, callback) => {
|
|
77
|
+
let timeoutID;
|
|
78
|
+
let cancelled = false;
|
|
79
|
+
let lastExec = 0;
|
|
80
|
+
const clearExistingTimeout = () => {
|
|
81
|
+
if (timeoutID) {
|
|
82
|
+
clearTimeout(timeoutID);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const cancel = () => {
|
|
86
|
+
clearExistingTimeout();
|
|
87
|
+
cancelled = true;
|
|
88
|
+
};
|
|
89
|
+
function wrapper(...args) {
|
|
90
|
+
const elapsed = Date.now() - lastExec;
|
|
91
|
+
if (cancelled) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const exec = () => {
|
|
95
|
+
lastExec = Date.now();
|
|
96
|
+
callback.apply(this, args);
|
|
97
|
+
};
|
|
98
|
+
clearExistingTimeout();
|
|
99
|
+
if (elapsed > delay) {
|
|
100
|
+
exec();
|
|
101
|
+
} else {
|
|
102
|
+
timeoutID = setTimeout(exec, delay - elapsed);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
wrapper.cancel = cancel;
|
|
106
|
+
return wrapper;
|
|
107
|
+
};
|
|
108
|
+
var widthThrottle = (delay) => {
|
|
109
|
+
return function(target, _name, descriptor) {
|
|
110
|
+
const oldValue = descriptor.value;
|
|
111
|
+
const wrapper = throttle(delay, oldValue);
|
|
112
|
+
descriptor.value = wrapper;
|
|
113
|
+
target.componentWillUnmount = function() {
|
|
114
|
+
target.componentWillUnmount && target.componentWillUnmount();
|
|
115
|
+
wrapper.cancel();
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
var debounce = (delay, callback) => {
|
|
120
|
+
let timeoutID;
|
|
121
|
+
function wrapper(...args) {
|
|
122
|
+
if (timeoutID)
|
|
123
|
+
clearTimeout(timeoutID);
|
|
124
|
+
const exec = () => {
|
|
125
|
+
callback(...args);
|
|
126
|
+
};
|
|
127
|
+
timeoutID = setTimeout(exec, delay);
|
|
128
|
+
}
|
|
129
|
+
return wrapper;
|
|
130
|
+
};
|
|
131
|
+
var resizeAliYun = (imgUrl = "", width = 300) => {
|
|
132
|
+
if (!imgUrl || !imgUrl.startsWith("http"))
|
|
133
|
+
return imgUrl;
|
|
134
|
+
imgUrl = imgUrl.replace(/[?#].*/g, "");
|
|
135
|
+
return `${imgUrl}?x-oss-process=image/resize,w_${width}`;
|
|
136
|
+
};
|
|
137
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
138
|
+
0 && (module.exports = {
|
|
139
|
+
debounce,
|
|
140
|
+
delayHandle,
|
|
141
|
+
formatterPrice,
|
|
142
|
+
formatterTax,
|
|
143
|
+
getBase64,
|
|
144
|
+
getObjectURL,
|
|
145
|
+
mockSkeletons,
|
|
146
|
+
resizeAliYun,
|
|
147
|
+
throttle,
|
|
148
|
+
widthThrottle
|
|
149
|
+
});
|
package/dist/tools.mjs
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import "./chunk-WDFZ2WQK.mjs";
|
|
2
|
+
|
|
3
|
+
// src/tools.ts
|
|
4
|
+
var mockSkeletons = (length, fn) => {
|
|
5
|
+
const mockList = [];
|
|
6
|
+
fn = fn || ((id) => ({ id }));
|
|
7
|
+
for (let i = -1; i >= -length; i--) {
|
|
8
|
+
mockList.push(fn(i));
|
|
9
|
+
}
|
|
10
|
+
return mockList;
|
|
11
|
+
};
|
|
12
|
+
var delayHandle = (tick) => {
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
if (tick > 0) {
|
|
15
|
+
setTimeout(() => resolve(), tick * 1e3);
|
|
16
|
+
} else {
|
|
17
|
+
resolve();
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
function getBase64(file) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
const reader = new FileReader();
|
|
24
|
+
reader.readAsDataURL(file);
|
|
25
|
+
reader.onload = () => resolve(reader.result);
|
|
26
|
+
reader.onerror = (error) => reject(error);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function getObjectURL(file) {
|
|
30
|
+
let url = "";
|
|
31
|
+
if (window.URL !== void 0) {
|
|
32
|
+
url = window.URL.createObjectURL(file);
|
|
33
|
+
} else if (window.webkitURL !== void 0) {
|
|
34
|
+
url = window.webkitURL.createObjectURL(file);
|
|
35
|
+
}
|
|
36
|
+
return url;
|
|
37
|
+
}
|
|
38
|
+
function formatterPrice(value = "") {
|
|
39
|
+
return parseFloat(`${value}`).toFixed(2);
|
|
40
|
+
}
|
|
41
|
+
function formatterTax(percentTax) {
|
|
42
|
+
const numberTax = parseInt(percentTax);
|
|
43
|
+
return ["0", "100"].includes(percentTax) || isNaN(numberTax) ? "" : `${numberTax}%`;
|
|
44
|
+
}
|
|
45
|
+
var throttle = (delay, callback) => {
|
|
46
|
+
let timeoutID;
|
|
47
|
+
let cancelled = false;
|
|
48
|
+
let lastExec = 0;
|
|
49
|
+
const clearExistingTimeout = () => {
|
|
50
|
+
if (timeoutID) {
|
|
51
|
+
clearTimeout(timeoutID);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const cancel = () => {
|
|
55
|
+
clearExistingTimeout();
|
|
56
|
+
cancelled = true;
|
|
57
|
+
};
|
|
58
|
+
function wrapper(...args) {
|
|
59
|
+
const elapsed = Date.now() - lastExec;
|
|
60
|
+
if (cancelled) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const exec = () => {
|
|
64
|
+
lastExec = Date.now();
|
|
65
|
+
callback.apply(this, args);
|
|
66
|
+
};
|
|
67
|
+
clearExistingTimeout();
|
|
68
|
+
if (elapsed > delay) {
|
|
69
|
+
exec();
|
|
70
|
+
} else {
|
|
71
|
+
timeoutID = setTimeout(exec, delay - elapsed);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
wrapper.cancel = cancel;
|
|
75
|
+
return wrapper;
|
|
76
|
+
};
|
|
77
|
+
var widthThrottle = (delay) => {
|
|
78
|
+
return function(target, _name, descriptor) {
|
|
79
|
+
const oldValue = descriptor.value;
|
|
80
|
+
const wrapper = throttle(delay, oldValue);
|
|
81
|
+
descriptor.value = wrapper;
|
|
82
|
+
target.componentWillUnmount = function() {
|
|
83
|
+
target.componentWillUnmount && target.componentWillUnmount();
|
|
84
|
+
wrapper.cancel();
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
var debounce = (delay, callback) => {
|
|
89
|
+
let timeoutID;
|
|
90
|
+
function wrapper(...args) {
|
|
91
|
+
if (timeoutID)
|
|
92
|
+
clearTimeout(timeoutID);
|
|
93
|
+
const exec = () => {
|
|
94
|
+
callback(...args);
|
|
95
|
+
};
|
|
96
|
+
timeoutID = setTimeout(exec, delay);
|
|
97
|
+
}
|
|
98
|
+
return wrapper;
|
|
99
|
+
};
|
|
100
|
+
var resizeAliYun = (imgUrl = "", width = 300) => {
|
|
101
|
+
if (!imgUrl || !imgUrl.startsWith("http"))
|
|
102
|
+
return imgUrl;
|
|
103
|
+
imgUrl = imgUrl.replace(/[?#].*/g, "");
|
|
104
|
+
return `${imgUrl}?x-oss-process=image/resize,w_${width}`;
|
|
105
|
+
};
|
|
106
|
+
export {
|
|
107
|
+
debounce,
|
|
108
|
+
delayHandle,
|
|
109
|
+
formatterPrice,
|
|
110
|
+
formatterTax,
|
|
111
|
+
getBase64,
|
|
112
|
+
getObjectURL,
|
|
113
|
+
mockSkeletons,
|
|
114
|
+
resizeAliYun,
|
|
115
|
+
throttle,
|
|
116
|
+
widthThrottle
|
|
117
|
+
};
|
package/dist/valid.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const regPhone: RegExp;
|
|
2
|
+
declare const isValidPhone: (value: string) => boolean;
|
|
3
|
+
declare const regCaptchaSms: RegExp;
|
|
4
|
+
declare const isValidCaptchaSms: (value: string) => boolean;
|
|
5
|
+
declare const regNumber: RegExp;
|
|
6
|
+
declare const isValidNumber: (value: string) => boolean;
|
|
7
|
+
|
|
8
|
+
export { isValidCaptchaSms, isValidNumber, isValidPhone, regCaptchaSms, regNumber, regPhone };
|
package/dist/valid.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const regPhone: RegExp;
|
|
2
|
+
declare const isValidPhone: (value: string) => boolean;
|
|
3
|
+
declare const regCaptchaSms: RegExp;
|
|
4
|
+
declare const isValidCaptchaSms: (value: string) => boolean;
|
|
5
|
+
declare const regNumber: RegExp;
|
|
6
|
+
declare const isValidNumber: (value: string) => boolean;
|
|
7
|
+
|
|
8
|
+
export { isValidCaptchaSms, isValidNumber, isValidPhone, regCaptchaSms, regNumber, regPhone };
|
package/dist/valid.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/valid.ts
|
|
21
|
+
var valid_exports = {};
|
|
22
|
+
__export(valid_exports, {
|
|
23
|
+
isValidCaptchaSms: () => isValidCaptchaSms,
|
|
24
|
+
isValidNumber: () => isValidNumber,
|
|
25
|
+
isValidPhone: () => isValidPhone,
|
|
26
|
+
regCaptchaSms: () => regCaptchaSms,
|
|
27
|
+
regNumber: () => regNumber,
|
|
28
|
+
regPhone: () => regPhone
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(valid_exports);
|
|
31
|
+
var regPhone = /^1[3-9]\d{9}$/;
|
|
32
|
+
var isValidPhone = (value) => Boolean(regPhone.test(value.replace(/\s/g, "")));
|
|
33
|
+
var regCaptchaSms = /^\d{4}$/;
|
|
34
|
+
var isValidCaptchaSms = (value) => Boolean(regCaptchaSms.test(value.replace(/\s/g, "")));
|
|
35
|
+
var regNumber = /^\d+$/;
|
|
36
|
+
var isValidNumber = (value) => Boolean(regNumber.test(value.replace(/\s/g, "")));
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
isValidCaptchaSms,
|
|
40
|
+
isValidNumber,
|
|
41
|
+
isValidPhone,
|
|
42
|
+
regCaptchaSms,
|
|
43
|
+
regNumber,
|
|
44
|
+
regPhone
|
|
45
|
+
});
|
package/dist/valid.mjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import "./chunk-WDFZ2WQK.mjs";
|
|
2
|
+
|
|
3
|
+
// src/valid.ts
|
|
4
|
+
var regPhone = /^1[3-9]\d{9}$/;
|
|
5
|
+
var isValidPhone = (value) => Boolean(regPhone.test(value.replace(/\s/g, "")));
|
|
6
|
+
var regCaptchaSms = /^\d{4}$/;
|
|
7
|
+
var isValidCaptchaSms = (value) => Boolean(regCaptchaSms.test(value.replace(/\s/g, "")));
|
|
8
|
+
var regNumber = /^\d+$/;
|
|
9
|
+
var isValidNumber = (value) => Boolean(regNumber.test(value.replace(/\s/g, "")));
|
|
10
|
+
export {
|
|
11
|
+
isValidCaptchaSms,
|
|
12
|
+
isValidNumber,
|
|
13
|
+
isValidPhone,
|
|
14
|
+
regCaptchaSms,
|
|
15
|
+
regNumber,
|
|
16
|
+
regPhone
|
|
17
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xfe-repo/web-utils",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"exports": {
|
|
6
|
+
"./*": {
|
|
7
|
+
"import": "./dist/*.mjs",
|
|
8
|
+
"require": "./dist/*.js",
|
|
9
|
+
"types": "./dist/*.d.ts"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"js-cookie": "^3.0.5"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/js-cookie": "^3.0.5",
|
|
20
|
+
"@types/node": "^20.10.3",
|
|
21
|
+
"eslint": "^8.53.0",
|
|
22
|
+
"tsup": "^8.0.1",
|
|
23
|
+
"typescript": "^5.2.2",
|
|
24
|
+
"@xfe-repo/eslint-config": "0.0.0",
|
|
25
|
+
"@xfe-repo/typescript-config": "0.0.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsup",
|
|
29
|
+
"dev": "tsup --watch",
|
|
30
|
+
"lint": "eslint \"src/**/*.ts*\"",
|
|
31
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
32
|
+
}
|
|
33
|
+
}
|