@whitesev/utils 2.2.8 → 2.3.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.
@@ -0,0 +1,43 @@
1
+ declare class RefImpl {
2
+ _value: any;
3
+ _isRef: boolean;
4
+ _rawValue: any;
5
+ _vue: Vue;
6
+ constructor(vueIns: Vue, rawValue: any);
7
+ get value(): any;
8
+ set value(newValue: any);
9
+ }
10
+ declare class ObjectRefImpl {
11
+ object: any;
12
+ key: any;
13
+ constructor(object: any, key: any);
14
+ get value(): any;
15
+ set value(newValue: any);
16
+ }
17
+ export declare class Vue {
18
+ private reactMap;
19
+ private targetMap;
20
+ private activeEffect;
21
+ constructor();
22
+ /**
23
+ * 生成一个被代理的对象
24
+ * @param target 需要代理的对象
25
+ */
26
+ reactive<T extends object>(target: T): T;
27
+ /**
28
+ * 观察被reactive的对象值改变
29
+ * @param source 被观察的对象,这里采用函数返回对象
30
+ * @param changeCallBack 值改变的回调
31
+ */
32
+ watch<T>(source: () => T, changeCallBack: (newValue: T | undefined, oldValue: T | undefined) => void): void;
33
+ toReactive(value: any): any;
34
+ ref(value: any): RefImpl;
35
+ toRef(object: any, key: any): ObjectRefImpl;
36
+ toRefs(object: any): {};
37
+ private trigger;
38
+ private triggerEffect;
39
+ private track;
40
+ private trackEffect;
41
+ private traversal;
42
+ }
43
+ export {};
@@ -1,110 +1,110 @@
1
- import type { AnyObject } from "./Utils";
2
- export declare interface Vue2Object extends AnyObject {
3
- $attrs: AnyObject;
4
- $children: Vue2Object[];
5
- $createElement: (...args: any[]) => any;
6
- $el: HTMLElement;
7
- $listeners: AnyObject;
8
- $options: AnyObject;
9
- $parent: Vue2Object;
10
- $refs: AnyObject;
11
- $root: Vue2Object;
12
- $scopedSlots: AnyObject;
13
- $slots: AnyObject;
14
- $store: AnyObject;
15
- $vnode: AnyObject;
16
- _data: AnyObject;
17
- _directInactive: boolean;
18
- _events: AnyObject;
19
- _hasHookEvent: boolean;
20
- _isBeingDestroyed: boolean;
21
- _isDestroyed: boolean;
22
- _isMounted: boolean;
23
- _isVue: boolean;
24
- $data: AnyObject;
25
- $isServer: boolean;
26
- $props: AnyObject;
27
- $route: AnyObject & {
28
- fullPath: string;
29
- hash: string;
30
- matched: AnyObject[];
31
- meta: AnyObject;
32
- name: string;
33
- params: AnyObject;
34
- path: string;
35
- query: AnyObject;
36
- };
37
- $router: AnyObject & {
38
- afterHooks: Function[];
39
- app: Vue2Object;
40
- apps: Vue2Object[];
41
- beforeHooks: Function[];
42
- fallback: boolean;
43
- history: AnyObject & {
44
- base: string;
45
- current: AnyObject;
46
- listeners: AnyObject[];
47
- router: Vue2Object["$router"];
48
- /**
49
- *
50
- * @param delta 访问的距离。如果 delta < 0 则后退相应数量的记录,如果 > 0 则前进。
51
- * @param triggerListeners 是否应该触发连接到该历史的监听器
52
- * @returns
53
- */
54
- go: (delta: number, triggerListeners?: boolean) => void;
55
- /**
56
- *
57
- * @param to 要设置的地址
58
- * @param data 可选的 HistoryState 以关联该导航记录
59
- * @returns
60
- */
61
- push: (to: string, data?: AnyObject) => void;
62
- /**
63
- *
64
- * @param to 要设置的地址
65
- * @param data 可选的 HistoryState 以关联该导航记录
66
- * @returns
67
- */
68
- replace: (to: string, data?: AnyObject) => void;
69
- };
70
- matcher: AnyObject & {
71
- addRoute: (...args: any[]) => any;
72
- addRoutes: (...args: any[]) => any;
73
- getRoutes: () => any;
74
- match: (...args: any[]) => any;
75
- };
76
- mode: string;
77
- resolveHooks: ((...args: any[]) => any)[];
78
- currentRoute: AnyObject;
79
- beforeEach: (callback: ((
80
- /** 即将要进入的目标 路由对象 */
81
- to: Vue2Object["$route"],
82
- /** 当前导航正要离开的路由 */
83
- from: Vue2Object["$route"],
84
- /**
85
- *
86
- * + next(): 进行管道中的下一个钩子。如果全部钩子执行完了,则导航的状态就是 confirmed (确认的)
87
- * + next(false): 中断当前的导航。如果浏览器的 URL 改变了 (可能是用户手动或者浏览器后退按钮),那么 URL 地址会重置到 from 路由对应的地址。
88
- * + next('/') 或者 next({ path: '/' }): 跳转到一个不同的地址。当前的导航被中断,然后进行一个新的导航。你可以向 next 传递任意位置对象,且允许设置诸如 replace: true、name: 'home' 之类的选项以及任何用在 router-link 的 to prop 或 router.push 中的选项。
89
- * + next(error): (2.4.0+) 如果传入 next 的参数是一个 Error 实例,则导航会被终止且该错误会被传递给 router.onError() 注册过的回调。
90
- */
91
- next: Function) => void)
92
- /** 移除上一个添加的监听 */
93
- | (() => void)) => void;
94
- afterEach: (callback: ((
95
- /** 即将要进入的目标 路由对象 */
96
- to: Vue2Object["$route"],
97
- /** 当前导航正要离开的路由 */
98
- from: Vue2Object["$route"]) => void)
99
- /** 移除上一个添加的监听 */
100
- | (() => void)) => void;
101
- };
102
- $ssrContext: AnyObject;
103
- $watch: (key: string | string[] | (() => any), handler: (this: any, newVal: any, oldVal: any) => void, options?: {
104
- immediate?: boolean;
105
- deep?: boolean;
106
- }) => void;
107
- }
108
- export declare interface HTMLVue2DivElement extends HTMLDivElement {
109
- __vue__: Vue2Object;
110
- }
1
+ export declare interface Vue2Object {
2
+ $attrs: any;
3
+ $children: Vue2Object[];
4
+ $createElement: (...args: any[]) => any;
5
+ $el: HTMLElement;
6
+ $listeners: any;
7
+ $options: any;
8
+ $parent: Vue2Object;
9
+ $refs: any;
10
+ $root: Vue2Object;
11
+ $scopedSlots: any;
12
+ $slots: any;
13
+ $store: any;
14
+ $vnode: any;
15
+ _data: any;
16
+ _directInactive: boolean;
17
+ _events: any;
18
+ _hasHookEvent: boolean;
19
+ _isBeingDestroyed: boolean;
20
+ _isDestroyed: boolean;
21
+ _isMounted: boolean;
22
+ _isVue: boolean;
23
+ $data: any;
24
+ $isServer: boolean;
25
+ $props: any;
26
+ $route: any & {
27
+ fullPath: string;
28
+ hash: string;
29
+ matched: any[];
30
+ meta: any;
31
+ name: string;
32
+ params: any;
33
+ path: string;
34
+ query: any;
35
+ };
36
+ $router: any & {
37
+ afterHooks: Function[];
38
+ app: Vue2Object;
39
+ apps: Vue2Object[];
40
+ beforeHooks: Function[];
41
+ fallback: boolean;
42
+ history: any & {
43
+ base: string;
44
+ current: any;
45
+ listeners: any[];
46
+ router: Vue2Object["$router"];
47
+ /**
48
+ *
49
+ * @param delta 访问的距离。如果 delta < 0 则后退相应数量的记录,如果 > 0 则前进。
50
+ * @param triggerListeners 是否应该触发连接到该历史的监听器
51
+ * @returns
52
+ */
53
+ go: (delta: number, triggerListeners?: boolean) => void;
54
+ /**
55
+ *
56
+ * @param to 要设置的地址
57
+ * @param data 可选的 HistoryState 以关联该导航记录
58
+ * @returns
59
+ */
60
+ push: (to: string, data?: any) => void;
61
+ /**
62
+ *
63
+ * @param to 要设置的地址
64
+ * @param data 可选的 HistoryState 以关联该导航记录
65
+ * @returns
66
+ */
67
+ replace: (to: string, data?: any) => void;
68
+ };
69
+ matcher: any & {
70
+ addRoute: (...args: any[]) => any;
71
+ addRoutes: (...args: any[]) => any;
72
+ getRoutes: () => any;
73
+ match: (...args: any[]) => any;
74
+ };
75
+ mode: string;
76
+ resolveHooks: ((...args: any[]) => any)[];
77
+ currentRoute: any;
78
+ beforeEach: (callback: ((
79
+ /** 即将要进入的目标 路由对象 */
80
+ to: Vue2Object["$route"],
81
+ /** 当前导航正要离开的路由 */
82
+ from: Vue2Object["$route"],
83
+ /**
84
+ *
85
+ * + next(): 进行管道中的下一个钩子。如果全部钩子执行完了,则导航的状态就是 confirmed (确认的)。
86
+ * + next(false): 中断当前的导航。如果浏览器的 URL 改变了 (可能是用户手动或者浏览器后退按钮),那么 URL 地址会重置到 from 路由对应的地址。
87
+ * + next('/') 或者 next({ path: '/' }): 跳转到一个不同的地址。当前的导航被中断,然后进行一个新的导航。你可以向 next 传递任意位置对象,且允许设置诸如 replace: true、name: 'home' 之类的选项以及任何用在 router-link 的 to prop 或 router.push 中的选项。
88
+ * + next(error): (2.4.0+) 如果传入 next 的参数是一个 Error 实例,则导航会被终止且该错误会被传递给 router.onError() 注册过的回调。
89
+ */
90
+ next: Function) => void)
91
+ /** 移除上一个添加的监听 */
92
+ | (() => void)) => void;
93
+ afterEach: (callback: ((
94
+ /** 即将要进入的目标 路由对象 */
95
+ to: Vue2Object["$route"],
96
+ /** 当前导航正要离开的路由 */
97
+ from: Vue2Object["$route"]) => void)
98
+ /** 移除上一个添加的监听 */
99
+ | (() => void)) => void;
100
+ };
101
+ $ssrContext: any;
102
+ $watch: (key: string | string[] | (() => any), handler: (this: any, newVal: any, oldVal: any) => void, options?: {
103
+ immediate?: boolean;
104
+ deep?: boolean;
105
+ }) => void;
106
+ [key: string]: any;
107
+ }
108
+ export declare interface HTMLVue2DivElement extends HTMLDivElement {
109
+ __vue__: Vue2Object;
110
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "2.2.8",
3
+ "version": "2.3.0",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -44,6 +44,7 @@
44
44
  "typescript": "^5.5.4"
45
45
  },
