@yqg/simple 1.0.1 → 1.0.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.
@@ -0,0 +1,91 @@
1
+ /*
2
+ * @Author: YQG Team
3
+ * @Date: 2024-12-19
4
+ * @Description: Type definitions for object utilities
5
+ */
6
+
7
+ /**
8
+ * 评估属性值,如果是函数则执行
9
+ * @param value - 属性值或函数
10
+ * @param values - 传递给函数的参数
11
+ * @returns 评估后的值
12
+ */
13
+ export function evalProp<T = any, V = any>(value: T | ((values: V) => T), values?: V): T;
14
+
15
+ /**
16
+ * 根据键字符串从对象中提取值
17
+ * @param obj - 目标对象
18
+ * @param keyString - 键字符串,支持点号和方括号语法,如 'a.b.c' 或 'a[0].b'
19
+ * @returns 提取的值
20
+ */
21
+ export function pickValue<T = any>(obj: any, keyString: string): T | undefined;
22
+
23
+ /**
24
+ * 根据键字符串设置对象的值
25
+ * @param obj - 目标对象
26
+ * @param keyString - 键字符串,支持点号和方括号语法
27
+ * @param value - 要设置的值
28
+ * @returns 新对象
29
+ */
30
+ export function setValue<T extends Record<string, any>>(obj: T, keyString: string, value: any): T;
31
+
32
+ /**
33
+ * 展开对象的键
34
+ * @param origin - 原始对象
35
+ * @returns 展开后的对象
36
+ */
37
+ export function spreadObjectKeys<T extends Record<string, any>>(origin: T): T;
38
+
39
+ /**
40
+ * 将数字转换为字符串
41
+ * @param val - 数字或布尔值
42
+ * @returns 字符串或原值
43
+ */
44
+ export function numbersToStr<T>(val: T | T[]): T extends number | boolean ? string : T;
45
+
46
+ /**
47
+ * 是否为移动设备
48
+ */
49
+ export const isMobile: boolean;
50
+
51
+ /**
52
+ * 展开 Vue 组件属性
53
+ * @param props - 组件属性对象
54
+ * @returns 展开后的属性对象
55
+ */
56
+ export function spreadProps(props?: {
57
+ class?: any;
58
+ style?: any;
59
+ ref?: any;
60
+ key?: any;
61
+ [key: string]: any;
62
+ }): {
63
+ key?: any;
64
+ class?: any;
65
+ style?: any;
66
+ ref?: any;
67
+ props: Record<string, any>;
68
+ };
69
+
70
+ /**
71
+ * 向类名追加新类名
72
+ * @param className - 原类名
73
+ * @param appendix - 要追加的类名
74
+ * @returns 新类名
75
+ */
76
+ export function appendClass(
77
+ className: string | Record<string, boolean> | string[] | undefined,
78
+ appendix: string
79
+ ): string | Record<string, boolean> | string[];
80
+
81
+ /**
82
+ * 深度合并两个对象
83
+ * @param target - 目标对象
84
+ * @param source - 源对象
85
+ * @returns 合并后的新对象
86
+ */
87
+ export function merge<T extends Record<string, any>, S extends Record<string, any>>(
88
+ target?: T,
89
+ source?: S
90
+ ): T & S;
91
+
@@ -0,0 +1,62 @@
1
+ /*
2
+ * @Author: YQG Team
3
+ * @Date: 2024-12-19
4
+ * @Description: Type definitions for Storage class
5
+ */
6
+
7
+ /**
8
+ * 存储类,封装 localStorage 或 sessionStorage
9
+ */
10
+ export default class Storage {
11
+ /**
12
+ * 存储键名
13
+ */
14
+ key: string;
15
+
16
+ /**
17
+ * 是否使用 sessionStorage
18
+ */
19
+ useSessionStorage: boolean;
20
+
21
+ /**
22
+ * 存储对象
23
+ */
24
+ storage: Storage;
25
+
26
+ /**
27
+ * 创建存储实例
28
+ * @param key - 存储键名
29
+ * @param useSessionStorage - 是否使用 sessionStorage,默认为 false(使用 localStorage)
30
+ */
31
+ constructor(key: string, useSessionStorage?: boolean);
32
+
33
+ /**
34
+ * 设置存储值
35
+ * @param cache - 要存储的数据
36
+ */
37
+ set(cache: any): void;
38
+
39
+ /**
40
+ * 获取存储值
41
+ * @returns 存储的数据或 null
42
+ */
43
+ get<T = any>(): T | null;
44
+
45
+ /**
46
+ * 删除存储项
47
+ */
48
+ remove(): void;
49
+
50
+ /**
51
+ * 监听存储变化
52
+ * @param fn - 回调函数
53
+ */
54
+ on(fn: (event: StorageEvent) => void): void;
55
+
56
+ /**
57
+ * 取消监听
58
+ * @param needsRemove - 是否同时删除存储项
59
+ */
60
+ off(needsRemove?: boolean): void;
61
+ }
62
+
@@ -0,0 +1,15 @@
1
+ /*
2
+ * @Author: YQG Team
3
+ * @Date: 2024-12-19
4
+ * @Description: Type definitions for swim lane storage
5
+ */
6
+
7
+ import Storage from './storage.ts';
8
+
9
+ /**
10
+ * 泳道存储实例
11
+ */
12
+ declare const swimLaneStorage: Storage;
13
+
14
+ export default swimLaneStorage;
15
+
@@ -0,0 +1,13 @@
1
+ /*
2
+ * @Author: YQG Team
3
+ * @Date: 2024-12-19
4
+ * @Description: Type definitions for tool utilities
5
+ */
6
+
7
+ /**
8
+ * 驼峰转换为下划线连接
9
+ * @param camelStr - 驼峰字符串,例如 camelStr
10
+ * @returns 下划线字符串,例如 camel_str
11
+ */
12
+ export function camelCaseToUnderscore(camelStr: string): string;
13
+
package/src/util/tool.js CHANGED
@@ -5,47 +5,6 @@
5
5
  * @Last Modified time: 2022-10-20 18:15:32
