@xfe-repo/web-utils 1.3.1 → 1.3.2
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/dist/env.js +26 -0
- package/dist/storage.d.ts +1 -0
- package/dist/storage.js +4 -1
- package/dist/tools.d.ts +2 -6
- package/dist/tools.js +5 -37
- package/package.json +2 -2
package/dist/env.js
CHANGED
|
@@ -17,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
21
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
22
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
23
|
// file that has been converted to a CommonJS file using a Babel-
|
|
@@ -44,8 +45,16 @@ __export(env_exports, {
|
|
|
44
45
|
module.exports = __toCommonJS(env_exports);
|
|
45
46
|
|
|
46
47
|
// src/storage.ts
|
|
48
|
+
var storage_exports = {};
|
|
49
|
+
__export(storage_exports, {
|
|
50
|
+
cookies: () => cookies,
|
|
51
|
+
getUrlQuery: () => getUrlQuery,
|
|
52
|
+
parseUrlQuery: () => parseUrlQuery,
|
|
53
|
+
setUrlQuery: () => setUrlQuery
|
|
54
|
+
});
|
|
47
55
|
var import_js_cookie = __toESM(require("js-cookie"));
|
|
48
56
|
var import_query_string = __toESM(require("query-string"));
|
|
57
|
+
__reExport(storage_exports, require("querystring"));
|
|
49
58
|
var cookies = import_js_cookie.default.withConverter({
|
|
50
59
|
read(value) {
|
|
51
60
|
return value;
|
|
@@ -54,6 +63,23 @@ var cookies = import_js_cookie.default.withConverter({
|
|
|
54
63
|
return encodeURIComponent(`${value}`);
|
|
55
64
|
}
|
|
56
65
|
});
|
|
66
|
+
function parseUrlQuery(options) {
|
|
67
|
+
let { search, hash } = window.location;
|
|
68
|
+
if (!search && hash.indexOf("?") !== -1) {
|
|
69
|
+
search = `?${hash.split("?")[1]}`;
|
|
70
|
+
}
|
|
71
|
+
return import_query_string.default.parse(search, options);
|
|
72
|
+
}
|
|
73
|
+
function getUrlQuery(key) {
|
|
74
|
+
const queryJson = parseUrlQuery({ parseBooleans: true, parseNumbers: true });
|
|
75
|
+
return queryJson[key];
|
|
76
|
+
}
|
|
77
|
+
function setUrlQuery(queryJson) {
|
|
78
|
+
let { hash } = window.location;
|
|
79
|
+
const search = import_query_string.default.stringify(queryJson, { skipNull: true, skipEmptyString: true });
|
|
80
|
+
const url = `?${search}${hash.split("?")[0]}`;
|
|
81
|
+
window.history.replaceState({}, "", url);
|
|
82
|
+
}
|
|
57
83
|
|
|
58
84
|
// src/env.ts
|
|
59
85
|
var isServer = typeof window === "undefined";
|
package/dist/storage.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import cookie from 'js-cookie';
|
|
2
2
|
import queryString, { ParseOptions, ParsedQuery } from 'query-string';
|
|
3
|
+
export * from 'querystring';
|
|
3
4
|
|
|
4
5
|
declare const cookies: cookie.CookiesStatic<string>;
|
|
5
6
|
declare function parseUrlQuery(options?: ParseOptions): queryString.ParsedQuery<string>;
|
package/dist/storage.js
CHANGED
|
@@ -17,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
21
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
22
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
23
|
// file that has been converted to a CommonJS file using a Babel-
|
|
@@ -38,6 +39,7 @@ __export(storage_exports, {
|
|
|
38
39
|
module.exports = __toCommonJS(storage_exports);
|
|
39
40
|
var import_js_cookie = __toESM(require("js-cookie"));
|
|
40
41
|
var import_query_string = __toESM(require("query-string"));
|
|
42
|
+
__reExport(storage_exports, require("querystring"), module.exports);
|
|
41
43
|
var cookies = import_js_cookie.default.withConverter({
|
|
42
44
|
read(value) {
|
|
43
45
|
return value;
|
|
@@ -68,5 +70,6 @@ function setUrlQuery(queryJson) {
|
|
|
68
70
|
cookies,
|
|
69
71
|
getUrlQuery,
|
|
70
72
|
parseUrlQuery,
|
|
71
|
-
setUrlQuery
|
|
73
|
+
setUrlQuery,
|
|
74
|
+
...require("querystring")
|
|
72
75
|
});
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { debounce, throttle } from 'throttle-debounce';
|
|
2
2
|
|
|
3
3
|
/** mock 骨架屏数据 */
|
|
4
4
|
declare const mockSkeletons: <T>(length: number, fn?: (id: number) => Partial<T>) => T[];
|
|
@@ -7,10 +7,6 @@ declare function getBase64(file: File | Blob): Promise<any>;
|
|
|
7
7
|
declare function getObjectURL(file: File | Blob): string;
|
|
8
8
|
declare function formatterPrice(value?: string | number | undefined): string;
|
|
9
9
|
declare function formatterTax(percentTax: string): string;
|
|
10
|
-
declare const throttle: (delay: number, callback: any) => {
|
|
11
|
-
(this: any, ...args: any[]): void;
|
|
12
|
-
cancel: () => void;
|
|
13
|
-
};
|
|
14
10
|
declare function uuid(): string;
|
|
15
11
|
declare const imgRelative2Absolute: (imgUrl?: string) => string;
|
|
16
12
|
declare const resizeAliYun: (imgUrl?: string, width?: number | null, quality?: number) => string;
|
|
@@ -41,4 +37,4 @@ declare const combobox2Options: <CB extends Record<string, (ComboBox | ComboBox<
|
|
|
41
37
|
optionsMap: OptionsMapType<keyof CB>;
|
|
42
38
|
};
|
|
43
39
|
|
|
44
|
-
export { type ComboBox, type OptionsMapType, type OptionsRecordType, type OptionsType, combobox2Options, delayHandle, fieldsArrayToString, fieldsReset, formatterPrice, formatterTax, getBase64, getObjectURL, imgRelative2Absolute, mockSkeletons, resizeAliYun,
|
|
40
|
+
export { type ComboBox, type OptionsMapType, type OptionsRecordType, type OptionsType, combobox2Options, delayHandle, fieldsArrayToString, fieldsReset, formatterPrice, formatterTax, getBase64, getObjectURL, imgRelative2Absolute, mockSkeletons, resizeAliYun, uuid };
|
package/dist/tools.js
CHANGED
|
@@ -29,13 +29,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
29
29
|
}
|
|
30
30
|
return to;
|
|
31
31
|
};
|
|
32
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
33
32
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
33
|
|
|
35
34
|
// src/tools.ts
|
|
36
35
|
var tools_exports = {};
|
|
37
36
|
__export(tools_exports, {
|
|
38
37
|
combobox2Options: () => combobox2Options,
|
|
38
|
+
debounce: () => import_throttle_debounce.debounce,
|
|
39
39
|
delayHandle: () => delayHandle,
|
|
40
40
|
fieldsArrayToString: () => fieldsArrayToString,
|
|
41
41
|
fieldsReset: () => fieldsReset,
|
|
@@ -46,7 +46,7 @@ __export(tools_exports, {
|
|
|
46
46
|
imgRelative2Absolute: () => imgRelative2Absolute,
|
|
47
47
|
mockSkeletons: () => mockSkeletons,
|
|
48
48
|
resizeAliYun: () => resizeAliYun,
|
|
49
|
-
throttle: () => throttle,
|
|
49
|
+
throttle: () => import_throttle_debounce.throttle,
|
|
50
50
|
uuid: () => uuid
|
|
51
51
|
});
|
|
52
52
|
module.exports = __toCommonJS(tools_exports);
|
|
@@ -68,7 +68,7 @@ var regAssets = /^(\/(assets|static))/i;
|
|
|
68
68
|
var isAssets = (value) => Boolean(regAssets.test(value.replace(/\s/g, "")));
|
|
69
69
|
|
|
70
70
|
// src/tools.ts
|
|
71
|
-
|
|
71
|
+
var import_throttle_debounce = require("throttle-debounce");
|
|
72
72
|
var mockSkeletons = (length, fn) => {
|
|
73
73
|
const mockList = [];
|
|
74
74
|
fn = fn || ((id) => ({ id }));
|
|
@@ -110,38 +110,6 @@ function formatterTax(percentTax) {
|
|
|
110
110
|
const numberTax = parseInt(percentTax);
|
|
111
111
|
return ["0", "100"].includes(percentTax) || isNaN(numberTax) ? "" : `${numberTax}%`;
|
|
112
112
|
}
|
|
113
|
-
var throttle = (delay, callback) => {
|
|
114
|
-
let timeoutID;
|
|
115
|
-
let cancelled = false;
|
|
116
|
-
let lastExec = 0;
|
|
117
|
-
const clearExistingTimeout = () => {
|
|
118
|
-
if (timeoutID) {
|
|
119
|
-
clearTimeout(timeoutID);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
const cancel = () => {
|
|
123
|
-
clearExistingTimeout();
|
|
124
|
-
cancelled = true;
|
|
125
|
-
};
|
|
126
|
-
function wrapper(...args) {
|
|
127
|
-
const elapsed = Date.now() - lastExec;
|
|
128
|
-
if (cancelled) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
const exec = () => {
|
|
132
|
-
lastExec = Date.now();
|
|
133
|
-
callback.apply(this, args);
|
|
134
|
-
};
|
|
135
|
-
clearExistingTimeout();
|
|
136
|
-
if (elapsed > delay) {
|
|
137
|
-
exec();
|
|
138
|
-
} else {
|
|
139
|
-
timeoutID = setTimeout(exec, delay - elapsed);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
wrapper.cancel = cancel;
|
|
143
|
-
return wrapper;
|
|
144
|
-
};
|
|
145
113
|
function uuid() {
|
|
146
114
|
let s = [];
|
|
147
115
|
let hexDigits = "0123456789abcdef";
|
|
@@ -215,6 +183,7 @@ var combobox2Options = (comboBox) => {
|
|
|
215
183
|
// Annotate the CommonJS export names for ESM import in node:
|
|
216
184
|
0 && (module.exports = {
|
|
217
185
|
combobox2Options,
|
|
186
|
+
debounce,
|
|
218
187
|
delayHandle,
|
|
219
188
|
fieldsArrayToString,
|
|
220
189
|
fieldsReset,
|
|
@@ -226,6 +195,5 @@ var combobox2Options = (comboBox) => {
|
|
|
226
195
|
mockSkeletons,
|
|
227
196
|
resizeAliYun,
|
|
228
197
|
throttle,
|
|
229
|
-
uuid
|
|
230
|
-
...require("throttle-debounce")
|
|
198
|
+
uuid
|
|
231
199
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xfe-repo/web-utils",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"module": "dist/*.js",
|
|
6
6
|
"types": "types/*.d.ts",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"@types/throttle-debounce": "^5.0.2",
|
|
23
24
|
"throttle-debounce": "^5.0.2",
|
|
24
25
|
"js-cookie": "^3.0.5",
|
|
25
26
|
"query-string": "^7.1.3"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"@types/throttle-debounce": "^5.0.2",
|
|
29
29
|
"@types/js-cookie": "^3.0.5",
|
|
30
30
|
"@types/node": "^20.10.3",
|
|
31
31
|
"@xfe-repo/eslint-config": "0.0.5",
|