@gx-design-vue/pro-utils 0.1.4 → 0.2.0-alpha.1

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 (171) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -2
  3. package/dist/array/index.d.ts +5 -0
  4. package/dist/array/index.js +6 -0
  5. package/dist/array/slice.d.ts +11 -0
  6. package/dist/array/slice.js +29 -0
  7. package/dist/array/sort.d.ts +41 -0
  8. package/dist/array/sort.js +65 -0
  9. package/dist/array/tree.d.ts +83 -0
  10. package/dist/array/tree.js +157 -0
  11. package/dist/array/unique.d.ts +12 -0
  12. package/dist/array/unique.js +14 -0
  13. package/dist/base64/index.d.ts +26 -0
  14. package/dist/base64/index.js +106 -0
  15. package/dist/class/index.d.ts +2 -0
  16. package/dist/class/index.js +3 -0
  17. package/dist/class/prefix.d.ts +25 -0
  18. package/dist/class/prefix.js +15 -0
  19. package/dist/clone/cloneDeep.d.ts +30 -0
  20. package/dist/clone/cloneDeep.js +35 -0
  21. package/dist/clone/cloneDeepWith.d.ts +14 -0
  22. package/dist/clone/cloneDeepWith.js +150 -0
  23. package/dist/clone/getTag.d.ts +10 -0
  24. package/dist/clone/getTag.js +13 -0
  25. package/dist/clone/index.d.ts +3 -0
  26. package/dist/clone/index.js +4 -0
  27. package/dist/clone/symbols.d.ts +10 -0
  28. package/dist/clone/symbols.js +13 -0
  29. package/dist/clone/tags.d.ts +47 -0
  30. package/dist/clone/tags.js +48 -0
  31. package/dist/dom/event.d.ts +21 -0
  32. package/dist/dom/event.js +26 -0
  33. package/dist/dom/index.d.ts +5 -0
  34. package/dist/dom/index.js +6 -0
  35. package/dist/dom/measure.d.ts +19 -0
  36. package/dist/dom/measure.js +42 -0
  37. package/dist/dom/raf.d.ts +14 -0
  38. package/dist/dom/raf.js +44 -0
  39. package/dist/dom/scroll.d.ts +20 -0
  40. package/dist/dom/scroll.js +97 -0
  41. package/dist/file/config.d.ts +13 -0
  42. package/dist/file/config.js +81 -0
  43. package/dist/file/convert.d.ts +41 -0
  44. package/dist/file/convert.js +69 -0
  45. package/dist/file/index.d.ts +5 -0
  46. package/dist/file/index.js +6 -0
  47. package/dist/file/media.d.ts +35 -0
  48. package/dist/file/media.js +161 -0
  49. package/dist/file/type.d.ts +25 -0
  50. package/dist/file/type.js +58 -0
  51. package/dist/function/copy.d.ts +12 -0
  52. package/dist/function/copy.js +13 -0
  53. package/dist/function/getValue.d.ts +12 -0
  54. package/dist/function/getValue.js +19 -0
  55. package/dist/function/index.d.ts +5 -0
  56. package/dist/function/index.js +6 -0
  57. package/dist/function/object.d.ts +24 -0
  58. package/dist/function/object.js +33 -0
  59. package/dist/function/run.d.ts +11 -0
  60. package/dist/function/run.js +15 -0
  61. package/dist/index.d.ts +59 -26
  62. package/dist/index.js +61 -0
  63. package/dist/is/base64.d.ts +17 -0
  64. package/dist/is/base64.js +27 -0
  65. package/dist/is/browser.d.ts +9 -0
  66. package/dist/is/browser.js +14 -0
  67. package/dist/is/deepEqual.d.ts +13 -0
  68. package/dist/is/deepEqual.js +62 -0
  69. package/dist/is/device.d.ts +21 -0
  70. package/dist/is/device.js +37 -0
  71. package/dist/is/equal.d.ts +12 -0
  72. package/dist/is/equal.js +34 -0
  73. package/dist/is/img.d.ts +10 -0
  74. package/dist/is/img.js +13 -0
  75. package/dist/is/index.d.ts +16 -0
  76. package/dist/is/index.js +17 -0
  77. package/dist/is/nil.d.ts +17 -0
  78. package/dist/is/nil.js +22 -0
  79. package/dist/is/plainObject.d.ts +17 -0
  80. package/dist/is/plainObject.js +30 -0
  81. package/dist/is/primitive.d.ts +10 -0
  82. package/dist/is/primitive.js +13 -0
  83. package/dist/is/server.d.ts +9 -0
  84. package/dist/is/server.js +10 -0
  85. package/dist/is/type.d.ts +60 -0
  86. package/dist/is/type.js +84 -0
  87. package/dist/is/typedArray.d.ts +30 -0
  88. package/dist/is/typedArray.js +33 -0
  89. package/dist/is/unsafeProperty.d.ts +10 -0
  90. package/dist/is/unsafeProperty.js +18 -0
  91. package/dist/is/url.d.ts +10 -0
  92. package/dist/is/url.js +20 -0
  93. package/dist/is/valid.d.ts +17 -0
  94. package/dist/is/valid.js +23 -0
  95. package/dist/merge/index.d.ts +19 -5
  96. package/dist/merge/index.js +42 -0
  97. package/dist/merge/mergeWith.d.ts +12 -0
  98. package/dist/merge/mergeWith.js +31 -0
  99. package/dist/merge/useDeepMege.d.ts +46 -0
  100. package/dist/merge/useDeepMege.js +56 -0
  101. package/dist/number/chinese.d.ts +10 -0
  102. package/dist/number/chinese.js +46 -0
  103. package/dist/number/format.d.ts +27 -0
  104. package/dist/number/format.js +72 -0
  105. package/dist/number/index.d.ts +3 -0
  106. package/dist/number/index.js +4 -0
  107. package/dist/object/classNames.d.ts +10 -0
  108. package/dist/object/classNames.js +30 -0
  109. package/dist/object/index.d.ts +5 -0
  110. package/dist/object/index.js +6 -0
  111. package/dist/object/omitBoolean.d.ts +10 -0
  112. package/dist/object/omitBoolean.js +13 -0
  113. package/dist/object/omitUndefined.d.ts +12 -0
  114. package/dist/object/omitUndefined.js +18 -0
  115. package/dist/object/omitUndefinedAndEmptyArr.d.ts +10 -0
  116. package/dist/object/omitUndefinedAndEmptyArr.js +19 -0
  117. package/dist/pro-utils.esm.js +948 -0
  118. package/dist/pro-utils.js +1 -0
  119. package/dist/string/duration.d.ts +10 -0
  120. package/dist/string/duration.js +25 -0
  121. package/dist/string/empty.d.ts +14 -0
  122. package/dist/string/empty.js +26 -0
  123. package/dist/string/index.d.ts +5 -0
  124. package/dist/string/index.js +6 -0
  125. package/dist/string/nanoid.d.ts +9 -0
  126. package/dist/string/nanoid.js +32 -0
  127. package/dist/string/uuid.d.ts +34 -0
  128. package/dist/string/uuid.js +57 -0
  129. package/dist/table/column.d.ts +27 -0
  130. package/dist/table/column.js +42 -0
  131. package/dist/table/index.d.ts +3 -0
  132. package/dist/table/index.js +4 -0
  133. package/dist/table/page.d.ts +13 -0
  134. package/dist/table/page.js +23 -0
  135. package/dist/typing.d.ts +262 -0
  136. package/dist/typing.js +1 -0
  137. package/dist/vue/index.d.ts +2 -0
  138. package/dist/vue/index.js +3 -0
  139. package/dist/vue/slots.d.ts +56 -0
  140. package/dist/vue/slots.js +89 -0
  141. package/package.json +45 -64
  142. package/dist/classNames/index.d.ts +0 -2
  143. package/dist/components/FieldLabel/index.d.ts +0 -77
  144. package/dist/components/FieldLabel/index.less +0 -107
  145. package/dist/components/LabelIconTip/index.d.ts +0 -20
  146. package/dist/components/LabelIconTip/index.less +0 -38
  147. package/dist/design/ant-design-theme.less +0 -4
  148. package/dist/design/ant-design-vue.less +0 -1
  149. package/dist/design/config.less +0 -2
  150. package/dist/isBrowser/index.d.ts +0 -1
  151. package/dist/isDeepEqualReact/index.d.ts +0 -1
  152. package/dist/isServer.d.ts +0 -2
  153. package/dist/omitBoolean/index.d.ts +0 -6
  154. package/dist/omitUndefined/index.d.ts +0 -5
  155. package/dist/pro-utils.es.js +0 -1044
  156. package/dist/pro-utils.umd.js +0 -1
  157. package/dist/proUtils.less +0 -4
  158. package/dist/scroll/easings.d.ts +0 -1
  159. package/dist/scroll/getScroll.d.ts +0 -2
  160. package/dist/scroll/index.d.ts +0 -4
  161. package/dist/scroll/raf.d.ts +0 -9
  162. package/dist/scroll/scrollTo.d.ts +0 -10
  163. package/dist/scroll/throttleByAnimationFrame.d.ts +0 -5
  164. package/dist/slots/index.d.ts +0 -9
  165. package/dist/style/index.less +0 -2
  166. package/dist/style.css +0 -1
  167. package/dist/style.less +0 -3
  168. package/dist/typings/index.d.ts +0 -30
  169. package/dist/utils/config.d.ts +0 -8
  170. package/dist/utils/index.d.ts +0 -208
  171. package/dist/utils/validate.d.ts +0 -25