6
6
  */
7
7
 
8
- import CryptoJS from 'crypto-js';
9
-
10
- const CALL_SECRET = 'ainiliangwannian';
11
- /**
12
- * AES 解密
13
- * @param ciphertext, key
14
- * @returns utf8字符串
15
- */
16
- export const aesDecrypt = (ciphertext, key = CALL_SECRET) => {
17
- if (ciphertext) {
18
- const encodeKey = CryptoJS.enc.Utf8.parse(key);
19
- const decrypted = CryptoJS.AES.decrypt(ciphertext, encodeKey, {
20
- mode: CryptoJS.mode.ECB,
21
- padding: CryptoJS.pad.Pkcs7
22
- });
23
-
24
- return decrypted.toString(CryptoJS.enc.Utf8);
25
- }
26
-
27
- return ciphertext;
28
- };
29
-
30
- /**
31
- * AES 加密
32
- * @param message, key
33
- * @returns 密码对象Base64字符串
34
- */
35
- export const aesEncrypt = (message, key = CALL_SECRET) => {
36
- if (message) {
37
- const encodeKey = CryptoJS.enc.Utf8.parse(key);
38
- const ciphertext = CryptoJS.AES.encrypt(message, encodeKey, {
39
- mode: CryptoJS.mode.ECB,
40
- padding: CryptoJS.pad.Pkcs7
41
- });
42
-
43
- return ciphertext.toString();
44
- }
45
-
46
- return message;
47
- };
48
-
49
8
  const isString = value => (typeof value === 'string');
50
9
  /* 驼峰转换为下划线链接,例如camelStr => camel_str */
51
10
  export const camelCaseToUnderscore = camelStr => (