@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,69 @@
1
+ //#region src/file/convert.ts
2
+ /**
3
+ * 获取 Blob URL
4
+ *
5
+ * @param blob - Blob 对象
6
+ * @returns Blob URL
7
+ */
8
+ function getBlobUrl(blob) {
9
+ return URL.createObjectURL(blob);
10
+ }
11
+ /**
12
+ * 获取文件 base64 编码
13
+ *
14
+ * @param file - 文件对象
15
+ * @returns base64 字符串
16
+ */
17
+ function getBase64(file) {
18
+ return new Promise((resolve, reject) => {
19
+ const reader = new FileReader();
20
+ reader.readAsDataURL(file);
21
+ reader.onload = () => resolve(reader.result);
22
+ reader.onerror = (error) => reject(error);
23
+ });
24
+ }
25
+ /**
26
+ * Data URL 转 Blob 对象
27
+ *
28
+ * @param url - Data URL
29
+ * @returns Blob 对象
30
+ */
31
+ function dataURLtoBlob(url) {
32
+ const arr = url.split(",");
33
+ const mime = arr[0].match(/:(.*?);/)[1];
34
+ const str = atob(arr[1]);
35
+ let n = str.length;
36
+ const u8arr = new Uint8Array(n);
37
+ while (n--) u8arr[n] = str.charCodeAt(n);
38
+ return new Blob([u8arr], { type: mime });
39
+ }
40
+ /**
41
+ * Data URL 转 File 对象
42
+ *
43
+ * @param url - Data URL
44
+ * @param filename - 文件名
45
+ * @returns File 对象
46
+ */
47
+ function dataURLtoFile(url, filename) {
48
+ const arr = url.split(",");
49
+ const mime = arr[0].match(/:(.*?);/)[1];
50
+ const str = atob(arr[1]);
51
+ let n = str.length;
52
+ const u8arr = new Uint8Array(n);
53
+ while (n--) u8arr[n] = str.charCodeAt(n);
54
+ return new File([u8arr], filename, { type: mime });
55
+ }
56
+ /**
57
+ * Blob 转 File 对象
58
+ *
59
+ * @param blob - Blob 对象
60
+ * @param fileName - 文件名
61
+ * @param fileType - 文件类型
62
+ * @returns File 对象
63
+ */
64
+ function blobToDataURL(blob, fileName, fileType) {
65
+ return new window.File([blob], fileName, { type: fileType });
66
+ }
67
+
68
+ //#endregion
69
+ export { blobToDataURL, dataURLtoBlob, dataURLtoFile, getBase64, getBlobUrl };
@@ -0,0 +1,5 @@
1
+ import { fileTypes } from "./config.js";
2
+ import { blobToDataURL, dataURLtoBlob, dataURLtoFile, getBase64, getBlobUrl } from "./convert.js";
3
+ import { generateVideoPicture, getMediaInfos, getVideoCoverPicture } from "./media.js";
4
+ import { checkFileType, getFileSuffix, getVideoFileUrl } from "./type.js";
5
+ export { blobToDataURL, checkFileType, dataURLtoBlob, dataURLtoFile, fileTypes, generateVideoPicture, getBase64, getBlobUrl, getFileSuffix, getMediaInfos, getVideoCoverPicture, getVideoFileUrl };
@@ -0,0 +1,6 @@
1
+ import { fileTypes } from "./config.js";
2
+ import { blobToDataURL, dataURLtoBlob, dataURLtoFile, getBase64, getBlobUrl } from "./convert.js";
3
+ import { checkFileType, getFileSuffix, getVideoFileUrl } from "./type.js";
4
+ import { generateVideoPicture, getMediaInfos, getVideoCoverPicture } from "./media.js";
5
+
6
+ export { blobToDataURL, checkFileType, dataURLtoBlob, dataURLtoFile, fileTypes, generateVideoPicture, getBase64, getBlobUrl, getFileSuffix, getMediaInfos, getVideoCoverPicture, getVideoFileUrl };
@@ -0,0 +1,16 @@
1
+ import { MediaOptions } from "../typing.js";
2
+
3
+ //#region src/file/media.d.ts
4
+ declare function getMediaInfos(mediaInfo: {
5
+ url: any;
6
+ fileType?: string;
7
+ }): Promise<MediaOptions>;
8
+ declare function getVideoCoverPicture(videoInfo: {
9
+ url: any;
10
+ currentTime?: number;
11
+ videoSuffix?: string;
12
+ videoAllowPlay?: boolean;
13
+ }): Promise<string>;
14
+ declare function generateVideoPicture(videoUrl: string, currentTime?: number): Promise<string>;
15
+ //#endregion
16
+ export { generateVideoPicture, getMediaInfos, getVideoCoverPicture };
@@ -0,0 +1,161 @@
1
+ import { isBase64 } from "../is/base64.js";
2
+ import "../is/index.js";
3
+ import { fileTypes } from "./config.js";
4
+ import { checkFileType, getFileSuffix } from "./type.js";
5
+
6
+ //#region src/file/media.ts
7
+ /**
8
+ * 获取媒体信息(图片/视频/音频)
9
+ *
10
+ * @param mediaInfo - 媒体信息配置
11
+ * @returns 媒体详细信息
12
+ */
13
+ function getMediaInfos(mediaInfo) {
14
+ const { url = "", fileType = "1" } = mediaInfo || {};
15
+ let mediaUrl = "";
16
+ let result = {
17
+ play: false,
18
+ height: 0,
19
+ size: 0,
20
+ width: 0,
21
+ duration: 0
22
+ };
23
+ function resetResult() {
24
+ result = {
25
+ play: false,
26
+ height: 0,
27
+ size: 0,
28
+ width: 0,
29
+ duration: 0
30
+ };
31
+ }
32
+ if (url instanceof File) mediaUrl = URL.createObjectURL(url);
33
+ else if (isBase64(url)) mediaUrl = url;
34
+ else if (url instanceof Blob) mediaUrl = URL.createObjectURL(url);
35
+ else if (url.includes("https") || url.includes("http")) mediaUrl = fileType === "1" ? url : url;
36
+ return new Promise((resolve) => {
37
+ let el;
38
+ if (fileType === "4") {
39
+ resolve(result);
40
+ return;
41
+ }
42
+ if (fileType === "1") {
43
+ el = document.createElement("img");
44
+ el.src = mediaUrl;
45
+ } else if (fileType === "2") {
46
+ el = document.createElement("audio");
47
+ el.src = mediaUrl;
48
+ } else if (fileType === "3") {
49
+ el = document.createElement("video");
50
+ el.src = mediaUrl;
51
+ }
52
+ if (fileType === "1") el.onload = function() {
53
+ resetResult();
54
+ result.play = true;
55
+ result.width = el.width || 0;
56
+ result.height = el.height || 0;
57
+ resolve(result);
58
+ el = null;
59
+ };
60
+ else el.oncanplay = function() {
61
+ resetResult();
62
+ result.play = true;
63
+ result.width = el?.videoWidth || 0;
64
+ result.height = el?.videoHeight || 0;
65
+ result.duration = el?.duration || 0;
66
+ resolve(result);
67
+ el = null;
68
+ };
69
+ el.onerror = function() {
70
+ resetResult();
71
+ resolve(result);
72
+ el = null;
73
+ };
74
+ });
75
+ }
76
+ /**
77
+ * 获取视频封面图
78
+ *
79
+ * @param videoInfo - 视频信息
80
+ * @returns 封面图 base64
81
+ */
82
+ async function getVideoCoverPicture(videoInfo) {
83
+ const { url = "", currentTime, videoSuffix = "", videoAllowPlay = false } = videoInfo;
84
+ let videoUrl = "";
85
+ let fileSuffix = videoSuffix;
86
+ let fileType = "1";
87
+ let videoPlayInfo;
88
+ if (url instanceof File) {
89
+ videoUrl = URL.createObjectURL(url);
90
+ fileSuffix = getFileSuffix(url.name);
91
+ fileType = checkFileType(url.name);
92
+ } else if (url instanceof Blob) {
93
+ videoUrl = URL.createObjectURL(url);
94
+ fileType = checkFileType(url);
95
+ } else if (isBase64(url)) {
96
+ videoUrl = url;
97
+ fileType = checkFileType(url);
98
+ } else if (url.includes("https") || url.includes("http")) {
99
+ videoUrl = url;
100
+ fileSuffix = getFileSuffix(url);
101
+ fileType = checkFileType(url);
102
+ }
103
+ if (fileSuffix ? fileTypes.videoAllowType.includes(fileSuffix.toLowerCase()) : false) if (videoAllowPlay) return generateVideoPicture(videoUrl, currentTime);
104
+ else {
105
+ videoPlayInfo = await getMediaInfos({
106
+ url: videoUrl,
107
+ fileType
108
+ });
109
+ if (videoPlayInfo.play) return generateVideoPicture(videoUrl, currentTime);
110
+ else return new Promise((resolve) => {
111
+ resolve("");
112
+ });
113
+ }
114
+ else return new Promise((resolve) => {
115
+ resolve("");
116
+ });
117
+ }
118
+ /**
119
+ * 生成视频截图
120
+ *
121
+ * @param videoUrl - 视频 URL
122
+ * @param currentTime - 截图时间点
123
+ * @returns 截图 base64
124
+ */
125
+ async function generateVideoPicture(videoUrl, currentTime = 0) {
126
+ return new Promise((resolve) => {
127
+ let video = document.createElement("video");
128
+ if (video) {
129
+ video.controls = true;
130
+ video.muted = true;
131
+ video.setAttribute("src", videoUrl);
132
+ video.setAttribute("muted", String(true));
133
+ video.setAttribute("crossorigin", "anonymous");
134
+ video.setAttribute("autoplay", String(true));
135
+ video.addEventListener("loadeddata", async () => {
136
+ let seekResolve;
137
+ video?.addEventListener("seeked", async () => {
138
+ if (seekResolve) seekResolve();
139
+ });
140
+ while (currentTime < (video?.duration || 0)) {
141
+ if (video) video.currentTime = currentTime;
142
+ await new Promise((r) => seekResolve = r);
143
+ const canvas = document.createElement("canvas");
144
+ const scale = .8;
145
+ const ctx = canvas.getContext("2d");
146
+ const w = video?.videoWidth || 0 * scale;
147
+ const h = video?.videoHeight || 0 * scale;
148
+ const space = 0;
149
+ canvas.width = video?.videoWidth || 0 * scale;
150
+ canvas.height = video?.videoHeight || 0 * scale;
151
+ if (video) ctx.drawImage(video, 0, 0, w + space, h + space);
152
+ video = null;
153
+ resolve(w === 0 || h === 0 ? "" : canvas.toDataURL("image/png", 1));
154
+ }
155
+ });
156
+ }
157
+ });
158
+ }
159
+
160
+ //#endregion
161
+ export { generateVideoPicture, getMediaInfos, getVideoCoverPicture };
@@ -0,0 +1,6 @@
1
+ //#region src/file/type.d.ts
2
+ declare function getFileSuffix(url: string): string;
3
+ declare function getVideoFileUrl(url: string): string;
4
+ declare function checkFileType(url: any, type?: '1' | '2' | '3' | '4'): "1" | "2" | "3" | "4";
5
+ //#endregion
6
+ export { checkFileType, getFileSuffix, getVideoFileUrl };
@@ -0,0 +1,58 @@
1
+ import { isBase64 } from "../is/base64.js";
2
+ import "../is/index.js";
3
+ import { fileTypes } from "./config.js";
4
+
5
+ //#region src/file/type.ts
6
+ /**
7
+ * 获取文件后缀名
8
+ *
9
+ * @param url - 文件 URL
10
+ * @returns 后缀名
11
+ */
12
+ function getFileSuffix(url) {
13
+ if (!url || typeof url !== "string") return "";
14
+ const newUrl = getVideoFileUrl(url);
15
+ const index = newUrl.lastIndexOf(".");
16
+ return index > 0 ? `${newUrl?.substring?.(index)?.split("?")?.[0]}`?.split(".")?.[1] || "" : "";
17
+ }
18
+ /**
19
+ * 截取视频 URL(去除参数)
20
+ *
21
+ * @param url - URL
22
+ * @returns 处理后的 URL
23
+ */
24
+ function getVideoFileUrl(url) {
25
+ if (!url || typeof url !== "string") return "";
26
+ const index = url.indexOf("?");
27
+ return index > 0 ? `${url.substring(0, index)}` : url;
28
+ }
29
+ /**
30
+ * 检查文件类型
31
+ *
32
+ * @param url - 文件 URL 或对象
33
+ * @param type - 指定类型
34
+ * @returns 文件类型代码:1 图片, 2 音频, 3 视频, 4 其他
35
+ */
36
+ function checkFileType(url, type) {
37
+ if (type) return type;
38
+ if (!url) return "4";
39
+ if (url === "data:") return "4";
40
+ let fileType = "4";
41
+ if (isBase64(url)) {
42
+ if (url.includes("data:image/")) fileType = "png";
43
+ else if (url.includes("data:video/")) fileType = "mp4";
44
+ else if (url.includes("data:audio/")) fileType = "mp3";
45
+ } else if (url instanceof Blob) {
46
+ url = String(url);
47
+ if (url.includes("image")) fileType = "png";
48
+ else if (url.includes("video")) fileType = "mp4";
49
+ else if (url.includes("audio")) fileType = "mp3";
50
+ } else fileType = getFileSuffix(url).toLowerCase();
51
+ if (fileTypes.imageType.includes(fileType)) return "1";
52
+ if (fileTypes.videoType.includes(fileType)) return "3";
53
+ if (fileTypes.audioType.includes(fileType)) return "2";
54
+ return "4";
55
+ }
56
+
57
+ //#endregion
58
+ export { checkFileType, getFileSuffix, getVideoFileUrl };
@@ -0,0 +1,6 @@
1
+ import { RecordType } from "../typing.js";
2
+
3
+ //#region src/function/copy.d.ts
4
+ declare function deepCopy<T = RecordType>(data: any): T;
5
+ //#endregion
6
+ export { deepCopy };
@@ -0,0 +1,13 @@
1
+ //#region src/function/copy.ts
2
+ /**
3
+ * 简单深拷贝(使用 JSON 序列化)
4
+ *
5
+ * @param data - 要拷贝的数据
6
+ * @returns 拷贝后的数据
7
+ */
8
+ function deepCopy(data) {
9
+ return JSON.parse(JSON.stringify(data));
10
+ }
11
+
12
+ //#endregion
13
+ export { deepCopy };
@@ -0,0 +1,5 @@
1
+ //#region src/function/getValue.d.ts
2
+ type DeepValueOf<T, K> = K extends `${infer First}:${infer Rest}` ? First extends keyof T ? Rest extends '' ? T[First] : DeepValueOf<T[First], Rest> : undefined : K extends keyof T ? T[K] : undefined;
3
+ declare function getValueFromObjectByKey<T extends object, K extends string | string[] = string>(object: T, key: K): DeepValueOf<T, K extends string ? K : string> | undefined;
4
+ //#endregion
5
+ export { getValueFromObjectByKey };
@@ -0,0 +1,19 @@
1
+ //#region src/function/getValue.ts
2
+ /**
3
+ * 根据 key 从对象中获取值(支持嵌套路径)
4
+ *
5
+ * @param object - 目标对象
6
+ * @param key - 键路径(支持用冒号分隔的嵌套路径)
7
+ * @returns 获取的值
8
+ */
9
+ function getValueFromObjectByKey(object, key) {
10
+ if (typeof key !== "string" && !Array.isArray(key)) return;
11
+ const keys = Array.isArray(key) ? key : key.split(":");
12
+ let currentValue = object;
13
+ for (let i = 0; i < keys.length; i++) if (currentValue && Object.prototype.hasOwnProperty.call(currentValue, keys[i])) currentValue = currentValue[keys[i]];
14
+ else return;
15
+ return currentValue;
16
+ }
17
+
18
+ //#endregion
19
+ export { getValueFromObjectByKey };
@@ -0,0 +1,5 @@
1
+ import { deepCopy } from "./copy.js";
2
+ import { getValueFromObjectByKey } from "./getValue.js";
3
+ import { forInObject, getSymbols, keysOf } from "./object.js";
4
+ import { runFunction } from "./run.js";
5
+ export { deepCopy, forInObject, getSymbols, getValueFromObjectByKey, keysOf, runFunction };
@@ -0,0 +1,6 @@
1
+ import { forInObject, getSymbols, keysOf } from "./object.js";
2
+ import { deepCopy } from "./copy.js";
3
+ import { getValueFromObjectByKey } from "./getValue.js";
4
+ import { runFunction } from "./run.js";
5
+
6
+ export { deepCopy, forInObject, getSymbols, getValueFromObjectByKey, keysOf, runFunction };
@@ -0,0 +1,6 @@
1
+ //#region src/function/object.d.ts
2
+ declare function getSymbols(object: any): symbol[];
3
+ declare function forInObject<T extends object>(obj: T, callback: (key: keyof T, value: T[keyof T]) => void): void;
4
+ declare function keysOf<T extends object>(obj: T): (keyof T)[];
5
+ //#endregion
6
+ export { forInObject, getSymbols, keysOf };
@@ -0,0 +1,33 @@
1
+ //#region src/function/object.ts
2
+ /**
3
+ * 获取对象的 Symbol 属性
4
+ *
5
+ * @param object - 目标对象
6
+ * @returns Symbol 属性数组
7
+ */
8
+ function getSymbols(object) {
9
+ return Object.getOwnPropertySymbols(object);
10
+ }
11
+ /**
12
+ * 遍历对象属性
13
+ *
14
+ * @param obj - 目标对象
15
+ * @param callback - 回调函数
16
+ */
17
+ function forInObject(obj, callback) {
18
+ Object.keys(obj).forEach((key) => {
19
+ callback(key, obj[key]);
20
+ });
21
+ }
22
+ /**
23
+ * 获取对象的所有键
24
+ *
25
+ * @param obj - 目标对象
26
+ * @returns 键数组
27
+ */
28
+ function keysOf(obj) {
29
+ return Object.keys(obj);
30
+ }
31
+
32
+ //#endregion
33
+ export { forInObject, getSymbols, keysOf };
@@ -0,0 +1,4 @@
1
+ //#region src/function/run.d.ts
2
+ declare function runFunction<T extends any[]>(valueEnum: any, ...rest: T): any;
3
+ //#endregion
4
+ export { runFunction };
@@ -0,0 +1,15 @@
1
+ //#region src/function/run.ts
2
+ /**
3
+ * 如果值是函数则执行它,否则返回值
4
+ *
5
+ * @param valueEnum - 值或函数
6
+ * @param rest - 函数参数
7
+ * @returns 执行结果或原值
8
+ */
9
+ function runFunction(valueEnum, ...rest) {
10
+ if (typeof valueEnum === "function") return valueEnum(...rest);
11
+ return valueEnum;
12
+ }
13
+
14
+ //#endregion
15
+ export { runFunction };
package/dist/index.d.ts CHANGED
@@ -1,26 +1,58 @@
1
- import Base64 from './base64';
2
- import classNames from './classNames';
3
- import { getValueFromObjectByKey } from './getValueFromObjectByKey';
4
- import isServer from './isServer';
5
- import { getScrollContainer, isInContainer, isScroll } from './scroll';
6
- import getScroll from './scroll/getScroll';
7
- import scrollTo from './scroll/scrollTo';
8
- import throttleByAnimationFrame from './scroll/throttleByAnimationFrame';
9
- export * from './cloneDeep';
10
- export * from './cloneDeep/cloneDeepWith';
11
- export * from './isBrowser';
12
- export * from './isDeepEqualReact';
13
- export * from './isImg';
14
- export * from './isNil';
15
- export * from './isUrl';
16
- export * from './merge';
17
- export * from './merge/mergeWith';
18
- export * from './merge/useDeepMege';
19
- export * from './nanoid';
20
- export * from './omitBoolean';
21
- export * from './omitUndefined';
22
- export * from './omitUndefinedAndEmptyArr';
23
- export * from './slots';
24
- export * from './typings';
25
- export * from './utils';
26
- export { Base64, classNames, getScroll, getScrollContainer, getValueFromObjectByKey, isInContainer, isScroll, isServer, scrollTo, throttleByAnimationFrame };
1
+ import { arraySlice } from "./array/slice.js";
2
+ import { compareArray, compareArraySort, compareArrayTimeSort, compareTime } from "./array/sort.js";
3
+ import { AlignType, BasicTablePageConfig, Breakpoint, CustomRender, DeepPartial, ExtendIfDefined, Fn, LimitDeepPartial, MediaOptions, Nullable, OmitUndefined, RecordType, SemanticClassNames, SemanticStyles, SizeType, VueNode, WithFalse, WithIfDefault, WithRequired } from "./typing.js";
4
+ import { filterTree, findSourceByTree, findValueAndAncestors, getArrayLast, getLevelData, getMaxFloor, getSortIndex, treeData } from "./array/tree.js";
5
+ import { arrayUnique } from "./array/unique.js";
6
+ import "./array/index.js";
7
+ import { PrefixCls, getPrefixCls } from "./class/prefix.js";
8
+ import { cloneDeep } from "./clone/cloneDeep.js";
9
+ import { cloneDeepWith, cloneDeepWithImpl, copyProperties } from "./clone/cloneDeepWith.js";
10
+ import { off, on } from "./dom/event.js";
11
+ import { getTextWidth } from "./dom/measure.js";
12
+ import wrapperRaf from "./dom/raf.js";
13
+ import { getScroll, getScrollContainer, isInContainer, isScroll, isWindow } from "./dom/scroll.js";
14
+ import "./dom/index.js";
15
+ import { fileTypes } from "./file/config.js";
16
+ import { blobToDataURL, dataURLtoBlob, dataURLtoFile, getBase64, getBlobUrl } from "./file/convert.js";
17
+ import { generateVideoPicture, getMediaInfos, getVideoCoverPicture } from "./file/media.js";
18
+ import { checkFileType, getFileSuffix, getVideoFileUrl } from "./file/type.js";
19
+ import "./file/index.js";
20
+ import { deepCopy } from "./function/copy.js";
21
+ import { getValueFromObjectByKey } from "./function/getValue.js";
22
+ import { forInObject, getSymbols, keysOf } from "./function/object.js";
23
+ import { runFunction } from "./function/run.js";
24
+ import "./function/index.js";
25
+ import { isBase64, isDataURLBase64 } from "./is/base64.js";
26
+ import { isBrowser } from "./is/browser.js";
27
+ import { isDeepEqualReact } from "./is/deepEqual.js";
28
+ import { isMobile, isTablet, isWindowsOs } from "./is/device.js";
29
+ import { isEqual } from "./is/equal.js";
30
+ import { isImg } from "./is/img.js";
31
+ import { isNil, isNotNil } from "./is/nil.js";
32
+ import { isObjectWithSymbols, isPlainObject } from "./is/plainObject.js";
33
+ import { isPrimitive } from "./is/primitive.js";
34
+ import { isServer } from "./is/server.js";
35
+ import { is, isArray, isBoolean, isFunction, isJSONStr, isNumber, isObject, isString } from "./is/type.js";
36
+ import { isTypedArray } from "./is/typedArray.js";
37
+ import { isUnsafeProperty } from "./is/unsafeProperty.js";
38
+ import { isUrl } from "./is/url.js";
39
+ import { convertValueBoolean, isValid } from "./is/valid.js";
40
+ import { mergeWith } from "./merge/mergeWith.js";
41
+ import { deepMerge, merge } from "./merge/index.js";
42
+ import { toChinesNum } from "./number/chinese.js";
43
+ import { formatNumber, toConvertNumberShow } from "./number/format.js";
44
+ import classNames from "./object/classNames.js";
45
+ import { omitBoolean } from "./object/omitBoolean.js";
46
+ import { omitUndefined } from "./object/omitUndefined.js";
47
+ import { omitUndefinedAndEmptyArr } from "./object/omitUndefinedAndEmptyArr.js";
48
+ import "./object/index.js";
49
+ import { formatDuration } from "./string/duration.js";
50
+ import { handleEmptyField } from "./string/empty.js";
51
+ import { nanoid } from "./string/nanoid.js";
52
+ import { getRandomNumber } from "./string/uuid.js";
53
+ import { genColumnKey, handleShowIndex } from "./table/column.js";
54
+ import { handleCurrentPage } from "./table/page.js";
55
+ import "./table/index.js";
56
+ import { RenderResult, SlotsPropsResult, filterEmpty, getKeys, getSlot, getSlotVNode, getSlotsChildren, getSlotsProps, isEmptyElement, slotRender } from "./vue/slots.js";
57
+ import "./vue/index.js";
58
+ export { AlignType, BasicTablePageConfig, Breakpoint, CustomRender, DeepPartial, ExtendIfDefined, Fn, LimitDeepPartial, MediaOptions, Nullable, OmitUndefined, PrefixCls, RecordType, RenderResult, SemanticClassNames, SemanticStyles, SizeType, SlotsPropsResult, VueNode, WithFalse, WithIfDefault, WithRequired, arraySlice, arrayUnique, blobToDataURL, checkFileType, classNames, cloneDeep, cloneDeepWith, cloneDeepWithImpl, compareArray, compareArraySort, compareArrayTimeSort, compareTime, convertValueBoolean, copyProperties, dataURLtoBlob, dataURLtoFile, deepCopy, deepMerge, fileTypes, filterEmpty, filterTree, findSourceByTree, findValueAndAncestors, forInObject, formatDuration, formatNumber, genColumnKey, generateVideoPicture, getArrayLast, getBase64, getBlobUrl, getFileSuffix, getKeys, getLevelData, getMaxFloor, getMediaInfos, getPrefixCls, getRandomNumber, getScroll, getScrollContainer, getSlot, getSlotVNode, getSlotsChildren, getSlotsProps, getSortIndex, getSymbols, getTextWidth, getValueFromObjectByKey, getVideoCoverPicture, getVideoFileUrl, handleCurrentPage, handleEmptyField, handleShowIndex, is, isArray, isBase64, isBoolean, isBrowser, isDataURLBase64, isDeepEqualReact, isEmptyElement, isEqual, isFunction, isImg, isInContainer, isJSONStr, isMobile, isNil, isNotNil, isNumber, isObject, isObjectWithSymbols, isPlainObject, isPrimitive, isScroll, isServer, isString, isTablet, isTypedArray, isUnsafeProperty, isUrl, isValid, isWindow, isWindowsOs, keysOf, merge, mergeWith, nanoid, off, omitBoolean, omitUndefined, omitUndefinedAndEmptyArr, on, wrapperRaf as raf, runFunction, slotRender, toChinesNum, toConvertNumberShow, treeData };
package/dist/index.js ADDED
@@ -0,0 +1,60 @@
1
+ import { isBase64, isDataURLBase64 } from "./is/base64.js";
2
+ import { isBrowser } from "./is/browser.js";
3
+ import { isDeepEqualReact } from "./is/deepEqual.js";
4
+ import { isMobile, isTablet, isWindowsOs } from "./is/device.js";
5
+ import { isEqual } from "./is/equal.js";
6
+ import { isImg } from "./is/img.js";
7
+ import { isNil, isNotNil } from "./is/nil.js";
8
+ import { forInObject, getSymbols, keysOf } from "./function/object.js";
9
+ import { is, isArray, isBoolean, isFunction, isJSONStr, isNumber, isObject, isString } from "./is/type.js";
10
+ import { isObjectWithSymbols, isPlainObject } from "./is/plainObject.js";
11
+ import { isPrimitive } from "./is/primitive.js";
12
+ import { isServer } from "./is/server.js";
13
+ import { isTypedArray } from "./is/typedArray.js";
14
+ import { isUnsafeProperty } from "./is/unsafeProperty.js";
15
+ import { isUrl } from "./is/url.js";
16
+ import { convertValueBoolean, isValid } from "./is/valid.js";
17
+ import "./is/index.js";
18
+ import { arraySlice } from "./array/slice.js";
19
+ import { compareArray, compareArraySort, compareArrayTimeSort, compareTime } from "./array/sort.js";
20
+ import { filterTree, findSourceByTree, findValueAndAncestors, getArrayLast, getLevelData, getMaxFloor, getSortIndex, treeData } from "./array/tree.js";
21
+ import { arrayUnique } from "./array/unique.js";
22
+ import "./array/index.js";
23
+ import { getPrefixCls } from "./class/prefix.js";
24
+ import { cloneDeepWith, cloneDeepWithImpl, copyProperties } from "./clone/cloneDeepWith.js";
25
+ import { cloneDeep } from "./clone/cloneDeep.js";
26
+ import "./clone/index.js";
27
+ import { off, on } from "./dom/event.js";
28
+ import { getTextWidth } from "./dom/measure.js";
29
+ import wrapperRaf from "./dom/raf.js";
30
+ import { getScroll, getScrollContainer, isInContainer, isScroll, isWindow } from "./dom/scroll.js";
31
+ import "./dom/index.js";
32
+ import { fileTypes } from "./file/config.js";
33
+ import { blobToDataURL, dataURLtoBlob, dataURLtoFile, getBase64, getBlobUrl } from "./file/convert.js";
34
+ import { checkFileType, getFileSuffix, getVideoFileUrl } from "./file/type.js";
35
+ import { generateVideoPicture, getMediaInfos, getVideoCoverPicture } from "./file/media.js";
36
+ import "./file/index.js";
37
+ import { deepCopy } from "./function/copy.js";
38
+ import { getValueFromObjectByKey } from "./function/getValue.js";
39
+ import { runFunction } from "./function/run.js";
40
+ import { mergeWith } from "./merge/mergeWith.js";
41
+ import { deepMerge, merge } from "./merge/index.js";
42
+ import { toChinesNum } from "./number/chinese.js";
43
+ import { formatNumber, toConvertNumberShow } from "./number/format.js";
44
+ import "./number/index.js";
45
+ import classNames_default from "./object/classNames.js";
46
+ import { omitBoolean } from "./object/omitBoolean.js";
47
+ import { omitUndefined } from "./object/omitUndefined.js";
48
+ import { omitUndefinedAndEmptyArr } from "./object/omitUndefinedAndEmptyArr.js";
49
+ import "./object/index.js";
50
+ import { formatDuration } from "./string/duration.js";
51
+ import { handleEmptyField } from "./string/empty.js";
52
+ import { nanoid } from "./string/nanoid.js";
53
+ import { getRandomNumber } from "./string/uuid.js";
54
+ import { genColumnKey, handleShowIndex } from "./table/column.js";
55
+ import { handleCurrentPage } from "./table/page.js";
56
+ import "./table/index.js";
57
+ import { filterEmpty, getKeys, getSlot, getSlotVNode, getSlotsChildren, getSlotsProps, isEmptyElement, slotRender } from "./vue/slots.js";
58
+ import "./vue/index.js";
59
+
60
+ export { arraySlice, arrayUnique, blobToDataURL, checkFileType, classNames_default as classNames, cloneDeep, cloneDeepWith, cloneDeepWithImpl, compareArray, compareArraySort, compareArrayTimeSort, compareTime, convertValueBoolean, copyProperties, dataURLtoBlob, dataURLtoFile, deepCopy, deepMerge, fileTypes, filterEmpty, filterTree, findSourceByTree, findValueAndAncestors, forInObject, formatDuration, formatNumber, genColumnKey, generateVideoPicture, getArrayLast, getBase64, getBlobUrl, getFileSuffix, getKeys, getLevelData, getMaxFloor, getMediaInfos, getPrefixCls, getRandomNumber, getScroll, getScrollContainer, getSlot, getSlotVNode, getSlotsChildren, getSlotsProps, getSortIndex, getSymbols, getTextWidth, getValueFromObjectByKey, getVideoCoverPicture, getVideoFileUrl, handleCurrentPage, handleEmptyField, handleShowIndex, is, isArray, isBase64, isBoolean, isBrowser, isDataURLBase64, isDeepEqualReact, isEmptyElement, isEqual, isFunction, isImg, isInContainer, isJSONStr, isMobile, isNil, isNotNil, isNumber, isObject, isObjectWithSymbols, isPlainObject, isPrimitive, isScroll, isServer, isString, isTablet, isTypedArray, isUnsafeProperty, isUrl, isValid, isWindow, isWindowsOs, keysOf, merge, mergeWith, nanoid, off, omitBoolean, omitUndefined, omitUndefinedAndEmptyArr, on, wrapperRaf as raf, runFunction, slotRender, toChinesNum, toConvertNumberShow, treeData };
@@ -0,0 +1,5 @@
1
+ //#region src/is/base64.d.ts
2
+ declare function isBase64(str?: string): boolean;
3
+ declare function isDataURLBase64(str: string): boolean;
4
+ //#endregion
5
+ export { isBase64, isDataURLBase64 };
@@ -0,0 +1,27 @@
1
+ //#region src/is/base64.ts
2
+ /**
3
+ * 判断是否为 base64 编码的字符串
4
+ *
5
+ * @param str - 要判断的字符串
6
+ * @returns 是否为 base64 编码
7
+ */
8
+ function isBase64(str = "") {
9
+ if (str && [
10
+ "data:image/",
11
+ "data:video/",
12
+ "data:audio/"
13
+ ].find((item) => str.includes(item))) return true;
14
+ return false;
15
+ }
16
+ /**
17
+ * 判断是否为 Data URL 格式的 base64 字符串
18
+ *
19
+ * @param str - 要判断的字符串
20
+ * @returns 是否为 Data URL 格式的 base64
21
+ */
22
+ function isDataURLBase64(str) {
23
+ return typeof str === "string" && /^data:(?:image|video|audio)\/[A-Za-z]+;base64,[A-Za-z0-9+/=]+$/.test(str);
24
+ }
25
+
26
+ //#endregion
27
+ export { isBase64, isDataURLBase64 };
@@ -0,0 +1,4 @@
1
+ //#region src/is/browser.d.ts
2
+ declare function isBrowser(): boolean;
3
+ //#endregion
4
+ export { isBrowser };