@minto-ai/tools 1.0.2 → 1.0.3

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.
package/README.md CHANGED
@@ -637,8 +637,8 @@ console.log(divide(100.001, 0.001)) // 100001
637
637
  import { copyText } from '@minto-ai/tools'
638
638
 
639
639
  copyText('Hello, World!').then(
640
- (text) => console.log('Text copied to clipboard:', text),
641
- (error) => console.error('Failed to copy text:', error)
640
+ text => console.log('Text copied to clipboard:', text),
641
+ error => console.error('Failed to copy text:', error)
642
642
  )
643
643
  ```
644
644
 
@@ -1069,7 +1069,7 @@ console.log(isDocumentFilePath('/path/to/document.doc')) // true
1069
1069
  #### 示例
1070
1070
 
1071
1071
  ```typescript
1072
- import { getFileSuffixIcon, FileSuffixEnum } from '@minto-ai/tools'
1072
+ import { FileSuffixEnum, getFileSuffixIcon } from '@minto-ai/tools'
1073
1073
 
1074
1074
  console.log(getFileSuffixIcon(FileSuffixEnum.PDF)) // 返回 pdfIcon 的路径
1075
1075
  console.log(getFileSuffixIcon(FileSuffixEnum.JPG)) // 返回 imageIcon 的路径
@@ -1258,7 +1258,8 @@ import { isWebSocketSupported } from '@minto-ai/tools'
1258
1258
 
1259
1259
  if (isWebSocketSupported()) {
1260
1260
  console.log('WebSocket is supported!')
1261
- } else {
1261
+ }
1262
+ else {
1262
1263
  console.log('WebSocket is not supported!')
1263
1264
  }
1264
1265
  ```
@@ -1307,7 +1308,7 @@ const socket = createWebSocket('ws://example.com')
1307
1308
  ```typescript
1308
1309
  import { createWorker } from '@minto-ai/tools'
1309
1310
 
