@gx-design-vue/pro-utils 0.2.0-beta.86 → 0.2.0-beta.88

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 (175) 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 +4 -0
  6. package/dist/array/slice.js +28 -0
  7. package/dist/array/sort.d.ts +7 -0
  8. package/dist/array/sort.js +65 -0
  9. package/dist/array/tree.d.ts +25 -0
  10. package/dist/array/tree.js +157 -0
  11. package/dist/array/unique.d.ts +6 -0
  12. package/dist/array/unique.js +14 -0
  13. package/dist/base64/index.d.ts +10 -19
  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 +15 -0
  18. package/dist/class/prefix.js +15 -0
  19. package/dist/clone/cloneDeep.d.ts +4 -0
  20. package/dist/clone/cloneDeep.js +35 -0
  21. package/dist/clone/cloneDeepWith.d.ts +6 -0
  22. package/dist/clone/cloneDeepWith.js +150 -0
  23. package/dist/clone/getTag.d.ts +4 -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 +4 -0
  28. package/dist/clone/symbols.js +13 -0
  29. package/dist/clone/tags.d.ts +25 -0
  30. package/dist/clone/tags.js +48 -0
  31. package/dist/dom/event.d.ts +5 -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 +12 -0
  36. package/dist/dom/measure.js +42 -0
  37. package/dist/dom/raf.d.ts +7 -0
  38. package/dist/dom/raf.js +44 -0
  39. package/dist/dom/scroll.d.ts +10 -0
  40. package/dist/dom/scroll.js +74 -0
  41. package/dist/file/config.d.ts +10 -0
  42. package/dist/file/config.js +81 -0
  43. package/dist/file/convert.d.ts +8 -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 +16 -0
  48. package/dist/file/media.js +161 -0
  49. package/dist/file/type.d.ts +6 -0
  50. package/dist/file/type.js +58 -0
  51. package/dist/function/copy.d.ts +6 -0
  52. package/dist/function/copy.js +13 -0
  53. package/dist/function/getValue.d.ts +5 -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 +6 -0
  58. package/dist/function/object.js +33 -0
  59. package/dist/function/run.d.ts +4 -0
  60. package/dist/function/run.js +15 -0
  61. package/dist/index.d.ts +58 -26
  62. package/dist/index.js +60 -0
  63. package/dist/is/base64.d.ts +5 -0
  64. package/dist/is/base64.js +27 -0
  65. package/dist/is/browser.d.ts +4 -0
  66. package/dist/is/browser.js +14 -0
  67. package/dist/is/deepEqual.d.ts +4 -0
  68. package/dist/is/deepEqual.js +62 -0
  69. package/dist/is/device.d.ts +6 -0
  70. package/dist/is/device.js +37 -0
  71. package/dist/is/equal.d.ts +4 -0
  72. package/dist/is/equal.js +34 -0
  73. package/dist/is/img.d.ts +4 -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 +5 -0
  78. package/dist/is/nil.js +22 -0
  79. package/dist/is/plainObject.d.ts +5 -0
  80. package/dist/is/plainObject.js +30 -0
  81. package/dist/is/primitive.d.ts +4 -0
  82. package/dist/is/primitive.js +13 -0
  83. package/dist/is/server.d.ts +4 -0
  84. package/dist/is/server.js +10 -0
  85. package/dist/is/type.d.ts +11 -0
  86. package/dist/is/type.js +84 -0
  87. package/dist/is/typedArray.d.ts +4 -0
  88. package/dist/is/typedArray.js +33 -0
  89. package/dist/is/unsafeProperty.d.ts +4 -0
  90. package/dist/is/unsafeProperty.js +18 -0
  91. package/dist/is/url.d.ts +4 -0
  92. package/dist/is/url.js +20 -0
  93. package/dist/is/valid.d.ts +5 -0
  94. package/dist/is/valid.js +23 -0
  95. package/dist/merge/index.d.ts +6 -49
  96. package/dist/merge/index.js +41 -0
  97. package/dist/merge/mergeWith.d.ts +4 -49
  98. package/dist/merge/mergeWith.js +31 -0
  99. package/dist/number/chinese.d.ts +4 -0
  100. package/dist/number/chinese.js +46 -0
  101. package/dist/number/format.d.ts +13 -0
  102. package/dist/number/format.js +72 -0
  103. package/dist/number/index.d.ts +3 -0
  104. package/dist/number/index.js +4 -0
  105. package/dist/object/classNames.d.ts +4 -0
  106. package/dist/object/classNames.js +30 -0
  107. package/dist/object/index.d.ts +5 -0
  108. package/dist/object/index.js +6 -0
  109. package/dist/object/omitBoolean.d.ts +4 -0
  110. package/dist/object/omitBoolean.js +13 -0
  111. package/dist/object/omitUndefined.d.ts +6 -0
  112. package/dist/object/omitUndefined.js +18 -0
  113. package/dist/object/omitUndefinedAndEmptyArr.d.ts +4 -0
  114. package/dist/object/omitUndefinedAndEmptyArr.js +19 -0
  115. package/dist/pro-utils.js +1 -1166
  116. package/dist/string/duration.d.ts +4 -0
  117. package/dist/string/duration.js +25 -0
  118. package/dist/string/empty.d.ts +7 -0
  119. package/dist/string/empty.js +26 -0
  120. package/dist/string/index.d.ts +5 -0
  121. package/dist/string/index.js +6 -0
  122. package/dist/string/nanoid.d.ts +4 -0
  123. package/dist/string/nanoid.js +32 -0
  124. package/dist/string/uuid.d.ts +9 -0
  125. package/dist/string/uuid.js +57 -0
  126. package/dist/table/column.d.ts +13 -0
  127. package/dist/table/column.js +42 -0
  128. package/dist/table/index.d.ts +3 -0
  129. package/dist/table/index.js +4 -0
  130. package/dist/table/page.d.ts +6 -0
  131. package/dist/table/page.js +23 -0
  132. package/dist/typing.d.ts +37 -0
  133. package/dist/typing.js +1 -0
  134. package/dist/vue/index.d.ts +2 -0
  135. package/dist/vue/index.js +3 -0
  136. package/dist/vue/slots.d.ts +56 -0
  137. package/dist/vue/slots.js +89 -0
  138. package/package.json +48 -23
  139. package/dist/classNames/index.d.ts +0 -2
  140. package/dist/cloneDeep/cloneDeepWith.d.ts +0 -43
  141. package/dist/cloneDeep/index.d.ts +0 -47
  142. package/dist/getValueFromObjectByKey/index.d.ts +0 -3
  143. package/dist/isBrowser/index.d.ts +0 -1
  144. package/dist/isDeepEqualReact/index.d.ts +0 -1
  145. package/dist/isImg/index.d.ts +0 -2
  146. package/dist/isNil/index.d.ts +0 -1
  147. package/dist/isServer.d.ts +0 -2
  148. package/dist/isUrl/index.d.ts +0 -6
  149. package/dist/merge/useDeepMege.d.ts +0 -43
  150. package/dist/nanoid/index.d.ts +0 -6
  151. package/dist/omitBoolean/index.d.ts +0 -6
  152. package/dist/omitUndefined/index.d.ts +0 -2
  153. package/dist/omitUndefinedAndEmptyArr/index.d.ts +0 -1
  154. package/dist/pro-utils.umd.cjs +0 -13
  155. package/dist/scroll/easings.d.ts +0 -1
  156. package/dist/scroll/getScroll.d.ts +0 -2
  157. package/dist/scroll/index.d.ts +0 -4
  158. package/dist/scroll/scrollTo.d.ts +0 -10
  159. package/dist/scroll/throttleByAnimationFrame.d.ts +0 -5
  160. package/dist/slots/index.d.ts +0 -68
  161. package/dist/typings/index.d.ts +0 -40
  162. package/dist/utils/config.d.ts +0 -7
  163. package/dist/utils/getSymbols.d.ts +0 -1
  164. package/dist/utils/getTag.d.ts +0 -8
  165. package/dist/utils/index.d.ts +0 -333
  166. package/dist/utils/isEqual.d.ts +0 -9
  167. package/dist/utils/isNotNil.d.ts +0 -1
  168. package/dist/utils/isPlainObject.d.ts +0 -43
  169. package/dist/utils/isPrimitive.d.ts +0 -29
  170. package/dist/utils/isTypedArray.d.ts +0 -27
  171. package/dist/utils/isUnsafeProperty.d.ts +0 -11
  172. package/dist/utils/isValid.d.ts +0 -2
  173. package/dist/utils/raf.d.ts +0 -5
  174. package/dist/utils/tags.d.ts +0 -26
  175. package/dist/utils/validate.d.ts +0 -28
