@xfe-repo/web-utils 1.0.5 → 1.0.7

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.
@@ -0,0 +1,9 @@
1
+ import cookie from 'js-cookie';
2
+ import queryString, { ParseOptions, ParsedQuery } from 'query-string';
3
+
4
+ declare const cookies: cookie.CookiesStatic<string>;
5
+ declare function parseUrlQuery(options?: ParseOptions): queryString.ParsedQuery<string>;
6
+ declare function getUrlQuery(key: string): string | (string | null)[] | null | undefined;
7
+ declare function setUrlQuery(queryJson: ParsedQuery<string | boolean | number>): void;
8
+
9
+ export { cookies, getUrlQuery, parseUrlQuery, setUrlQuery };
@@ -0,0 +1,9 @@
1
+ import cookie from 'js-cookie';
2
+ import queryString, { ParseOptions, ParsedQuery } from 'query-string';
3
+
4
+ declare const cookies: cookie.CookiesStatic<string>;
5
+ declare function parseUrlQuery(options?: ParseOptions): queryString.ParsedQuery<string>;
6
+ declare function getUrlQuery(key: string): string | (string | null)[] | null | undefined;
7
+ declare function setUrlQuery(queryJson: ParsedQuery<string | boolean | number>): void;
8
+
9
+ export { cookies, getUrlQuery, parseUrlQuery, setUrlQuery };
@@ -27,18 +27,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
- // src/token.ts
31
- var token_exports = {};
32
- __export(token_exports, {
30
+ // src/storage.ts
31
+ var storage_exports = {};
32
+ __export(storage_exports, {
33
33
  cookies: () => cookies,
34
- getFingerPrint: () => getFingerPrint,
35
34
  getUrlQuery: () => getUrlQuery,
36
35
  parseUrlQuery: () => parseUrlQuery,
37
- setUrlQuery: () => setUrlQuery,
38
- uuid: () => uuid
36
+ setUrlQuery: () => setUrlQuery
39
37
  });
40
- module.exports = __toCommonJS(token_exports);
38
+ module.exports = __toCommonJS(storage_exports);
41
39
  var import_js_cookie = __toESM(require("js-cookie"));
40
+ var import_query_string = __toESM(require("query-string"));
42
41
  var cookies = import_js_cookie.default.withConverter({
43
42
  read(value) {
44
43
  return value;
@@ -47,68 +46,27 @@ var cookies = import_js_cookie.default.withConverter({
47
46
  return encodeURIComponent(`${value}`);
48
47
  }
49
48
  });
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() {
49
+ function parseUrlQuery(options) {
72
50
  let { search, hash } = window.location;
73
- const queryJson = {};
74
51
  if (!search && hash.indexOf("?") !== -1) {
75
52
  search = `?${hash.split("?")[1]}`;
76
53
  }
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;
54
+ return import_query_string.default.parse(search, options);
88
55
  }
89
56
  function getUrlQuery(key) {
90
- const queryJson = parseUrlQuery();
57
+ const queryJson = parseUrlQuery({ parseBooleans: true, parseNumbers: true });
91
58
  return queryJson[key];
92
59
  }
93
- function setUrlQuery(key, value, isDelete) {
94
- const queryJson = parseUrlQuery();
60
+ function setUrlQuery(queryJson) {
95
61
  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]);
62
+ const search = import_query_string.default.stringify(queryJson, { skipNull: true, skipEmptyString: true });
63
+ const url = `${origin}${pathname}${search ? `?${search}` : ""}${hash.split("?")[0]}`;
64
+ window.history.replaceState({}, "", url);
105
65
  }
106
66
  // Annotate the CommonJS export names for ESM import in node:
107
67
  0 && (module.exports = {
108
68
  cookies,
109
- getFingerPrint,
110
69
  getUrlQuery,
111
70
  parseUrlQuery,
112
- setUrlQuery,
113
- uuid
71
+ setUrlQuery
114
72
  });
@@ -0,0 +1,36 @@
1
+ import "./chunk-6BSPRPK2.mjs";
2
+
3
+ // src/storage.ts
4
+ import cookie from "js-cookie";
5
+ import queryString from "query-string";
6
+ var cookies = cookie.withConverter({
7
+ read(value) {
8
+ return value;
9
+ },
10
+ write(value) {
11
+ return encodeURIComponent(`${value}`);
12
+ }
13
+ });
14
+ function parseUrlQuery(options) {
15
+ let { search, hash } = window.location;
16
+ if (!search && hash.indexOf("?") !== -1) {
17
+ search = `?${hash.split("?")[1]}`;
18
+ }
19
+ return queryString.parse(search, options);
20
+ }
21
+ function getUrlQuery(key) {
22
+ const queryJson = parseUrlQuery({ parseBooleans: true, parseNumbers: true });
23
+ return queryJson[key];
24
+ }
25
+ function setUrlQuery(queryJson) {
26
+ let { hash, origin, pathname } = window.location;
27
+ const search = queryString.stringify(queryJson, { skipNull: true, skipEmptyString: true });
28
+ const url = `${origin}${pathname}${search ? `?${search}` : ""}${hash.split("?")[0]}`;
29
+ window.history.replaceState({}, "", url);
30
+ }
31
+ export {
32
+ cookies,
33
+ getUrlQuery,
34
+ parseUrlQuery,
35
+ setUrlQuery
36
+ };
package/dist/tools.d.mts CHANGED
@@ -11,6 +11,7 @@ declare const throttle: (delay: number, callback: any) => {
11
11
  };
12
12
  declare const widthThrottle: (delay: number) => (target: any, _name: string, descriptor: PropertyDescriptor) => void;
13
13
  declare const debounce: <T extends (...args: any) => any>(delay: number, callback: T) => T;
14
+ declare function uuid(): string;
14
15
  declare const imgRelative2Absolute: (imgUrl?: string) => string;
15
16
  declare const resizeAliYun: (imgUrl?: string, width?: number | null, quality?: number) => string;
16
17
  type FieldsWithoutArray<FS extends Record<string, any>> = {
@@ -40,4 +41,4 @@ declare const combobox2Options: <CB extends Record<string, (ComboBox<number> | C
40
41
  optionsMap: OptionsMapType<keyof CB>;
41
42
  };
42
43
 
43
- export { type ComboBox, type OptionsMapType, type OptionsRecordType, type OptionsType, combobox2Options, debounce, delayHandle, fieldsArrayToString, fieldsReset, formatterPrice, formatterTax, getBase64, getObjectURL, imgRelative2Absolute, mockSkeletons, resizeAliYun, throttle, widthThrottle };
44
+ export { type ComboBox, type OptionsMapType, type OptionsRecordType, type OptionsType, combobox2Options, debounce, delayHandle, fieldsArrayToString, fieldsReset, formatterPrice, formatterTax, getBase64, getObjectURL, imgRelative2Absolute, mockSkeletons, resizeAliYun, throttle, uuid, widthThrottle };
package/dist/tools.d.ts CHANGED
@@ -11,6 +11,7 @@ declare const throttle: (delay: number, callback: any) => {
11
11
  };
12
12
  declare const widthThrottle: (delay: number) => (target: any, _name: string, descriptor: PropertyDescriptor) => void;
13
13
  declare const debounce: <T extends (...args: any) => any>(delay: number, callback: T) => T;
14
+ declare function uuid(): string;
14
15
  declare const imgRelative2Absolute: (imgUrl?: string) => string;
15
16
  declare const resizeAliYun: (imgUrl?: string, width?: number | null, quality?: number) => string;
16
17
  type FieldsWithoutArray<FS extends Record<string, any>> = {
@@ -40,4 +41,4 @@ declare const combobox2Options: <CB extends Record<string, (ComboBox<number> | C
40
41
  optionsMap: OptionsMapType<keyof CB>;
41
42
  };
42
43
 
43
- export { type ComboBox, type OptionsMapType, type OptionsRecordType, type OptionsType, combobox2Options, debounce, delayHandle, fieldsArrayToString, fieldsReset, formatterPrice, formatterTax, getBase64, getObjectURL, imgRelative2Absolute, mockSkeletons, resizeAliYun, throttle, widthThrottle };
44
+ export { type ComboBox, type OptionsMapType, type OptionsRecordType, type OptionsType, combobox2Options, debounce, delayHandle, fieldsArrayToString, fieldsReset, formatterPrice, formatterTax, getBase64, getObjectURL, imgRelative2Absolute, mockSkeletons, resizeAliYun, throttle, uuid, widthThrottle };
package/dist/tools.js CHANGED
@@ -47,6 +47,7 @@ __export(tools_exports, {
47
47
  mockSkeletons: () => mockSkeletons,
48
48
  resizeAliYun: () => resizeAliYun,
49
49
  throttle: () => throttle,
50
+ uuid: () => uuid,
50
51
  widthThrottle: () => widthThrottle
51
52
  });
52
53
  module.exports = __toCommonJS(tools_exports);
@@ -164,6 +165,17 @@ var debounce = (delay, callback) => {
164
165
  }
165
166
  return wrapper;
166
167
  };
168
+ function uuid() {
169
+ let s = [];
170
+ let hexDigits = "0123456789abcdef";
171
+ for (let i = 0; i < 36; i++) {
172
+ s[i] = hexDigits.substr(Math.floor(Math.random() * 16), 1);
173
+ }
174
+ s[14] = "4";
175
+ s[19] = hexDigits.substr(s[19] & 3 | 8, 1);
176
+ s[8] = s[13] = s[18] = s[23] = "-";
177
+ return s.join("");
178
+ }
167
179
  var imgRelative2Absolute = (imgUrl = "") => {
168
180
  if (!imgUrl)
169
181
  return imgUrl;
@@ -245,5 +257,6 @@ var combobox2Options = (comboBox) => {
245
257
  mockSkeletons,
246
258
  resizeAliYun,
247
259
  throttle,
260
+ uuid,
248
261
  widthThrottle
249
262
  });
package/dist/tools.mjs CHANGED
@@ -108,6 +108,17 @@ var debounce = (delay, callback) => {
108
108
  }
109
109
  return wrapper;
110
110
  };
111
+ function uuid() {
112
+ let s = [];
113
+ let hexDigits = "0123456789abcdef";
114
+ for (let i = 0; i < 36; i++) {
115
+ s[i] = hexDigits.substr(Math.floor(Math.random() * 16), 1);
116
+ }
117
+ s[14] = "4";
118
+ s[19] = hexDigits.substr(s[19] & 3 | 8, 1);
119
+ s[8] = s[13] = s[18] = s[23] = "-";
120
+ return s.join("");
121
+ }
111
122
  var imgRelative2Absolute = (imgUrl = "") => {
112
123
  if (!imgUrl)
113
124
  return imgUrl;
@@ -188,5 +199,6 @@ export {
188
199
  mockSkeletons,
189
200
  resizeAliYun,
190
201
  throttle,
202
+ uuid,
191
203
  widthThrottle
192
204
  };
package/package.json CHANGED
@@ -1,25 +1,29 @@
1
1
  {
2
2
  "name": "@xfe-repo/web-utils",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "sideEffects": false,
5
5
  "exports": {
6
6
  "./*": {
7
7
  "import": {
8
8
  "types": "./dist/*.d.mts",
9
- "require": "./dist/*.mjs"
9
+ "default": "./dist/*.mjs"
10
10
  },
11
11
  "require": {
12
12
  "types": "./dist/*.d.ts",
13
13
  "default": "./dist/*.js"
14
14
  },
15
- "default": "./dist/*.js"
15
+ "default": {
16
+ "types": "./dist/*.d.ts",
17
+ "default": "./dist/*.js"
18
+ }
16
19
  }
17
20
  },
18
21
  "files": [
19
22
  "dist"
20
23
  ],
21
24
  "dependencies": {
22
- "js-cookie": "^3.0.5"
25
+ "js-cookie": "^3.0.5",
26
+ "query-string": "^7.1.3"
23
27
  },
24
28
  "devDependencies": {
25
29
  "@types/js-cookie": "^3.0.5",
@@ -1,24 +0,0 @@
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/token.d.mts DELETED
@@ -1,10 +0,0 @@
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 DELETED
@@ -1,10 +0,0 @@
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.mjs DELETED
@@ -1,76 +0,0 @@
1
- import "./chunk-6BSPRPK2.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
- };