1310
- const myWorker = createWorker(function () {
1311
+ const myWorker = createWorker(() => {
1311
1312
  console.log('Hello from the Web Worker!')
1312
1313
  })
1313
1314
  ```
@@ -1325,9 +1326,9 @@ const myWorker = createWorker(function () {
1325
1326
  #### 例子
1326
1327
 
1327
1328
  ```typescript
1328
- import { createWorker, closeWorker } from '@minto-ai/tools'
1329
+ import { closeWorker, createWorker } from '@minto-ai/tools'
1329
1330
 
1330
- const myWorker = createWorker(function () {
1331
+ const myWorker = createWorker(() => {
1331
1332
  console.log('Hello from the Web Worker!')
1332
1333
  })
1333
1334
  // 当不再需要 Worker 时
@@ -3,4 +3,4 @@ import { default as isAndroid } from './is-android';
3
3
  import { default as isIos } from './is-ios';
4
4
  import { default as isMobile } from './is-mobile';
5
5
  import { default as isPc } from './is-pc';
6
- export { copyText, isIos, isMobile, isPc, isAndroid };
6
+ export { copyText, isAndroid, isIos, isMobile, isPc };
@@ -4,5 +4,5 @@
4
4
  * @param value 输入值。
5
5
  * @returns 转换后的数字值,如果无法解析则返回 `NaN`。
6
6
  */
7
- declare function beParsedAsNumber(value: never): number;
7
+ declare function beParsedAsNumber(value: number | string): number;
8
8
  export default beParsedAsNumber;
@@ -10,4 +10,4 @@ import { default as isNumber } from './is-number';
10
10
  import { default as isObject } from './is-object';
11
11
  import { default as isString } from './is-string';
12
12
  import { default as isUndefined } from './is-undefined';
13
- export { checkArrayEmpty, checkEmpty, checkEmptyNotZero, checkObjectEmpty, isArray, isNumber, isObject, isString, canBeParsedAsNumber, isUndefined, isNullOrUndefined, beParsedAsNumber };
13
+ export { beParsedAsNumber, canBeParsedAsNumber, checkArrayEmpty, checkEmpty, checkEmptyNotZero, checkObjectEmpty, isArray, isNullOrUndefined, isNumber, isObject, isString, isUndefined, };
@@ -78,4 +78,4 @@ declare const FileItemFeedTypeEnum: {
78
78
  readonly TWEET: 9;
79
79
  readonly COMIC_STRIP: 10;
80
80
  };
81
- export { FileSuffixEnum, FileItemFeedTypeEnum, ImageFileSuffixEnum, VideoFileSuffixEnum, PptFileSuffixEnum, DocumentFileSuffixEnum };
81
+ export { DocumentFileSuffixEnum, FileItemFeedTypeEnum, FileSuffixEnum, ImageFileSuffixEnum, PptFileSuffixEnum, VideoFileSuffixEnum, };
@@ -1,3 +1,3 @@
1
1
  declare const fileSuffixRegex: RegExp;
2
2
  declare const fileNameRegex: RegExp;
3
- export { fileSuffixRegex, fileNameRegex };
3
+ export { fileNameRegex, fileSuffixRegex };
@@ -1,12 +1,13 @@
1
+ import { DocumentFileSuffix, FileItemFeedType, FileSuffix, IFileItem, ImageFileSuffix, PptFileSuffix, VideoFileSuffix } from './types';
1
2
  import { default as batchDownloadFile } from './batch-download-file';
2
- import { FileSuffixEnum, FileItemFeedTypeEnum, ImageFileSuffixEnum } from './extends/enum';
3
+ import { FileItemFeedTypeEnum, FileSuffixEnum, ImageFileSuffixEnum } from './extends/enum';
3
4
  import { default as getFileFeedType } from './get-file-feed-type';
4
5
  import { default as getFileIcon } from './get-file-icon';
5
- import { default as getFileSuffixIcon } from './get-file-suffix-icon';
6
6
  import { default as getFileItemIcon } from './get-file-item-icon';
7
7
  import { default as getFileItemSuffix } from './get-file-item-suffix';
8
8
  import { default as getFileName } from './get-file-name';
9
9
  import { default as getFileSuffix } from './get-file-suffix';
10
+ import { default as getFileSuffixIcon } from './get-file-suffix-icon';
10
11
  import { default as getFileTitle } from './get-file-title';
11
12
  import { default as isDocumentFilePath } from './is-document-file-path';
12
13
  import { default as isFilePath } from './is-file-path';
@@ -14,6 +15,5 @@ import { default as isImageFilePath } from './is-image-file-path';
14
15
  import { default as isPptFilePath } from './is-ppt-file-path';
15
16
  import { default as isVideoFilePath } from './is-video-file-path';
16
17
  import { default as singleDownloadFile } from './single-download-file';
17
- import { IFileItem, FileSuffix, FileItemFeedType, ImageFileSuffix, VideoFileSuffix, PptFileSuffix, DocumentFileSuffix } from './types';
18
- export type { IFileItem, FileSuffix, FileItemFeedType, ImageFileSuffix, VideoFileSuffix, PptFileSuffix, DocumentFileSuffix };
19
- export { getFileName, getFileTitle, getFileSuffix, isFilePath, getFileIcon, getFileItemIcon, getFileSuffixIcon, getFileItemSuffix, singleDownloadFile, batchDownloadFile, FileSuffixEnum, FileItemFeedTypeEnum, ImageFileSuffixEnum, getFileFeedType, isImageFilePath, isVideoFilePath, isDocumentFilePath, isPptFilePath };
18
+ export type { DocumentFileSuffix, FileItemFeedType, FileSuffix, IFileItem, ImageFileSuffix, PptFileSuffix, VideoFileSuffix, };
19
+ export { batchDownloadFile, FileItemFeedTypeEnum, FileSuffixEnum, getFileFeedType, getFileIcon, getFileItemIcon, getFileItemSuffix, getFileName, getFileSuffix, getFileSuffixIcon, getFileTitle, ImageFileSuffixEnum, isDocumentFilePath, isFilePath, isImageFilePath, isPptFilePath, isVideoFilePath, singleDownloadFile, };
@@ -1,4 +1,4 @@
1
- import { FileSuffixEnum, FileItemFeedTypeEnum, ImageFileSuffixEnum, VideoFileSuffixEnum, PptFileSuffixEnum, DocumentFileSuffixEnum } from '../extends/enum';
1
+ import { DocumentFileSuffixEnum, FileItemFeedTypeEnum, FileSuffixEnum, ImageFileSuffixEnum, PptFileSuffixEnum, VideoFileSuffixEnum } from '../extends/enum';
2
2
  type FileSuffix = (typeof FileSuffixEnum)[keyof typeof FileSuffixEnum];
3
3
  type ImageFileSuffix = (typeof ImageFileSuffixEnum)[keyof typeof ImageFileSuffixEnum];
4
4
  type VideoFileSuffix = (typeof VideoFileSuffixEnum)[keyof typeof VideoFileSuffixEnum];
@@ -15,4 +15,4 @@ interface IFileItem {
15
15
  createTime?: string;
16
16
  feedType?: FileItemFeedType;
17
17
  }
18
- export type { IFileItem, FileSuffix, FileItemFeedType, ImageFileSuffix, VideoFileSuffix, PptFileSuffix, DocumentFileSuffix };
18
+ export type { DocumentFileSuffix, FileItemFeedType, FileSuffix, IFileItem, ImageFileSuffix, PptFileSuffix, VideoFileSuffix, };
@@ -2,7 +2,7 @@
2
2
  * 防抖函数的类型定义
3
3
  * @template T - 原始函数的类型
4
4
  */
5
- type DebouncedFunction<T extends (...args: any[]) => any> = {
5
+ interface DebouncedFunction<T extends (...args: any[]) => any> {
6
6
  /**
7
7
  * 防抖后的函数,参数类型与原函数一致
8
8
  */
@@ -11,7 +11,7 @@ type DebouncedFunction<T extends (...args: any[]) => any> = {
11
11
  * 取消防抖函数的未执行部分
12
12
  */
13
13
  cancel: () => void;
14
- };
14
+ }
15
15
  /**
16
16
  * 创建一个防抖函数。
17
17
  * 防抖函数的作用是限制一个函数在短时间内频繁触发的次数,直到指定的延迟时间结束后才执行。
@@ -1,3 +1,3 @@
1
1
  import { default as debounce } from './debounce';
2
2
  import { default as throttle } from './throttle';
3
- export { throttle, debounce };
3
+ export { debounce, throttle };
@@ -2,7 +2,7 @@
2
2
  * 节流函数的类型定义
3
3
  * @template T - 原始函数的类型
4
4
  */
5
- type ThrottledFunction<T extends (...args: any[]) => any> = {
5
+ interface ThrottledFunction<T extends (...args: any[]) => any> {
6
6
  /**
7
7
  * 节流后的函数,参数类型与原函数一致
8
8
  */
@@ -11,7 +11,7 @@ type ThrottledFunction<T extends (...args: any[]) => any> = {
11
11
  * 取消节流函数的未执行部分
12
12
  */
13
13
  cancel: () => void;
14
- };
14
+ }
15
15
  /**
16
16
  * 创建一个节流函数。
17
17
  * 节流函数的作用是限制一个函数在一定时间内最多执行一次,避免高频触发导致的性能问题。
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  export * from './array';
2
2
  export * from './browser';
3
3
  export * from './core';
4
- export * from './object';
5
- export * from './supply';
6
- export * from './web-socket';
7
- export * from './wrker';
8
4
  export * from './file';
9
5
  export * from './function';
10
6
  export * from './math';
7
+ export * from './object';
11
8
  export * from './string';
9
+ export * from './supply';
10
+ export * from './web-socket';
11
+ export * from './wrker';
package/dist/index.js CHANGED
@@ -67,7 +67,7 @@ function beParsedAsNumber(value) {
67
67
  return Number.NaN;
68
68
  }
69
69
  function canBeParsedAsNumber(value) {
70
- return /^-?\d+(\.\d+)?$/.test(String(value));
70
+ return /^-?\d+\.\d+$/.test(String(value));
71
71
  }
72
72
  function isArray(value) {
73
73
  return Array.isArray(value);
@@ -100,54 +100,6 @@ function isNullOrUndefined(value) {
100
100
  function isUndefined(value) {
101
101
  return value === void 0;
102
102
  }
103
- function deepFreeze(obj) {
104
- if (isObject(obj)) {
105
- Object.keys(obj).forEach((key) => {
106
- const prop = obj[key];
107
- if (prop && typeof prop === "object") {
108
- deepFreeze(prop);
109
- }
110
- });
111
- }
112
- return Object.freeze(obj);
113
- }
114
- function pickObject(obj, keys) {
115
- const result = {};
116
- keys.forEach((key) => {
117
- if (key in obj) {
118
- result[key] = obj[key];
119
- }
120
- });
121
- return result;
122
- }
123
- function getUuid() {
124
- return window.crypto.getRandomValues(new Uint32Array(1))[0].toString(36);
125
- }
126
- function timeDelay(delay) {
127
- if (typeof delay !== "number" || delay < 0) {
128
- throw new Error("延迟时间必须是非负数");
129
- }
130
- return new Promise((resolve) => {
131
- setTimeout(resolve, delay);
132
- });
133
- }
134
- function createWebSocket(url) {
135
- return new WebSocket(url);
136
- }
137
- function isWebSocketSupported() {
138
- return ["WebSocket", "MozWebSocket"].some((key) => key in window);
139
- }
140
- function closeWorker(worker) {
141
- if (!worker) return;
142
- worker.terminate();
143
- }
144
- function createWorker(fun) {
145
- const blob = new Blob([`(${fun.toString()})()`]);
146
- const url = window.URL.createObjectURL(blob);
147
- const worker = new Worker(url);
148
- window.URL.revokeObjectURL(url);
149
- return worker;
150
- }
151
103
  const FileSuffixEnum = {
152
104
  DOC: "doc",
153
105
  DOCX: "docx",
@@ -253,7 +205,7 @@ async function batchDownloadFile(fileList, zipName) {
253
205
  });
254
206
  })
255
207
  );
256
- } catch (error) {
208
+ } catch {
257
209
  throw new Error("批量下载失败,部分文件下载出错。");
258
210
  }
259
211
  const zipData = await zip.generateAsync({
@@ -358,7 +310,8 @@ function getFileItemIcon(fileItem) {
358
310
  return fileIcon;
359
311
  }
360
312
  function isDocumentFilePath(filePath) {
361
- if (!filePath) return false;
313
+ if (!filePath)
314
+ return false;
362
315
  const fileSuffix = getFileSuffix(filePath);
363
316
  return Object.values(DocumentFileSuffixEnum).includes(fileSuffix);
364
317
  }
@@ -366,17 +319,20 @@ function isFilePath(filePath) {
366
319
  return !!getFileSuffix(filePath);
367
320
  }
368
321
  function isImageFilePath(filePath) {
369
- if (!filePath) return false;
322
+ if (!filePath)
323
+ return false;
370
324
  const fileSuffix = getFileSuffix(filePath);
371
325
  return Object.values(ImageFileSuffixEnum).includes(fileSuffix);
372
326
  }
373
327
  function isPptFilePath(filePath) {
374
- if (!filePath) return false;
328
+ if (!filePath)
329
+ return false;
375
330
  const fileSuffix = getFileSuffix(filePath);
376
331
  return Object.values(PptFileSuffixEnum).includes(fileSuffix);
377
332
  }
378
333
  function isVideoFilePath(filePath) {
379
- if (!filePath) return false;
334
+ if (!filePath)
335
+ return false;
380
336
  const fileSuffix = getFileSuffix(filePath);
381
337
  return Object.values(VideoFileSuffixEnum).includes(fileSuffix);
382
338
  }
@@ -484,6 +440,26 @@ function subtract(minuend, subtrahend) {
484
440
  const difference = scaledMinuend - scaledSubtrahend;
485
441
  return difference / scalingFactor;
486
442
  }
443
+ function deepFreeze(obj) {
444
+ if (isObject(obj)) {
445
+ Object.keys(obj).forEach((key) => {
446
+ const prop = obj[key];
447
+ if (prop && typeof prop === "object") {
448
+ deepFreeze(prop);
449
+ }
450
+ });
451
+ }
452
+ return Object.freeze(obj);
453
+ }
454
+ function pickObject(obj, keys) {
455
+ const result = {};
456
+ keys.forEach((key) => {
457
+ if (key in obj) {
458
+ result[key] = obj[key];
459
+ }
460
+ });
461
+ return result;
462
+ }
487
463
  function chunkString(str, chunkSize = str.length) {
488
464
  if (chunkSize === 0) {
489
465
  throw new Error("块大小不能为 0");
@@ -500,6 +476,35 @@ function chunkString(str, chunkSize = str.length) {
500
476
  }
501
477
  return chunks;
502
478
  }
479
+ function getUuid() {
480
+ return window.crypto.getRandomValues(new Uint32Array(1))[0].toString(36);
481
+ }
482
+ function timeDelay(delay) {
483
+ if (typeof delay !== "number" || delay < 0) {
484
+ throw new Error("延迟时间必须是非负数");
485
+ }
486
+ return new Promise((resolve) => {
487
+ setTimeout(resolve, delay);
488
+ });
489
+ }
490
+ function createWebSocket(url) {
491
+ return new WebSocket(url);
492
+ }
493
+ function isWebSocketSupported() {
494
+ return ["WebSocket", "MozWebSocket"].some((key) => key in window);
495
+ }
496
+ function closeWorker(worker) {
497
+ if (!worker)
498
+ return;
499
+ worker.terminate();
500
+ }
501
+ function createWorker(fun) {
502
+ const blob = new Blob([`(${fun.toString()})()`]);
503
+ const url = window.URL.createObjectURL(blob);
504
+ const worker = new Worker(url);
505
+ window.URL.revokeObjectURL(url);
506
+ return worker;
507
+ }
503
508
  export {
504
509
  FileItemFeedTypeEnum,
505
510
  FileSuffixEnum,
@@ -3,4 +3,4 @@ import { default as divide } from './divide';
3
3
  import { default as getDecimalPlaces } from './get-decimal-places';
4
4
  import { default as multiply } from './multiply';
5
5
  import { default as subtract } from './subtract';
6
- export { add, divide, multiply, subtract, getDecimalPlaces };
6
+ export { add, divide, getDecimalPlaces, multiply, subtract };
@@ -1,3 +1,3 @@
1
1
  import { default as deepFreeze } from './deep-freeze';
2
2
  import { default as pickObject } from './pick-object';
3
- export { pickObject, deepFreeze };
3
+ export { deepFreeze, pickObject };
package/package.json CHANGED
@@ -1,22 +1,22 @@
1
1
  {
2
2
  "name": "@minto-ai/tools",
3
- "version": "1.0.2",
3
+ "type": "module",
4
+ "version": "1.0.3",
4
5
  "description": "明途公共工具库",
6
+ "author": "hcc",
7
+ "license": "ISC",
5
8
  "keywords": [
6
9
  "ts",
7
10
  "tools"
8
11
  ],
9
- "author": "hcc",
10
- "license": "ISC",
11
12
  "publishConfig": {
12
13
  "access": "public"
13
14
  },
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
14
17
  "files": [
15
18
  "dist"
16
19
  ],
17
- "type": "module",
18
- "module": "./dist/index.js",
19
- "types": "./dist/index.d.ts",
20
20
  "scripts": {
21
21
  "build": "vite build",
22
22
  "up": "gulp --gulpfile ../../gulpfile.cjs --cwd ./"