@@ -0,0 +1,14 @@
1
+ //#region src/is/browser.ts
2
+ const isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
3
+ /**
4
+ * 检查是否为浏览器环境
5
+ *
6
+ * @returns 是否为浏览器
7
+ */
8
+ function isBrowser() {
9
+ if (process.env.NODE_ENV === "TEST") return true;
10
+ return typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.matchMedia !== "undefined" && !isNode;
11
+ }
12
+
13
+ //#endregion
14
+ export { isBrowser };
@@ -0,0 +1,4 @@
1
+ //#region src/is/deepEqual.d.ts
2
+ declare function isDeepEqualReact(a: any, b: any, ignoreKeys?: string[], debug?: boolean): boolean;
3
+ //#endregion
4
+ export { isDeepEqualReact };
@@ -0,0 +1,62 @@
1
+ //#region src/is/deepEqual.ts
2
+ /**
3
+ * React 深度比较
4
+ *
5
+ * @param a - 第一个值
6
+ * @param b - 第二个值
7
+ * @param ignoreKeys - 忽略的键
8
+ * @param debug - 是否调试
9
+ * @returns 是否相等
10
+ */
11
+ function isDeepEqualReact(a, b, ignoreKeys, debug) {
12
+ if (a === b) return true;
13
+ if (a && b && typeof a === "object" && typeof b === "object") {
14
+ if (a.constructor !== b.constructor) return false;
15
+ let length;
16
+ let i;
17
+ if (Array.isArray(a)) {
18
+ length = a.length;
19
+ if (length != b.length) return false;
20
+ for (i = length; i-- !== 0;) if (!isDeepEqualReact(a[i], b[i], ignoreKeys, debug)) return false;
21
+ return true;
22
+ }
23
+ if (a instanceof Map && b instanceof Map) {
24
+ if (a.size !== b.size) return false;
25
+ for (i of a.entries()) if (!b.has(i[0])) return false;
26
+ for (i of a.entries()) if (!isDeepEqualReact(i[1], b.get(i[0]), ignoreKeys, debug)) return false;
27
+ return true;
28
+ }
29
+ if (a instanceof Set && b instanceof Set) {
30
+ if (a.size !== b.size) return false;
31
+ for (i of a.entries()) if (!b.has(i[0])) return false;
32
+ return true;
33
+ }
34
+ if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
35
+ length = a.length;
36
+ if (length != b.length) return false;
37
+ for (i = length; i-- !== 0;) if (a[i] !== b[i]) return false;
38
+ return true;
39
+ }
40
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
41
+ if (a.valueOf !== Object.prototype.valueOf && a.valueOf) return a.valueOf() === b.valueOf();
42
+ if (a.toString !== Object.prototype.toString && a.toString) return a.toString() === b.toString();
43
+ const keys = Object.keys(a);
44
+ length = keys.length;
45
+ if (length !== Object.keys(b).length) return false;
46
+ for (i = length; i-- !== 0;) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
47
+ for (i = length; i-- !== 0;) {
48
+ const key = keys[i];
49
+ if (ignoreKeys?.includes(key)) continue;
50
+ if (key === "_owner" && a.$$typeof) continue;
51
+ if (!isDeepEqualReact(a[key], b[key], ignoreKeys, debug)) {
52
+ if (debug) console.log(key);
53
+ return false;
54
+ }
55
+ }
56
+ return true;
57
+ }
58
+ return a !== a && b !== b;
59
+ }
60
+
61
+ //#endregion
62
+ export { isDeepEqualReact };
@@ -0,0 +1,6 @@
1
+ //#region src/is/device.d.ts
2
+ declare function isMobile(): boolean;
3
+ declare function isTablet(): boolean;
4
+ declare function isWindowsOs(): boolean;
5
+ //#endregion
6
+ export { isMobile, isTablet, isWindowsOs };
@@ -0,0 +1,37 @@
1
+ //#region src/is/device.ts
2
+ /**
3
+ * 判断是否为移动端
4
+ *
5
+ * @returns 是否为移动端
6
+ */
7
+ function isMobile() {
8
+ const userAgent = navigator.userAgent || navigator.vendor;
9
+ if (/iPhone/.test(userAgent)) return true;
10
+ if (/Android/.test(userAgent) && /Mobile/.test(userAgent)) return true;
11
+ if (/Windows Phone/.test(userAgent)) return true;
12
+ if (/Mobile/.test(userAgent) && !isTablet()) return true;
13
+ return false;
14
+ }
15
+ /**
16
+ * 判断是否为平板
17
+ *
18
+ * @returns 是否为平板
19
+ */
20
+ function isTablet() {
21
+ const userAgent = navigator.userAgent || navigator.vendor;
22
+ if (/iPad/.test(userAgent)) return true;
23
+ if (/Macintosh/.test(userAgent) && "ontouchend" in document) return true;
24
+ if (/Android/.test(userAgent) && !/Mobile/.test(userAgent)) return true;
25
+ return false;
26
+ }
27
+ /**
28
+ * 检查当前运行环境是否为 Windows OS
29
+ *
30
+ * @returns 是否为 Windows 系统
31
+ */
32
+ function isWindowsOs() {
33
+ return /windows|win32/i.test(navigator.userAgent);
34
+ }
35
+
36
+ //#endregion
37
+ export { isMobile, isTablet, isWindowsOs };
@@ -0,0 +1,4 @@
1
+ //#region src/is/equal.d.ts
2
+ declare function isEqual(obj1: any, obj2: any, shallow?: boolean): boolean;
3
+ //#endregion
4
+ export { isEqual };
@@ -0,0 +1,34 @@
1
+ //#region src/is/equal.ts
2
+ /**
3
+ * 深度比较两个对象
4
+ *
5
+ * @param obj1 - 第一个对象
6
+ * @param obj2 - 第二个对象
7
+ * @param shallow - 是否浅比较
8
+ * @returns 是否相等
9
+ */
10
+ function isEqual(obj1, obj2, shallow = false) {
11
+ const refSet = /* @__PURE__ */ new Set();
12
+ function deepEqual(a, b, level = 1) {
13
+ if (refSet.has(a)) return false;
14
+ if (a === b) return true;
15
+ if (shallow && level > 1) return false;
16
+ refSet.add(a);
17
+ const newLevel = level + 1;
18
+ if (Array.isArray(a)) {
19
+ if (!Array.isArray(b) || a.length !== b.length) return false;
20
+ for (let i = 0; i < a.length; i++) if (!deepEqual(a[i], b[i], newLevel)) return false;
21
+ return true;
22
+ }
23
+ if (a && b && typeof a === "object" && typeof b === "object") {
24
+ const keys = Object.keys(a);
25
+ if (keys.length !== Object.keys(b).length) return false;
26
+ return keys.every((key) => deepEqual(a[key], b[key], newLevel));
27
+ }
28
+ return false;
29
+ }
30
+ return deepEqual(obj1, obj2);
31
+ }
32
+
33
+ //#endregion
34
+ export { isEqual };
@@ -0,0 +1,4 @@
1
+ //#region src/is/img.d.ts
2
+ declare function isImg(path: string): boolean;
3
+ //#endregion
4
+ export { isImg };
package/dist/is/img.js ADDED
@@ -0,0 +1,13 @@
1
+ //#region src/is/img.ts
2
+ /**
3
+ * 判断是否是图片链接
4
+ *
5
+ * @param path - 图片路径
6
+ * @returns 是否为图片
7
+ */
8
+ function isImg(path) {
9
+ return /\w.(?:png|jpg|jpeg|svg|webp|gif|bmp)$/i.test(path);
10
+ }
11
+
12
+ //#endregion
13
+ export { isImg };
@@ -0,0 +1,16 @@
1
+ import { isBase64, isDataURLBase64 } from "./base64.js";
2
+ import { isBrowser } from "./browser.js";
3
+ import { isDeepEqualReact } from "./deepEqual.js";
4
+ import { isMobile, isTablet, isWindowsOs } from "./device.js";
5
+ import { isEqual } from "./equal.js";
6
+ import { isImg } from "./img.js";
7
+ import { isNil, isNotNil } from "./nil.js";
8
+ import { isObjectWithSymbols, isPlainObject } from "./plainObject.js";
9
+ import { isPrimitive } from "./primitive.js";
10
+ import { isServer } from "./server.js";
11
+ import { is, isArray, isBoolean, isFunction, isJSONStr, isNumber, isObject, isString } from "./type.js";
12
+ import { isTypedArray } from "./typedArray.js";
13
+ import { isUnsafeProperty } from "./unsafeProperty.js";
14
+ import { isUrl } from "./url.js";
15
+ import { convertValueBoolean, isValid } from "./valid.js";
16
+ export { convertValueBoolean, is, isArray, isBase64, isBoolean, isBrowser, isDataURLBase64, isDeepEqualReact, isEqual, isFunction, isImg, isJSONStr, isMobile, isNil, isNotNil, isNumber, isObject, isObjectWithSymbols, isPlainObject, isPrimitive, isServer, isString, isTablet, isTypedArray, isUnsafeProperty, isUrl, isValid, isWindowsOs };
@@ -0,0 +1,17 @@
1
+ import { isBase64, isDataURLBase64 } from "./base64.js";
2
+ import { isBrowser } from "./browser.js";
3
+ import { isDeepEqualReact } from "./deepEqual.js";
4
+ import { isMobile, isTablet, isWindowsOs } from "./device.js";
5
+ import { isEqual } from "./equal.js";
6
+ import { isImg } from "./img.js";
7
+ import { isNil, isNotNil } from "./nil.js";
8
+ import { is, isArray, isBoolean, isFunction, isJSONStr, isNumber, isObject, isString } from "./type.js";
9
+ import { isObjectWithSymbols, isPlainObject } from "./plainObject.js";
10
+ import { isPrimitive } from "./primitive.js";
11
+ import { isServer } from "./server.js";
12
+ import { isTypedArray } from "./typedArray.js";
13
+ import { isUnsafeProperty } from "./unsafeProperty.js";
14
+ import { isUrl } from "./url.js";
15
+ import { convertValueBoolean, isValid } from "./valid.js";
16
+
17
+ export { convertValueBoolean, is, isArray, isBase64, isBoolean, isBrowser, isDataURLBase64, isDeepEqualReact, isEqual, isFunction, isImg, isJSONStr, isMobile, isNil, isNotNil, isNumber, isObject, isObjectWithSymbols, isPlainObject, isPrimitive, isServer, isString, isTablet, isTypedArray, isUnsafeProperty, isUrl, isValid, isWindowsOs };
@@ -0,0 +1,5 @@
1
+ //#region src/is/nil.d.ts
2
+ declare function isNil<T>(val: T): val is Extract<T, null | undefined>;
3
+ declare function isNotNil<T>(val: T): val is Exclude<T, null | undefined>;
4
+ //#endregion
5
+ export { isNil, isNotNil };
package/dist/is/nil.js ADDED
@@ -0,0 +1,22 @@
1
+ //#region src/is/nil.ts
2
+ /**
3
+ * 判断值是否为 null 或 undefined
4
+ *
5
+ * @param val - 要判断的值
6
+ * @returns 是否为 null 或 undefined
7
+ */
8
+ function isNil(val) {
9
+ return val === null || val === void 0;
10
+ }
11
+ /**
12
+ * 判断值是否不为 null 且不为 undefined
13
+ *
14
+ * @param val - 要判断的值
15
+ * @returns 是否不为 null 且不为 undefined
16
+ */
17
+ function isNotNil(val) {
18
+ return val !== null && val !== void 0;
19
+ }
20
+
21
+ //#endregion
22
+ export { isNil, isNotNil };
@@ -0,0 +1,5 @@
1
+ //#region src/is/plainObject.d.ts
2
+ declare function isPlainObject(value: unknown): value is Record<string, unknown>;
3
+ declare function isObjectWithSymbols(value: unknown): boolean;
4
+ //#endregion
5
+ export { isObjectWithSymbols, isPlainObject };
@@ -0,0 +1,30 @@
1
+ import { getSymbols } from "../function/object.js";
2
+ import { isObject } from "./type.js";
3
+
4
+ //#region src/is/plainObject.ts
5
+ /**
6
+ * 判断是否为纯对象(plain object)
7
+ *
8
+ * @param value - 要判断的值
9
+ * @returns 是否为纯对象
10
+ */
11
+ function isPlainObject(value) {
12
+ if (!isObject(value)) return false;
13
+ const proto = Object.getPrototypeOf(value);
14
+ if (proto === null) return true;
15
+ const ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
16
+ return typeof ctor === "function" && ctor instanceof ctor && Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object);
17
+ }
18
+ /**
19
+ * 检查对象是否有 Symbol 属性
20
+ *
21
+ * @param value - 要检查的值
22
+ * @returns 是否有 Symbol 属性
23
+ */
24
+ function isObjectWithSymbols(value) {
25
+ if (!isObject(value)) return false;
26
+ return getSymbols(value).length > 0;
27
+ }
28
+
29
+ //#endregion
30
+ export { isObjectWithSymbols, isPlainObject };
@@ -0,0 +1,4 @@
1
+ //#region src/is/primitive.d.ts
2
+ declare function isPrimitive(value: unknown): value is string | number | boolean | null | undefined | symbol | bigint;
3
+ //#endregion
4
+ 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,4 @@
1
+ //#region src/is/server.d.ts
2
+ declare const isServer: boolean;
3
+ //#endregion
4
+ 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,11 @@
1
+ //#region src/is/type.d.ts
2
+ declare function is(val: unknown, type: string): boolean;
3
+ declare function isBoolean(val: unknown): val is boolean;
4
+ declare function isNumber(val: unknown): val is number;
5
+ declare function isArray(val: any): val is Array<any>;
6
+ declare function isObject(val: any): val is Record<any, any>;
7
+ declare function isString(value: unknown): value is string;
8
+ declare function isFunction(func: unknown): func is (...args: any[]) => any;
9
+ declare function isJSONStr(str: any): boolean;
10
+ //#endregion
11
+ 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,4 @@
1
+ //#region src/is/typedArray.d.ts
2
+ declare function isTypedArray(x: unknown): x is Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | BigUint64Array | Int8Array | Int16Array | Int32Array | BigInt64Array | Float32Array | Float64Array;
3
+ //#endregion
4
+ 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,4 @@
1
+ //#region src/is/unsafeProperty.d.ts
2
+ declare function isUnsafeProperty(property: string | symbol): boolean;
3
+ //#endregion
4
+ 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,4 @@
1
+ //#region src/is/url.d.ts
2
+ declare function isUrl(path: string | undefined): boolean;
3
+ //#endregion
4
+ 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,5 @@
1
+ //#region src/is/valid.d.ts
2
+ declare function isValid(value: any): boolean;
3
+ declare function convertValueBoolean(value: any): boolean;
4
+ //#endregion
5
+ 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,50 +1,7 @@
1
- /**
2
- * 用于合并 n 个对象
3
- * @param {any[]} ...rest
4
- * @returns T
5
- */
6
- declare const merge: <T = any>(...rest: any[]) => T;
7
- /**
8
- * Merges the properties of the source object into a deep clone of the target object.
9
- * Unlike `merge`, This function does not modify the original target object.
10
- *
11
- * This function performs a deep merge, meaning nested objects and arrays are merged recursively.
12
- *
13
- * - 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.
14
- * - If a property in the source object is undefined, it will not overwrite a defined property in the target object.
15
- *
16
- * Note that this function does not mutate the target object.
17
- *
18
- * @param {T} target - The target object to be cloned and merged into. This object is not modified directly.
19
- * @param {S} source - The source object whose properties will be merged into the cloned target object.
20
- * @returns {T & S} A new object with properties from the source object merged into a deep clone of the target object.
21
- *
22
- * @template T - Type of the target object.
23
- * @template S - Type of the source object.
24
- *
25
- * @example
26
- * const target = { a: 1, b: { x: 1, y: 2 } };
27
- * const source = { b: { y: 3, z: 4 }, c: 5 };
28
- *
29
- * const result = toMerged(target, source);
30
- * console.log(result);
31
- * // Output: { a: 1, b: { x: 1, y: 3, z: 4 }, c: 5 }
32
- *
33
- * @example
34
- * const target = { a: [1, 2], b: { x: 1 } };
35
- * const source = { a: [3], b: { y: 2 } };
36
- *
37
- * const result = toMerged(target, source);
38
- * console.log(result);
39
- * // Output: { a: [3, 2], b: { x: 1, y: 2 } }
40
- *
41
- * @example
42
- * const target = { a: null };
43
- * const source = { a: [1, 2, 3] };
44
- *
45
- * const result = toMerged(target, source);
46
- * console.log(result);
47
- * // Output: { a: [1, 2, 3] }
48
- */
1
+ import { mergeWith } from "./mergeWith.js";
2
+
3
+ //#region src/merge/index.d.ts
4
+ declare function merge<T = any>(...rest: any[]): T;
49
5
  declare function deepMerge<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S): T & S;
