@xfe-repo/web-utils 1.2.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.d.ts CHANGED
@@ -11,19 +11,5 @@ declare const isProduction: boolean;
11
11
  declare const release: string;
12
12
  declare const apiEnv: ApiEnv;
13
13
  declare const business: Business;
14
- declare const assetsHost = "https://imgs.xianghuanji.com/";
15
- declare const getErpSaasOrigin: (_apiEnv: ApiEnv) => string;
16
- declare const getMSaasOrigin: (_apiEnv: ApiEnv) => string;
17
- declare const isTestEnv: (_apiEnv: ApiEnv) => _apiEnv is TestEnv;
18
- declare const getEnvApi: (envApis: Record<ApiEnv, string>, _apiEnv?: ApiEnv) => string;
19
- declare const getBffApi: (_apiEnv?: ApiEnv) => string;
20
- declare function getEnvDomain(hostname: string): string;
21
- declare const sentryConfig: {
22
- dsn: string;
23
- release: string;
24
- enable: boolean;
25
- enablePerformance: boolean;
26
- debug: boolean;
27
- };
28
14
 
29
- export { type ApiEnv, type Business, type TestEnv, apiEnv, assetsHost, business, getBffApi, getEnvApi, getEnvDomain, getErpSaasOrigin, getMSaasOrigin, isAndroid, isClient, isIos, isProduction, isSSR, isServer, isTestEnv, isWeiXin, release, sentryConfig };
15
+ export { type ApiEnv, type Business, type TestEnv, apiEnv, business, isAndroid, isClient, isIos, isProduction, isSSR, isServer, isWeiXin, release };
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-
@@ -31,29 +32,29 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
32
  var env_exports = {};
32
33
  __export(env_exports, {
33
34
  apiEnv: () => apiEnv,
34
- assetsHost: () => assetsHost,
35
35
  business: () => business,
36
- getBffApi: () => getBffApi,
37
- getEnvApi: () => getEnvApi,
38
- getEnvDomain: () => getEnvDomain,
39
- getErpSaasOrigin: () => getErpSaasOrigin,
40
- getMSaasOrigin: () => getMSaasOrigin,
41
36
  isAndroid: () => isAndroid,
42
37
  isClient: () => isClient,
43
38
  isIos: () => isIos,
44
39
  isProduction: () => isProduction,
45
40
  isSSR: () => isSSR,
46
41
  isServer: () => isServer,
47
- isTestEnv: () => isTestEnv,
48
42
  isWeiXin: () => isWeiXin,
49
- release: () => release,
50
- sentryConfig: () => sentryConfig
43
+ release: () => release
51
44
  });
52
45
  module.exports = __toCommonJS(env_exports);
53
46
 
54
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
+ });
55
55
  var import_js_cookie = __toESM(require("js-cookie"));
56
56
  var import_query_string = __toESM(require("query-string"));
