@whitesev/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.
Files changed (55) hide show
  1. package/README.md +172 -0
  2. package/dist/index.cjs.js +6017 -0
  3. package/dist/index.cjs.js.map +1 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.esm.js +6015 -0
  6. package/dist/index.esm.js.map +1 -0
  7. package/dist/index.umd.js +6023 -0
  8. package/dist/index.umd.js.map +1 -0
  9. package/dist/src/ColorConversion.d.ts +45 -0
  10. package/dist/src/Dictionary.d.ts +87 -0
  11. package/dist/src/GBKEncoder.d.ts +17 -0
  12. package/dist/src/Hooks.d.ts +5 -0
  13. package/dist/src/Httpx.d.ts +50 -0
  14. package/dist/src/LockFunction.d.ts +16 -0
  15. package/dist/src/Log.d.ts +66 -0
  16. package/dist/src/Progress.d.ts +6 -0
  17. package/dist/src/Utils.d.ts +1560 -0
  18. package/dist/src/UtilsCore.d.ts +9 -0
  19. package/dist/src/UtilsGMCookie.d.ts +36 -0
  20. package/dist/src/UtilsGMMenu.d.ts +119 -0
  21. package/dist/src/ajaxHooker.d.ts +6 -0
  22. package/dist/src/indexedDB.d.ts +165 -0
  23. package/dist/src/tryCatch.d.ts +31 -0
  24. package/index.ts +3 -0
  25. package/package.json +34 -0
  26. package/rollup.config.js +28 -0
  27. package/src/ColorConversion.ts +124 -0
  28. package/src/Dictionary.ts +158 -0
  29. package/src/GBKEncoder.js +111 -0
  30. package/src/GBKEncoder.ts +116 -0
  31. package/src/Hooks.js +73 -0
  32. package/src/Httpx.js +747 -0
  33. package/src/LockFunction.js +35 -0
  34. package/src/Log.js +256 -0
  35. package/src/Progress.js +98 -0
  36. package/src/Utils.ts +4495 -0
  37. package/src/UtilsCore.ts +39 -0
  38. package/src/UtilsGMCookie.ts +167 -0
  39. package/src/UtilsGMMenu.js +464 -0
  40. package/src/ajaxHooker.js +560 -0
  41. package/src/indexedDB.js +355 -0
  42. package/src/tryCatch.js +100 -0
  43. package/src/types/AjaxHooker.d.ts +153 -0
  44. package/src/types/DOMUtils.d.ts +188 -0
  45. package/src/types/Hook.d.ts +16 -0
  46. package/src/types/Httpx.d.ts +1308 -0
  47. package/src/types/Indexdb.d.ts +128 -0
  48. package/src/types/LockFunction.d.ts +47 -0
  49. package/src/types/Log.d.ts +91 -0
  50. package/src/types/Progress.d.ts +30 -0
  51. package/src/types/TryCatch.d.ts +6 -0
  52. package/src/types/UtilsCore.d.ts +7 -0
  53. package/src/types/UtilsGMMenu.d.ts +224 -0
  54. package/src/types/global.d.ts +58 -0
  55. package/tsconfig.json +32 -0