@@ -0,0 +1,10 @@
1
+ //#region src/is/primitive.d.ts
2
+ /**
3
+ * 判断是否为原始类型
4
+ *
5
+ * @param value - 要判断的值
6
+ * @returns 是否为原始类型
7
+ */
8
+ declare function isPrimitive(value: unknown): value is string | number | boolean | null | undefined | symbol | bigint;
9
+ //#endregion
10
+ export { isPrimitive };
@@ -0,0 +1,13 @@
1
+ //#region src/is/primitive.ts
2
+ /**
3
+ * 判断是否为原始类型
4
+ *
5
+ * @param value - 要判断的值
6
+ * @returns 是否为原始类型
7
+ */
8
+ function isPrimitive(value) {
9
+ return value === null || typeof value !== "object" && typeof value !== "function";
10
+ }
11
+
12
+ //#endregion
13
+ export { isPrimitive };
@@ -0,0 +1,9 @@
1
+ //#region src/is/server.d.ts
2
+ /**
3
+ * 检查是否为服务端环境
4
+ *
5
+ * @returns 是否为服务端
6
+ */
7
+ declare const isServer: boolean;
8
+ //#endregion
9
+ export { isServer };
@@ -0,0 +1,10 @@
1
+ //#region src/is/server.ts
2
+ /**
3
+ * 检查是否为服务端环境
4
+ *
5
+ * @returns 是否为服务端
6
+ */
7
+ const isServer = typeof window === "undefined";
8
+
9
+ //#endregion
10
+ export { isServer };
@@ -0,0 +1,60 @@
1
+ //#region src/is/type.d.ts
2
+ /**
3
+ * 基础类型判断
4
+ *
5
+ * @param val - 要判断的值
6
+ * @param type - 类型名称
7
+ * @returns 是否为该类型
8
+ */
9
+ declare function is(val: unknown, type: string): boolean;
10
+ /**
11
+ * 判断是否为布尔值
12
+ *
13
+ * @param val - 要判断的值
14
+ * @returns 是否为布尔值
15
+ */
16
+ declare function isBoolean(val: unknown): val is boolean;
17
+ /**
18
+ * 判断是否为数字
19
+ *
20
+ * @param val - 要判断的值
21
+ * @returns 是否为数字
22
+ */
23
+ declare function isNumber(val: unknown): val is number;
24
+ /**
25
+ * 判断是否为数组
26
+ *
27
+ * @param val - 要判断的值
28
+ * @returns 是否为数组
29
+ */
30
+ declare function isArray(val: any): val is Array<any>;
31
+ /**
32
+ * 判断是否为对象
33
+ *
34
+ * @param val - 要判断的值
35
+ * @returns 是否为对象
36
+ */
37
+ declare function isObject(val: any): val is Record<any, any>;
38
+ /**
39
+ * 判断是否为字符串
40
+ *
41
+ * @param value - 要判断的值
42
+ * @returns 是否为字符串
43
+ */
44
+ declare function isString(value: unknown): value is string;
45
+ /**
46
+ * 判断是否为函数
47
+ *
48
+ * @param func - 要判断的值
49
+ * @returns 是否为函数
50
+ */
51
+ declare function isFunction(func: unknown): func is (...args: any[]) => any;
52
+ /**
53
+ * 判断是否为 JSON 字符串
54
+ *
55
+ * @param str - 要判断的字符串
56
+ * @returns 是否为 JSON 字符串
57
+ */
58
+ declare function isJSONStr(str: any): boolean;
59
+ //#endregion
60
+ export { is, isArray, isBoolean, isFunction, isJSONStr, isNumber, isObject, isString };
@@ -0,0 +1,84 @@
1
+ //#region src/is/type.ts
2
+ /**
3
+ * 基础类型判断
4
+ *
5
+ * @param val - 要判断的值
6
+ * @param type - 类型名称
7
+ * @returns 是否为该类型
8
+ */
9
+ function is(val, type) {
10
+ return Object.prototype.toString.call(val) === `[object ${type}]`;
11
+ }
12
+ /**
13
+ * 判断是否为布尔值
14
+ *
15
+ * @param val - 要判断的值
16
+ * @returns 是否为布尔值
17
+ */
18
+ function isBoolean(val) {
19
+ return typeof val === "boolean";
20
+ }
21
+ /**
22
+ * 判断是否为数字
23
+ *
24
+ * @param val - 要判断的值
25
+ * @returns 是否为数字
26
+ */
27
+ function isNumber(val) {
28
+ return typeof val === "number";
29
+ }
30
+ /**
31
+ * 判断是否为数组
32
+ *
33
+ * @param val - 要判断的值
34
+ * @returns 是否为数组
35
+ */
36
+ function isArray(val) {
37
+ if (typeof Array.isArray === "undefined") return Object.prototype.toString.call(val) === "[object Array]";
38
+ return Array.isArray(val);
39
+ }
40
+ /**
41
+ * 判断是否为对象
42
+ *
43
+ * @param val - 要判断的值
44
+ * @returns 是否为对象
45
+ */
46
+ function isObject(val) {
47
+ return val !== null && is(val, "Object");
48
+ }
49
+ /**
50
+ * 判断是否为字符串
51
+ *
52
+ * @param value - 要判断的值
53
+ * @returns 是否为字符串
54
+ */
55
+ function isString(value) {
56
+ return typeof value === "string";
57
+ }
58
+ /**
59
+ * 判断是否为函数
60
+ *
61
+ * @param func - 要判断的值
62
+ * @returns 是否为函数
63
+ */
64
+ function isFunction(func) {
65
+ return typeof func === "function" || Object.prototype.toString.call(func) === "[object Function]";
66
+ }
67
+ /**
68
+ * 判断是否为 JSON 字符串
69
+ *
70
+ * @param str - 要判断的字符串
71
+ * @returns 是否为 JSON 字符串
72
+ */
73
+ function isJSONStr(str) {
74
+ if (typeof str !== "string") return false;
75
+ try {
76
+ const obj = JSON.parse(str);
77
+ return typeof obj === "object" && obj !== null;
78
+ } catch {
79
+ return false;
80
+ }
81
+ }
82
+
83
+ //#endregion
84
+ export { is, isArray, isBoolean, isFunction, isJSONStr, isNumber, isObject, isString };
@@ -0,0 +1,30 @@
1
+ //#region src/is/typedArray.d.ts
2
+ /**
3
+ * Checks if a value is a TypedArray.
4
+ * @param {unknown} x The value to check.
5
+ * @returns {x is
6
+ * Uint8Array
7
+ * | Uint8ClampedArray
8
+ * | Uint16Array
9
+ * | Uint32Array
10
+ * | BigUint64Array
11
+ * | Int8Array
12
+ * | Int16Array
13
+ * | Int32Array
14
+ * | BigInt64Array
15
+ * | Float32Array
16
+ * | Float64Array} Returns true if `x` is a TypedArray, false otherwise.
17
+ *
18
+ * @example
19
+ * const arr = new Uint8Array([1, 2, 3]);
20
+ * isTypedArray(arr); // true
21
+ *
22
+ * const regularArray = [1, 2, 3];
23
+ * isTypedArray(regularArray); // false
24
+ *
25
+ * const buffer = new ArrayBuffer(16);
26
+ * isTypedArray(buffer); // false
27
+ */
28
+ declare function isTypedArray(x: unknown): x is Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | BigUint64Array | Int8Array | Int16Array | Int32Array | BigInt64Array | Float32Array | Float64Array;
29
+ //#endregion
30
+ export { isTypedArray };
@@ -0,0 +1,33 @@
1
+ //#region src/is/typedArray.ts
2
+ /**
3
+ * Checks if a value is a TypedArray.
4
+ * @param {unknown} x The value to check.
5
+ * @returns {x is
6
+ * Uint8Array
7
+ * | Uint8ClampedArray
8
+ * | Uint16Array
9
+ * | Uint32Array
10
+ * | BigUint64Array
11
+ * | Int8Array
12
+ * | Int16Array
13
+ * | Int32Array
14
+ * | BigInt64Array
15
+ * | Float32Array
16
+ * | Float64Array} Returns true if `x` is a TypedArray, false otherwise.
17
+ *
18
+ * @example
19
+ * const arr = new Uint8Array([1, 2, 3]);
20
+ * isTypedArray(arr); // true
21
+ *
22
+ * const regularArray = [1, 2, 3];
23
+ * isTypedArray(regularArray); // false
24
+ *
25
+ * const buffer = new ArrayBuffer(16);
26
+ * isTypedArray(buffer); // false
27
+ */
28
+ function isTypedArray(x) {
29
+ return ArrayBuffer.isView(x) && !(x instanceof DataView);
30
+ }
31
+
32
+ //#endregion
33
+ export { isTypedArray };
@@ -0,0 +1,10 @@
1
+ //#region src/is/unsafeProperty.d.ts
2
+ /**
3
+ * 检查属性名是否为不安全的属性名(原型链上的属性或构造函数)
4
+ *
5
+ * @param property - 属性名
6
+ * @returns 是否为不安全的属性名
7
+ */
8
+ declare function isUnsafeProperty(property: string | symbol): boolean;
9
+ //#endregion
10
+ export { isUnsafeProperty };
@@ -0,0 +1,18 @@
1
+ //#region src/is/unsafeProperty.ts
2
+ /**
3
+ * 检查属性名是否为不安全的属性名(原型链上的属性或构造函数)
4
+ *
5
+ * @param property - 属性名
6
+ * @returns 是否为不安全的属性名
7
+ */
8
+ function isUnsafeProperty(property) {
9
+ if (typeof property === "symbol") return false;
10
+ return [
11
+ "__proto__",
12
+ "constructor",
13
+ "prototype"
14
+ ].includes(property);
15
+ }
16
+
17
+ //#endregion
18
+ export { isUnsafeProperty };
@@ -0,0 +1,10 @@
1
+ //#region src/is/url.d.ts
2
+ /**
3
+ * 判断是否为 URL
4
+ *
5
+ * @param path - 路径
6
+ * @returns 是否为 URL
7
+ */
8
+ declare function isUrl(path: string | undefined): boolean;
9
+ //#endregion
10
+ export { isUrl };
package/dist/is/url.js ADDED
@@ -0,0 +1,20 @@
1
+ //#region src/is/url.ts
2
+ /**
3
+ * 判断是否为 URL
4
+ *
5
+ * @param path - 路径
6
+ * @returns 是否为 URL
7
+ */
8
+ function isUrl(path) {
9
+ if (!path) return false;
10
+ if (!path.startsWith("http")) return false;
11
+ try {
12
+ return !!new URL(path);
13
+ } catch (_) {
14
+ console.error("isUrl error", _);
15
+ return false;
16
+ }
17
+ }
18
+
19
+ //#endregion
20
+ export { isUrl };
@@ -0,0 +1,17 @@
1
+ //#region src/is/valid.d.ts
2
+ /**
3
+ * 判断值是否有效(不为 undefined、null 或空字符串)
4
+ *
5
+ * @param value - 要判断的值
6
+ * @returns 是否有效
7
+ */
8
+ declare function isValid(value: any): boolean;
9
+ /**
10
+ * 将值转换为布尔值
11
+ *
12
+ * @param value - 要转换的值
13
+ * @returns 转换后的布尔值
14
+ */
15
+ declare function convertValueBoolean(value: any): boolean;
16
+ //#endregion
17
+ export { convertValueBoolean, isValid };
@@ -0,0 +1,23 @@
1
+ //#region src/is/valid.ts
2
+ /**
3
+ * 判断值是否有效(不为 undefined、null 或空字符串)
4
+ *
5
+ * @param value - 要判断的值
6
+ * @returns 是否有效
7
+ */
8
+ function isValid(value) {
9
+ return value !== void 0 && value !== null && value !== "";
10
+ }
11
+ /**
12
+ * 将值转换为布尔值
13
+ *
14
+ * @param value - 要转换的值
15
+ * @returns 转换后的布尔值
16
+ */
17
+ function convertValueBoolean(value) {
18
+ if (typeof value === "boolean") return value;
19
+ return !!value;
20
+ }
21
+
22
+ //#endregion
23
+ export { convertValueBoolean, isValid };
@@ -1,7 +1,21 @@
1
+ import { useDeepMerge } from "./useDeepMege.js";
2
+ import { mergeWith } from "./mergeWith.js";
3
+
4
+ //#region src/merge/index.d.ts
1
5
  /**
2
- * 用于合并 n 个对象
3
- * @param {any[]} ...rest
4
- * @returns T
6
+ * 合并多个对象
7
+ *
8
+ * @param rest - 要合并的对象
9
+ * @returns 合并后的对象
5
10
  */