57
+ __reExport(storage_exports, require("querystring"));
57
58
  var cookies = import_js_cookie.default.withConverter({
58
59
  read(value) {
59
60
  return value;
@@ -62,6 +63,23 @@ var cookies = import_js_cookie.default.withConverter({
62
63
  return encodeURIComponent(`${value}`);
63
64
  }
64
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
+ }
65
83
 
66
84
  // src/env.ts
67
85
  var isServer = typeof window === "undefined";
@@ -80,86 +98,16 @@ var isProduction = process.env.NODE_ENV === "production";
80
98
  var release = process.env.REACT_APP_RELEASE || "dev";
81
99
  var apiEnv = process.env.REACT_APP_API_ENV || cookies.get("apiEnv");
82
100
  var business = process.env.REACT_APP_BUSINESS;
83
- var assetsHost = "https://imgs.xianghuanji.com/";
84
- var erpSaasOriginDic = {
85
- dev: `http://test.erp-saas.t.eshetang.com`,
86
- test: `http://test.erp-saas.t.eshetang.com`,
87
- stage: "http://stage.erp-saas.t.eshetang.com",
88
- beta: "https://erp.beta.eshetang.com",
89
- prod: "https://erp.eshetang.com"
90
- };
91
- var getErpSaasOrigin = (_apiEnv) => {
92
- if (isTestEnv(_apiEnv)) {
93
- return erpSaasOriginDic["test"].replace("test", _apiEnv);
94
- } else {
95
- return erpSaasOriginDic[_apiEnv];
96
- }
97
- };
98
- var mSaasOriginDic = {
99
- dev: `http://test.m.t.eshetang.com`,
100
- test: `http://test.m.t.eshetang.com`,
101
- stage: "http://stage.m.t.eshetang.com",
102
- beta: "https://beta.m.eshetang.com",
103
- prod: "https://m.eshetang.com"
104
- };
105
- var getMSaasOrigin = (_apiEnv) => {
106
- if (isTestEnv(_apiEnv)) {
107
- return mSaasOriginDic["test"].replace("test", _apiEnv);
108
- } else {
109
- return mSaasOriginDic[_apiEnv];
110
- }
111
- };
112
- var bffApiList = {
113
- dev: "http://localhost:6003/",
114
- test: `http://test.bff-s.t.eshetang.com/`,
115
- stage: "http://stage.bff-s.t.eshetang.com/",
116
- beta: "https://bff.beta.eshetang.com/",
117
- prod: "https://bff.eshetang.com/"
118
- };
119
- var isTestEnv = (_apiEnv) => {
120
- return _apiEnv.startsWith("test");
121
- };
122
- var getEnvApi = (envApis, _apiEnv = apiEnv) => {
123
- if (isTestEnv(_apiEnv)) {
124
- return envApis["test"].replace("test", _apiEnv);
125
- } else {
126
- return envApis[_apiEnv];
127
- }
128
- };
129
- var getBffApi = (_apiEnv = apiEnv) => {
130
- return getEnvApi(bffApiList, _apiEnv);
131
- };
132
- function getEnvDomain(hostname) {
133
- var _a;
134
- const isTest = hostname.startsWith("test");
135
- const isStage = hostname.startsWith("stage");
136
- return isTest || isStage ? ((_a = hostname.match(/[^(\w*)]+.*/)) == null ? void 0 : _a[0]) || hostname : hostname;
137
- }
138
- var sentryConfig = {
139
- dsn: "https://cb37486fcf8d44d68080373bb354e0f6@bug.dev.cm/1",
140
- release,
141
- enable: release.includes("release"),
142
- enablePerformance: release.includes("release"),
143
- debug: !isProduction
144
- };
145
101
  // Annotate the CommonJS export names for ESM import in node:
146
102
  0 && (module.exports = {
147
103
  apiEnv,
148
- assetsHost,
149
104
  business,
150
- getBffApi,
151
- getEnvApi,
152
- getEnvDomain,
153
- getErpSaasOrigin,
154
- getMSaasOrigin,
155
105
  isAndroid,
156
106
  isClient,
157
107
  isIos,
158
108
  isProduction,
159
109
  isSSR,
160
110
  isServer,
161
- isTestEnv,
162
111
  isWeiXin,
163
- release,
164
- sentryConfig
112
+ release
165
113
  });
package/dist/host.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { ApiEnv, TestEnv } from './env.js';
2
+
3
+ declare const isTestEnv: (_apiEnv: ApiEnv) => _apiEnv is TestEnv;
4
+ declare const getEnvApi: (envApis: Record<ApiEnv, string>, _apiEnv: ApiEnv) => string;
5
+ declare function getEnvDomain(hostname: string): string;
6
+ declare const getBffApi: (_apiEnv: ApiEnv) => string;
7
+
8
+ export { getBffApi, getEnvApi, getEnvDomain, isTestEnv };
package/dist/host.js ADDED
@@ -0,0 +1,61 @@
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/host.ts
21
+ var host_exports = {};
22
+ __export(host_exports, {
23
+ getBffApi: () => getBffApi,
24
+ getEnvApi: () => getEnvApi,
25
+ getEnvDomain: () => getEnvDomain,
26
+ isTestEnv: () => isTestEnv
27
+ });
28
+ module.exports = __toCommonJS(host_exports);
29
+ var isTestEnv = (_apiEnv) => {
30
+ return _apiEnv.startsWith("test");
31
+ };
32
+ var getEnvApi = (envApis, _apiEnv) => {
33
+ if (isTestEnv(_apiEnv)) {
34
+ return envApis["test"].replace("test", _apiEnv);
35
+ } else {
36
+ return envApis[_apiEnv];
37
+ }
38
+ };
39
+ function getEnvDomain(hostname) {
40
+ var _a;
41
+ const isTest = hostname.startsWith("test");
42
+ const isStage = hostname.startsWith("stage");
43
+ return isTest || isStage ? ((_a = hostname.match(/[^(\w*)]+.*/)) == null ? void 0 : _a[0]) || hostname : hostname;
44
+ }
45
+ var bffApiList = {
46
+ dev: "http://localhost:6003/",
47
+ test: `http://test.bff-s.t.eshetang.com/`,
48
+ stage: "http://stage.bff-s.t.eshetang.com/",
49
+ beta: "https://bff.beta.eshetang.com/",
50
+ prod: "https://bff.eshetang.com/"
51
+ };
52
+ var getBffApi = (_apiEnv) => {
53
+ return getEnvApi(bffApiList, _apiEnv);
54
+ };
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ getBffApi,
58
+ getEnvApi,
59
+ getEnvDomain,
60
+ isTestEnv
61
+ });
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 * from 'throttle-debounce';
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, throttle, uuid };
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
- __reExport(tools_exports, require("throttle-debounce"), module.exports);
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.2.1",
3
+ "version": "1.3.2",
4
4
  "sideEffects": false,
5
5
  "module": "dist/*.js",
6
6
  "types": "types/*.d.ts",
@@ -20,16 +20,19 @@
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
- "@xfe-repo/typescript-config": "0.0.6",
32
- "@xfe-repo/eslint-config": "0.0.5"
31
+ "@xfe-repo/eslint-config": "0.0.5",
32
+ "@xfe-repo/typescript-config": "0.0.6"
33
+ },
34
+ "publishConfig": {
35
+ "registry": "https://registry.npmjs.org/"
33
36
  },
34
37
  "scripts": {
35
38
  "build": "tsup",