50
- export { deepMerge, merge };
6
+ //#endregion
7
+ export { deepMerge, merge, mergeWith };
@@ -0,0 +1,41 @@
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
+
7
+ //#region src/merge/index.ts
8
+ /**
9
+ * 合并多个对象
10
+ *
11
+ * @param rest - 要合并的对象
12
+ * @returns 合并后的对象
13
+ */
14
+ function merge(...rest) {
15
+ const obj = {};
16
+ const il = rest.length;
17
+ let key;
18
+ let i = 0;
19
+ 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] = {
20
+ ...obj[key],
21
+ ...rest[i][key]
22
+ };
23
+ else obj[key] = rest[i][key];
24
+ return obj;
25
+ }
26
+ /**
27
+ * 深度合并对象
28
+ *
29
+ * @param target - 目标对象
30
+ * @param source - 源对象(一般是 default 对象)
31
+ * @returns 合并后的对象
32
+ */
33
+ function deepMerge(target, source) {
34
+ return mergeWith(cloneDeep(target), source, function mergeRecursively(targetValue, sourceValue) {
35
+ if (isPlainObject(sourceValue)) if (isPlainObject(targetValue)) return mergeWith(cloneDeep(targetValue), sourceValue, mergeRecursively);
36
+ else return mergeWith({}, sourceValue, mergeRecursively);
37
+ });
38
+ }
39
+
40
+ //#endregion
41
+ export { deepMerge, merge, mergeWith };