46
46
  "scripts": {
47
+ "dev": "rollup --config --watch",
47
48
  "build": "rollup --config",
48
49
  "build:all": "rollup --config"
49
50
  }
package/src/Httpx.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnyObject, Utils } from "./Utils";
1
+ import { Utils } from "./Utils";
2
2
  import { GenerateUUID } from "./UtilsCommon";
3
3
 
4
4
  /**
@@ -98,7 +98,7 @@ export type HttpxResponseCallBackType =
98
98
  export type HttpxResponseMap = {
99
99
  arraybuffer: ArrayBuffer;
100
100
  blob: Blob;
101
- json: AnyObject;
101
+ json: any;
102
102
  stream: ReadableStream<string>;
103
103
  document: Document;
104
104
  undefined: string;
@@ -1062,7 +1062,7 @@ export declare interface HttpxDetails {
1062
1062
  /**
1063
1063
  * 将该对象添加到响应的属性中,可为空
1064
1064
  */
1065
- context?: AnyObject;
1065
+ context?: any;
1066
1066
  /**
1067
1067
  * 重写mimeType,可为空
1068
1068
  */
package/src/Log.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { AnyObject } from "./Utils";
2
1
 
3
2
  /** Utils.Log的初始化配置 */
4
3
  declare interface UtilsLogOptions {
@@ -245,7 +244,7 @@ class Log {
245
244
  * @example
246
245
  * log.table([{"名字":"example","值":"123"},{"名字":"example2","值":"345"}])
247
246
  */
248
- table(msg: AnyObject[], color = this.#details.infoColor, otherStyle = "") {
247
+ table(msg: any[], color = this.#details.infoColor, otherStyle = "") {
249
248
  if (this.#disable) return;
250
249
  this.checkClearConsole();
251
250
  let stack = new Error()!.stack!.split("\n");
package/src/Utils.ts CHANGED
@@ -16,6 +16,7 @@ import type { Vue2Object } from "./VueObject";
16
16
  import type { UtilsAjaxHookResult } from "./AjaxHookerType";
17
17
  import { GenerateUUID } from "./UtilsCommon";
18
18
  import { WindowApi, type UtilsWindowApiOption } from "./WindowApi";
19
+ import { Vue } from "./Vue";
19
20
 
20
21
  export declare var unsafeWindow: Window & typeof globalThis;
21
22
 
@@ -1515,12 +1516,12 @@ class Utils {
1515
1516
  * Utils.getReactObj(document.querySelector("input"))?.reactProps?.onChange({target:{value:"123"}});
1516
1517
  */
1517
1518
  getReactObj(element: HTMLElement | Element): {
1518
- reactFiber?: AnyObject;
1519
- reactProps?: AnyObject;
1520
- reactEvents?: AnyObject;
1521
- reactEventHandlers?: AnyObject;
1522
- reactInternalInstance?: AnyObject;
1523
- reactContainer?: AnyObject;
1519
+ reactFiber?: any;
1520
+ reactProps?: any;
1521
+ reactEvents?: any;
1522
+ reactEventHandlers?: any;
1523
+ reactInternalInstance?: any;
1524
+ reactContainer?: any;
1524
1525
  } {
1525
1526
  let result = {};
1526
1527
  Object.keys(element).forEach((domPropsName) => {
@@ -2106,7 +2107,7 @@ class Utils {
2106
2107
  * Utils.isNotNull("123");
2107
2108
  * > true
2108
2109
  */
2109
- isNotNull<T>(value: T | null): value is T;
2110
+ isNotNull<T>(value: T | null | undefined): value is T;
2110
2111
  isNotNull(...args: any[]): boolean;
2111
2112
  isNotNull(...args: any[]): boolean {
2112
2113
  let UtilsContext = this;
@@ -2157,7 +2158,7 @@ class Utils {
2157
2158
  Utils.isNull(false,[123]);
2158
2159
  > false
2159
2160
  **/
2160
- isNull<T>(value: T | null): value is null;
2161
+ isNull<T>(value: T | undefined | null): value is null | undefined;
2161
2162
  isNull(...args: any[]): boolean;
2162
2163
  isNull(...args: any[]): boolean {
2163
2164
  let result = true;
@@ -2343,8 +2344,8 @@ class Utils {
2343
2344
  * Utils.parseObjectToArray({"工具类":"jsonToArray","return","Array"});
2344
2345
  * > ['jsonToArray', 'Array']
2345
2346
  **/
2346
- parseObjectToArray(target: AnyObject): any;
2347
- parseObjectToArray(target: AnyObject): any {
2347
+ parseObjectToArray(target: any): any;
2348
+ parseObjectToArray(target: any): any {
2348
2349
  if (typeof target !== "object") {
2349
2350
  throw new Error(
2350
2351
  "Utils.parseObjectToArray 参数 target 必须为 object 类型"
@@ -3322,7 +3323,6 @@ class Utils {
3322
3323
  }
3323
3324
  /**
3324
3325
  * 申请剪贴板权限
3325
- * @returns {Promise<boolean>}
3326
3326
  */
3327
3327
  requestClipboardPermission() {
3328
3328
  return new Promise((resolve, reject) => {
@@ -3335,16 +3335,13 @@ class Utils {
3335
3335
  .then((permissionStatus) => {
3336
3336
  resolve(true);
3337
3337
  })
3338
- .catch(
3339
- /** @param {TypeError} error */
3340
- (error) => {
3341
- console.error([
3342
- "申请剪贴板权限失败,尝试直接写入👉",
3343
- error.message ?? error.name ?? error.stack,
3344
- ]);
3345
- resolve(false);
3346
- }
3347
- );
3338
+ .catch((error: TypeError) => {
3339
+ console.error([
3340
+ "申请剪贴板权限失败,尝试直接写入👉",
3341
+ error.message ?? error.name ?? error.stack,
3342
+ ]);
3343
+ resolve(false);
3344
+ });
3348
3345
  } else {
3349
3346
  resolve(false);
3350
3347
  }
@@ -3911,7 +3908,9 @@ class Utils {
3911
3908
  /**
3912
3909
  * 将UrlSearchParams格式的字符串转为对象
3913
3910
  */
3914
- searchParamStrToObj<T extends any>(searhParamsStr?: string | null | undefined): T {
3911
+ searchParamStrToObj<T extends any>(
3912
+ searhParamsStr?: string | null | undefined
3913
+ ): T {
3915
3914
  if (typeof searhParamsStr !== "string") {
3916
3915
  // @ts-ignore
3917
3916
  return {};
@@ -4663,11 +4662,11 @@ class Utils {
4663
4662
  *
4664
4663
  */
4665
4664
  waitProperty<T extends any>(
4666
- checkObj: AnyObject | (() => AnyObject),
4665
+ checkObj: any | (() => any),
4667
4666
  checkPropertyName: string
4668
4667
  ): Promise<T>;
4669
4668
  waitProperty<T extends any>(
4670
- checkObj: AnyObject | (() => AnyObject),
4669
+ checkObj: any | (() => any),
4671
4670
  checkPropertyName: string
4672
4671
  ): Promise<T> {
4673
4672
  return new Promise((resolve) => {
@@ -4701,13 +4700,13 @@ class Utils {
4701
4700
  * console.log("test success set");
4702
4701
  */
4703
4702
  waitPropertyByInterval<T extends any>(
4704
- checkObj: AnyObject | (() => AnyObject),
4703
+ checkObj: any | (() => any),
4705
4704
  checkPropertyName: string | ((obj: any) => boolean),
4706
4705
  intervalTimer?: number,
4707
4706
  maxTime?: number
4708
4707
  ): Promise<T>;
4709
4708
  waitPropertyByInterval<T extends any>(
4710
- checkObj: AnyObject | (() => AnyObject),
4709
+ checkObj: any | (() => any),
4711
4710
  checkPropertyName: string | ((obj: any) => boolean),
4712
4711
  intervalTimer: number = 250,
4713
4712
  maxTime: number = -1
@@ -4837,13 +4836,13 @@ class Utils {
4837
4836
  * > 111;
4838
4837
  */
4839
4838
  watchObject(
4840
- target: AnyObject,
4839
+ target: any,
4841
4840
  propertyName: string,
4842
4841
  getCallBack: (value: any) => void,
4843
4842
  setCallBack: (value: any) => void
4844
4843
  ): void;
4845
4844
  watchObject(
4846
- target: AnyObject,
4845
+ target: any,
4847
4846
  propertyName: string,
4848
4847
  getCallBack: (value: any) => void,
4849
4848
  setCallBack: (value: any) => void
@@ -4968,6 +4967,10 @@ class Utils {
4968
4967
  * Utils.generateUUID()
4969
4968
  */
4970
4969
  generateUUID = GenerateUUID;
4970
+ /**
4971
+ * 自定义的动态响应对象
4972
+ */
4973
+ Vue = Vue;
4971
4974
  }
4972
4975
 
4973
4976
  let utils = new Utils();