6
- declare const merge: <T>(...rest: any[]) => T;
7
- export { merge };
11
+ declare function merge<T = any>(...rest: any[]): T;
12
+ /**
13
+ * 深度合并对象
14
+ *
15
+ * @param target - 目标对象
16
+ * @param source - 源对象(一般是 default 对象)
17
+ * @returns 合并后的对象
18
+ */
19
+ declare function deepMerge<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S): T & S;
20
+ //#endregion
21
+ export { deepMerge, merge, mergeWith, useDeepMerge };
@@ -0,0 +1,42 @@
1
+ import { isPlainObject } from "../is/plainObject.js";
2
+ import "../is/index.js";
3
+ import { cloneDeep } from "../clone/cloneDeep.js";
4
+ import "../clone/index.js";
5
+ import { mergeWith } from "./mergeWith.js";
6
+ import { useDeepMerge } from "./useDeepMege.js";
7
+
8
+ //#region src/merge/index.ts
9
+ /**
10
+ * 合并多个对象
11
+ *
12
+ * @param rest - 要合并的对象
13
+ * @returns 合并后的对象
14
+ */
15
+ function merge(...rest) {
16
+ const obj = {};
17
+ const il = rest.length;
18
+ let key;
19
+ let i = 0;
20
+ for (; i < il; i += 1) for (key in rest[i]) if (Object.prototype.hasOwnProperty.call(rest[i], key)) if (typeof obj[key] === "object" && typeof rest[i][key] === "object" && obj[key] !== void 0 && obj[key] !== null && !Array.isArray(obj[key]) && !Array.isArray(rest[i][key])) obj[key] = {
21
+ ...obj[key],
22
+ ...rest[i][key]
23
+ };
24
+ else obj[key] = rest[i][key];
25
+ return obj;
26
+ }
27
+ /**
28
+ * 深度合并对象
29
+ *
30
+ * @param target - 目标对象
31
+ * @param source - 源对象(一般是 default 对象)
32
+ * @returns 合并后的对象
33
+ */
34
+ function deepMerge(target, source) {
35
+ return mergeWith(cloneDeep(target), source, function mergeRecursively(targetValue, sourceValue) {
36
+ if (isPlainObject(sourceValue)) if (isPlainObject(targetValue)) return mergeWith(cloneDeep(targetValue), sourceValue, mergeRecursively);
37
+ else return mergeWith({}, sourceValue, mergeRecursively);
38
+ });
39
+ }
40
+
41
+ //#endregion
42
+ export { deepMerge, merge, mergeWith, useDeepMerge };
@@ -0,0 +1,12 @@
1
+ //#region src/merge/mergeWith.d.ts
2
+ /**
3
+ * 合并对象(带自定义处理)
4
+ *
5
+ * @param target - 目标对象
6
+ * @param source - 源对象
7
+ * @param merge - 自定义合并函数
8
+ * @returns 合并后的对象
9
+ */
10
+ declare function mergeWith<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S, merge: (targetValue: any, sourceValue: any, key: string, target: T, source: S) => any): T & S;
11
+ //#endregion
12
+ export { mergeWith };
@@ -0,0 +1,31 @@
1
+ import { isPlainObject } from "../is/plainObject.js";
2
+ import { isUnsafeProperty } from "../is/unsafeProperty.js";
3
+ import "../is/index.js";
4
+
5
+ //#region src/merge/mergeWith.ts
6
+ /**
7
+ * 合并对象(带自定义处理)
8
+ *
9
+ * @param target - 目标对象
10
+ * @param source - 源对象
11
+ * @param merge - 自定义合并函数
12
+ * @returns 合并后的对象
13
+ */
14
+ function mergeWith(target, source, merge) {
15
+ const sourceKeys = Object.keys(source);
16
+ for (let i = 0; i < sourceKeys.length; i++) {
17
+ const key = sourceKeys[i];
18
+ if (isUnsafeProperty(key)) continue;
19
+ const sourceValue = source[key];
20
+ const targetValue = target[key];
21
+ const merged = merge(targetValue, sourceValue, key, target, source);
22
+ if (merged !== void 0) target[key] = merged;
23
+ else if (isPlainObject(sourceValue)) if (isPlainObject(targetValue)) target[key] = mergeWith(targetValue, sourceValue, merge);
24
+ else target[key] = mergeWith({}, sourceValue, merge);
25
+ else target[key] = sourceValue;
26
+ }
27
+ return target;
28
+ }
29
+
30
+ //#endregion
31
+ export { mergeWith };
@@ -0,0 +1,46 @@
1
+ //#region src/merge/useDeepMege.d.ts
2
+ /**
3
+ * Merges the properties of the source object into a deep clone of the target object.
4
+ * Unlike `merge`, This function does not modify the original target object.
5
+ *
6
+ * This function performs a deep merge, meaning nested objects and arrays are merged recursively.
7
+ *
8
+ * - If a property in the source object is an array or object and the corresponding property in the target object is also an array or object, they will be merged.
9
+ * - If a property in the source object is undefined, it will not overwrite a defined property in the target object.
10
+ *
11
+ * Note that this function does not mutate the target object.
12
+ *
13
+ * @param {T} target - The target object to be cloned and merged into. This object is not modified directly.
14
+ * @param {S} source - The source object whose properties will be merged into the cloned target object.
15
+ * @returns {T & S} A new object with properties from the source object merged into a deep clone of the target object.
16
+ *
17
+ * @template T - Type of the target object.
18
+ * @template S - Type of the source object.
19
+ *
20
+ * @example
21
+ * const target = { a: 1, b: { x: 1, y: 2 } };
22
+ * const source = { b: { y: 3, z: 4 }, c: 5 };
23
+ *
24
+ * const result = toMerged(target, source);
25
+ * console.log(result);
26
+ * // Output: { a: 1, b: { x: 1, y: 3, z: 4 }, c: 5 }
27
+ *
28
+ * @example
29
+ * const target = { a: [1, 2], b: { x: 1 } };
30
+ * const source = { a: [3], b: { y: 2 } };
31
+ *
32
+ * const result = toMerged(target, source);
33
+ * console.log(result);
34
+ * // Output: { a: [3, 2], b: { x: 1, y: 2 } }
35
+ *
36
+ * @example
37
+ * const target = { a: null };
38
+ * const source = { a: [1, 2, 3] };
39
+ *
40
+ * const result = toMerged(target, source);
41
+ * console.log(result);
42
+ * // Output: { a: [1, 2, 3] }
43
+ */
44
+ declare function useDeepMerge<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S): T & S;
45
+ //#endregion
46
+ export { useDeepMerge };
@@ -0,0 +1,56 @@
1
+ import { isPlainObject } from "../is/plainObject.js";
2
+ import "../is/index.js";
3
+ import { mergeWith } from "./mergeWith.js";
4
+
5
+ //#region src/merge/useDeepMege.ts
6
+ /**
7
+ * Merges the properties of the source object into a deep clone of the target object.
8
+ * Unlike `merge`, This function does not modify the original target object.
9
+ *
10
+ * This function performs a deep merge, meaning nested objects and arrays are merged recursively.
11
+ *
12
+ * - If a property in the source object is an array or object and the corresponding property in the target object is also an array or object, they will be merged.
13
+ * - If a property in the source object is undefined, it will not overwrite a defined property in the target object.
14
+ *
15
+ * Note that this function does not mutate the target object.
16
+ *
17
+ * @param {T} target - The target object to be cloned and merged into. This object is not modified directly.
18
+ * @param {S} source - The source object whose properties will be merged into the cloned target object.
19
+ * @returns {T & S} A new object with properties from the source object merged into a deep clone of the target object.
20
+ *
21
+ * @template T - Type of the target object.
22
+ * @template S - Type of the source object.
23
+ *
24
+ * @example
25
+ * const target = { a: 1, b: { x: 1, y: 2 } };
26
+ * const source = { b: { y: 3, z: 4 }, c: 5 };
27
+ *
28
+ * const result = toMerged(target, source);
29
+ * console.log(result);
30
+ * // Output: { a: 1, b: { x: 1, y: 3, z: 4 }, c: 5 }
31
+ *
32
+ * @example
33
+ * const target = { a: [1, 2], b: { x: 1 } };
34
+ * const source = { a: [3], b: { y: 2 } };
35
+ *
36
+ * const result = toMerged(target, source);
37
+ * console.log(result);
38
+ * // Output: { a: [3, 2], b: { x: 1, y: 2 } }
39
+ *
40
+ * @example
41
+ * const target = { a: null };
42
+ * const source = { a: [1, 2, 3] };
43
+ *
44
+ * const result = toMerged(target, source);
45
+ * console.log(result);
46
+ * // Output: { a: [1, 2, 3] }
47
+ */
48
+ function useDeepMerge(target, source) {
49
+ return mergeWith(target, source, function mergeRecursively(targetValue, sourceValue) {
50
+ if (isPlainObject(sourceValue)) if (isPlainObject(targetValue)) return mergeWith(targetValue, sourceValue, mergeRecursively);
51
+ else return mergeWith({}, sourceValue, mergeRecursively);
52
+ });
53
+ }
54
+
55
+ //#endregion
56
+ export { useDeepMerge };
@@ -0,0 +1,10 @@
1
+ //#region src/number/chinese.d.ts
2
+ /**
3
+ * 数字转中文
4
+ *
5
+ * @param num - 要转换的数字
6
+ * @returns 中文数字
7
+ */
8
+ declare function toChinesNum(num: number): string;
9
+ //#endregion
10
+ export { toChinesNum };
@@ -0,0 +1,46 @@
1
+ import { isNumber } from "../is/type.js";
2
+ import "../is/index.js";
3
+
4
+ //#region src/number/chinese.ts
5
+ /**
6
+ * 数字转中文
7
+ *
8
+ * @param num - 要转换的数字
9
+ * @returns 中文数字
10
+ */
11
+ function toChinesNum(num) {
12
+ num = isNumber(num) && !Number.isNaN(num) ? num : 0;
13
+ const changeNum = [
14
+ "零",
15
+ "一",
16
+ "二",
17
+ "三",
18
+ "四",
19
+ "五",
20
+ "六",
21
+ "七",
22
+ "八",
23
+ "九"
24
+ ];
25
+ const unit = [
26
+ "",
27
+ "十",
28
+ "百",
29
+ "千",
30
+ "万"
31
+ ];
32
+ num = Number.parseInt(`${num}`);
33
+ const getWan = (temp) => {
34
+ const strArr = temp.toString().split("").reverse();
35
+ let newNum = "";
36
+ for (let i = 0; i < strArr.length; i++) newNum = (i === 0 && strArr[i] === "0" ? "" : i > 0 && strArr[i] === "0" && strArr[i - 1] === "0" ? "" : (num < 20 && i > 0 ? "" : changeNum[strArr[i]]) + (strArr[i] === "0" ? unit[0] : unit[i])) + newNum;
37
+ return newNum;
38
+ };
39
+ const overWan = Math.floor(num / 1e4);
40
+ let noWan = num % 1e4;
41
+ if (noWan.toString().length < 4) noWan = `0${noWan}`;
42
+ return overWan ? `${getWan(overWan)}万${getWan(noWan)}` : getWan(num);
43
+ }
44
+
45
+ //#endregion
46
+ export { toChinesNum };
@@ -0,0 +1,27 @@
1
+ //#region src/number/format.d.ts
2
+ /**
3
+ * 格式化数字,保留指定小数位
4
+ *
5
+ * @param fixedNum - 小数位数
6
+ * @param value - 要格式化的值
7
+ * @returns 格式化后的字符串
8
+ */
9
+ declare function formatNumber(fixedNum: number, value: number): string;
10
+ /**
11
+ * 转换数字为带单位的显示格式
12
+ *
13
+ * @param number - 要转换的数字
14
+ * @param options - 配置选项
15
+ * @returns 转换结果
16
+ */
17
+ declare function toConvertNumberShow(number: number, options?: {
18
+ toChinese?: boolean;
19
+ fixed?: number;
20
+ min?: number;
21
+ }): {
22
+ str: string;
23
+ number: string;
24
+ unit?: string;
25
+ };
26
+ //#endregion
27
+ export { formatNumber, toConvertNumberShow };