@@ -0,0 +1,45 @@
1
+ declare class ColorConversion {
2
+ constructor();
3
+ /**
4
+ * 判断是否是16进制颜色
5
+ * @param str
6
+ */
7
+ isHex(str: string): boolean;
8
+ /**
9
+ * 16进制颜色转rgba
10
+ *
11
+ * #ff0000 转 rgba(123,123,123, 0.4)
12
+ * @param hex
13
+ * @param opacity
14
+ */
15
+ hexToRgba(hex: string, opacity: number): string;
16
+ /**
17
+ * hex转rgb
18
+ * @param str
19
+ * @returns
20
+ */
21
+ hexToRgb(str: string): RegExpMatchArray;
22
+ /**
23
+ * rgb转hex
24
+ * @param redValue
25
+ * @param greenValue
26
+ * @param blueValue
27
+ * @returns
28
+ */
29
+ rgbToHex(redValue: string | number, greenValue: string | number, blueValue: string | number): string;
30
+ /**
31
+ * 获取颜色变暗或亮
32
+ * @param color 颜色
33
+ * @param level 0~1.0
34
+ * @returns
35
+ */
36
+ getDarkColor(color: string, level: number): string;
37
+ /**
38
+ * 获取颜色变亮
39
+ * @param color 颜色
40
+ * @param level 0~1.0
41
+ * @returns
42
+ */
43
+ getLightColor(color: string, level: number): string;
44
+ }
45
+ export { ColorConversion };
@@ -0,0 +1,87 @@
1
+ declare class UtilsDictionary<K extends any, V extends any> {
2
+ items: {
3
+ [key: string | number | symbol]: V;
4
+ };
5
+ /**
6
+ * 检查是否有某一个键
7
+ * @param key 键
8
+ */
9
+ has(key: K): boolean;
10
+ /**
11
+ * 检查已有的键中是否以xx开头
12
+ * @param key 需要匹配的键
13
+ */
14
+ startsWith(key: string): boolean;
15
+ /**
16
+ * 获取以xx开头的键的值
17
+ * @param key 需要匹配的键
18
+ */
19
+ getStartsWith(key: string): V | undefined;
20
+ /**
21
+ * 为字典添加某一个值
22
+ * @param key 键
23
+ * @param val 值,默认为""
24
+ */
25
+ set(key: K, val: V): void;
26
+ /**
27
+ * 删除某一个键
28
+ * @param key 键
29
+ */
30
+ delete(key: K): boolean;
31
+ /**
32
+ * 获取某个键的值
33
+ * @param key 键
34
+ */
35
+ get(key: K): V;
36
+ /**
37
+ * 返回字典中的所有值
38
+ */
39
+ values(): V[];
40
+ /**
41
+ * 清空字典
42
+ */
43
+ clear(): void;
44
+ /**
45
+ * 获取字典的长度
46
+ */
47
+ size(): number;
48
+ /**
49
+ * 获取字典所有的键
50
+ */
51
+ keys(): string[];
52
+ /**
53
+ * 返回字典本身
54
+ * @returns
55
+ */
56
+ getItems(): {
57
+ [key: string]: V;
58
+ [key: number]: V;
59
+ [key: symbol]: V;
60
+ };
61
+ /**
62
+ * 合并另一个字典
63
+ * @param data 需要合并的字典
64
+ */
65
+ concat(data: UtilsDictionary<K, V>): void;
66
+ /**
67
+ * 循环字典
68
+ */
69
+ forEach(callbackfn: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => void): void;
70
+ /**
71
+ * 获取字典的长度,同this.size
72
+ */
73
+ get length(): number;
74
+ /**
75
+ * 迭代器
76
+ */
77
+ get entries(): () => Generator<(string | V)[], void, unknown>;
78
+ /**
79
+ * 是否可遍历
80
+ */
81
+ get [Symbol.iterator](): () => Generator<(string | V)[], void, unknown>;
82
+ /**
83
+ * .toString()和.toLocaleString()输出的字符串
84
+ */
85
+ get [Symbol.toStringTag](): string;
86
+ }
87
+ export { UtilsDictionary };
@@ -0,0 +1,17 @@
1
+ declare class GBKEncoder {
2
+ #private;
3
+ constructor();
4
+ private handleText;
5
+ private isAscii;
6
+ /**
7
+ * 编码
8
+ * @param str
9
+ */
10
+ encode(str: string): string;
11
+ /**
12
+ * 解码
13
+ * @param {string} str
14
+ */
15
+ decode(str: string): string;
16
+ }
17
+ export { GBKEncoder };
@@ -0,0 +1,5 @@
1
+ export function Hooks(): void;
2
+ export class Hooks {
3
+ initEnv: () => void;
4
+ cleanEnv: () => boolean;
5
+ }
@@ -0,0 +1,50 @@
1
+ export function Httpx(__xmlHttpRequest__: any): void;
2
+ export class Httpx {
3
+ constructor(__xmlHttpRequest__: any);
4
+ /**
5
+ * 覆盖当前配置
6
+ * @param {HttpxDetailsConfig} details
7
+ */
8
+ config: (details?: HttpxDetailsConfig) => void;
9
+ /**
10
+ * 修改xmlHttpRequest
11
+ * @param {Function} httpRequest 网络请求函数
12
+ */
13
+ setXMLHttpRequest: (httpRequest: Function) => void;
14
+ /**
15
+ * GET 请求
16
+ * @param {...HttpxDetails|string} args
17
+ * @returns {Promise< HttpxAsyncResult >}
18
+ */
19
+ get: (...args: (HttpxDetails | string)[]) => Promise<HttpxAsyncResult<any>>;
20
+ /**
21
+ * POST 请求
22
+ * @param {...HttpxDetails|string} args
23
+ * @returns {Promise< HttpxAsyncResult >}
24
+ */
25
+ post: (...args: (HttpxDetails | string)[]) => Promise<HttpxAsyncResult<any>>;
26
+ /**
27
+ * HEAD 请求
28
+ * @param {...HttpxDetails|string} args
29
+ * @returns {Promise< HttpxAsyncResult >}
30
+ */
31
+ head: (...args: (HttpxDetails | string)[]) => Promise<HttpxAsyncResult<any>>;
32
+ /**
33
+ * OPTIONS 请求
34
+ * @param {...HttpxDetails|string} args
35
+ * @returns {Promise< HttpxAsyncResult >}
36
+ */
37
+ options: (...args: (HttpxDetails | string)[]) => Promise<HttpxAsyncResult<any>>;
38
+ /**
39
+ * DELETE 请求
40
+ * @param {...HttpxDetails|string} args
41
+ * @returns {Promise< HttpxAsyncResult >}
42
+ */
43
+ delete: (...args: (HttpxDetails | string)[]) => Promise<HttpxAsyncResult<any>>;
44
+ /**
45
+ * PUT 请求
46
+ * @param {...HttpxDetails|string} args
47
+ * @returns {Promise< HttpxAsyncResult >}
48
+ */
49
+ put: (...args: (HttpxDetails | string)[]) => Promise<HttpxAsyncResult<any>>;
50
+ }
@@ -0,0 +1,16 @@
1
+ export function LockFunction(callback: any, context: any, delayTime?: number): void;
2
+ export class LockFunction {
3
+ constructor(callback: any, context: any, delayTime?: number);
4
+ /**
5
+ * 锁
6
+ */
7
+ lock: () => void;
8
+ /**
9
+ * 解锁
10
+ */
11
+ unlock: () => void;
12
+ /**
13
+ * 执行
14
+ */
15
+ run: (...args: any[]) => Promise<void>;
16
+ }
@@ -0,0 +1,66 @@
1
+ export function Log(_GM_info_?: {
2
+ script: {
3
+ name: string;
4
+ };
5
+ }, console?: Console): void;
6
+ export class Log {
7
+ constructor(_GM_info_?: {
8
+ script: {
9
+ name: string;
10
+ };
11
+ }, console?: Console);
12
+ /**
13
+ * 前面的TAG标志
14
+ */
15
+ tag: string;
16
+ /**
17
+ * 控制台-普通输出
18
+ * @param {any} msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
19
+ * @param {string|undefined} color 输出的颜色
20
+ * @param {string|undefined} otherStyle 其它CSS
21
+ */
22
+ info: (msg: any, color: string | undefined, otherStyle: string | undefined) => void;
23
+ /**
24
+ * 控制台-警告输出
25
+ * @param {any} msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
26
+ * @param {string|undefined} color 输出的颜色
27
+ * @param {string|undefined} otherStyle 其它CSS
28
+ */
29
+ warn: (msg: any, color?: string | undefined, otherStyle?: string | undefined) => void;
30
+ /**
31
+ * 控制台-错误输出
32
+ * @param {any} msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
33
+ * @param {string|undefined} color 输出的颜色
34
+ * @param {string|undefined} otherStyle 其它CSS
35
+ */
36
+ error: (msg: any, color: string | undefined, otherStyle: string | undefined) => void;
37
+ /**
38
+ * 控制台-成功输出
39
+ * @param {any} msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
40
+ * @param {string|undefined} color 输出的颜色
41
+ * @param {string|undefined} otherStyle 其它CSS
42
+ */
43
+ success: (msg: any, color: string | undefined, otherStyle: string | undefined) => void;
44
+ /**
45
+ * 控制台-输出表格
46
+ * @param {object[]} msg
47
+ * @param {string|undefined} color 输出的颜色
48
+ * @param {string|undefined} otherStyle 其它CSS
49
+ * @example
50
+ * log.table([{"名字":"example","值":"123"},{"名字":"example2","值":"345"}])
51
+ */
52
+ table: (msg: object[], color?: string | undefined, otherStyle?: string | undefined) => void;
53
+ /**
54
+ * 配置Log对象的颜色
55
+ * @param {UtilsLogOptions} paramDetails 配置信息
56
+ */
57
+ config: (paramDetails: UtilsLogOptions) => void;
58
+ /**
59
+ * 禁用输出
60
+ */
61
+ disable: () => void;
62
+ /**
63
+ * 恢复输出
64
+ */
65
+ recovery: () => void;
66
+ }
@@ -0,0 +1,6 @@
1
+ export function Progress(paramConfig: any): void;
2
+ export class Progress {
3
+ constructor(paramConfig: any);
4
+ config: any;
5
+ draw: () => void;
6
+ }