@minto-ai/tools 1.0.45 → 1.0.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 获取文件路径(不包含查询参数)。
3
+ *
4
+ * @param filePath 文件路径。
5
+ * @returns 不包含查询参数的文件路径。
6
+ */
7
+ declare function getFilePathNotQuery(filePath: string): string;
8
+ export default getFilePathNotQuery;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 获取 URL 中的查询参数。
3
+ *
4
+ * @param filePath 文件路径。
5
+ * @returns 查询参数对象。
6
+ */
7
+ declare function getFileQuery(filePath: string): Record<string, any>;
8
+ export default getFileQuery;
@@ -3,6 +3,8 @@ import { default as batchDownloadFile } from './batch-download-file';
3
3
  import { FileSuffixEnum, ImageFileSuffixEnum } from './extends/enum';
4
4
  import { default as getFileIcon } from './get-file-icon';
5
5
  import { default as getFileName } from './get-file-name';
6
+ import { default as getFilePathNotQuery } from './get-file-path-not-query';
7
+ import { default as getFileQuery } from './get-file-query';
6
8
  import { default as getFileSuffix } from './get-file-suffix';
7
9
  import { default as getFileSuffixIcon } from './get-file-suffix-icon';
8
10
  import { default as getFileTitle } from './get-file-title';
@@ -15,4 +17,4 @@ import { default as isPptFilePath } from './is-ppt-file-path';
15
17
  import { default as isVideoFilePath } from './is-video-file-path';
16
18
  import { default as singleDownloadFile } from './single-download-file';
17
19
  export type { CompressFileSuffix, DocumentFileSuffix, FileSuffix, ImageFileSuffix, MusicFileSuffix, PptFileSuffix, VideoFileSuffix, };
18
- export { batchDownloadFile, FileSuffixEnum, getFileIcon, getFileName, getFileSuffix, getFileSuffixIcon, getFileTitle, ImageFileSuffixEnum, isCompressFilePath, isDocumentFilePath, isFilePath, isImageFilePath, isMusicFilePath, isPptFilePath, isVideoFilePath, singleDownloadFile, };
20
+ export { batchDownloadFile, FileSuffixEnum, getFileIcon, getFileName, getFilePathNotQuery, getFileQuery, getFileSuffix, getFileSuffixIcon, getFileTitle, ImageFileSuffixEnum, isCompressFilePath, isDocumentFilePath, isFilePath, isImageFilePath, isMusicFilePath, isPptFilePath, isVideoFilePath, singleDownloadFile, };
package/dist/index.d.ts CHANGED
@@ -7,5 +7,6 @@ export * from './math';
7
7
  export * from './object';
8
8
  export * from './string';
9
9
  export * from './supply';
10
+ export * from './validator';
10
11
  export * from './web-socket';
11
12
  export * from './wrker';
package/dist/index.js CHANGED
@@ -33,6 +33,14 @@ function _asyncToGenerator(n) {
33
33
  });
34
34
  };
35
35
  }
36
+ function _defineProperty(e, r, t) {
37
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
38
+ value: t,
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true
42
+ }) : e[r] = t, e;
43
+ }
36
44
  function _iterableToArrayLimit(r, l) {
37
45
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
38
46
  if (null != t) {
@@ -55,6 +63,27 @@ function _iterableToArrayLimit(r, l) {
55
63
  function _nonIterableRest() {
56
64
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
57
65
  }
66
+ function ownKeys$4(e, r) {
67
+ var t = Object.keys(e);
68
+ if (Object.getOwnPropertySymbols) {
69
+ var o = Object.getOwnPropertySymbols(e);
70
+ r && (o = o.filter(function(r2) {
71
+ return Object.getOwnPropertyDescriptor(e, r2).enumerable;
72
+ })), t.push.apply(t, o);
73
+ }
74
+ return t;
75
+ }
76
+ function _objectSpread2(e) {
77
+ for (var r = 1; r < arguments.length; r++) {
78
+ var t = null != arguments[r] ? arguments[r] : {};
79
+ r % 2 ? ownKeys$4(Object(t), true).forEach(function(r2) {
80
+ _defineProperty(e, r2, t[r2]);
81
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function(r2) {
82
+ Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
83
+ });
84
+ }
85
+ return e;
86
+ }
58
87
  function _regeneratorRuntime() {
59
88
  _regeneratorRuntime = function() {
60
89
  return r;
@@ -314,6 +343,20 @@ function _regeneratorRuntime() {
314
343
  function _slicedToArray(r, e) {
315
344
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
316
345
  }
346
+ function _toPrimitive(t, r) {
347
+ if ("object" != typeof t || !t) return t;
348
+ var e = t[Symbol.toPrimitive];
349
+ if (void 0 !== e) {
350
+ var i = e.call(t, r);
351
+ if ("object" != typeof i) return i;
352
+ throw new TypeError("@@toPrimitive must return a primitive value.");
353
+ }
354
+ return ("string" === r ? String : Number)(t);
355
+ }
356
+ function _toPropertyKey(t) {
357
+ var i = _toPrimitive(t, "string");
358
+ return "symbol" == typeof i ? i : i + "";
359
+ }
317
360
  function _typeof(o) {
318
361
  "@babel/helpers - typeof";
319
362
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
@@ -13135,6 +13178,12 @@ function isNullOrUndefined2(value) {
13135
13178
  function isUndefined(value) {
13136
13179
  return value === void 0;
13137
13180
  }
13181
+ function objectToQueryString(obj) {
13182
+ return Object.entries(obj).map(function(_ref) {
13183
+ var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1];
13184
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
13185
+ }).join("&");
13186
+ }
13138
13187
  var FileSuffixEnum = {
13139
13188
  DOC: "doc",
13140
13189
  DOCX: "docx",
@@ -13192,22 +13241,41 @@ var CompressFileSuffixEnum = {
13192
13241
  ZIP: FileSuffixEnum.ZIP,
13193
13242
  RAR: FileSuffixEnum.RAR
13194
13243
  };
13195
- var filePathRegex = new RegExp("(.*?)([^/.]*?)(\\.(".concat(Object.values(FileSuffixEnum).join("|"), "))?(\\?.*)?$"), "i");
13244
+ var filePathRegex = new RegExp("((.*?)(([^/.]*?)\\.(".concat(Object.values(FileSuffixEnum).join("|"), ")))(?:\\?(.*))?"), "i");
13196
13245
  function getFileSuffix(filePath) {
13197
- var _matchResult$4$toLowe, _matchResult$, _matchResult$$toLower;
13246
+ var _matchResult$5$toLowe, _matchResult$, _matchResult$$toLower;
13198
13247
  var matchResult = filePath.match(filePathRegex);
13199
- return (_matchResult$4$toLowe = matchResult === null || matchResult === void 0 || (_matchResult$ = matchResult[4]) === null || _matchResult$ === void 0 || (_matchResult$$toLower = _matchResult$.toLowerCase) === null || _matchResult$$toLower === void 0 ? void 0 : _matchResult$$toLower.call(_matchResult$)) !== null && _matchResult$4$toLowe !== void 0 ? _matchResult$4$toLowe : "";
13248
+ return (_matchResult$5$toLowe = matchResult === null || matchResult === void 0 || (_matchResult$ = matchResult[5]) === null || _matchResult$ === void 0 || (_matchResult$$toLower = _matchResult$.toLowerCase) === null || _matchResult$$toLower === void 0 ? void 0 : _matchResult$$toLower.call(_matchResult$)) !== null && _matchResult$5$toLowe !== void 0 ? _matchResult$5$toLowe : "";
13200
13249
  }
13201
13250
  function getFileTitle(filePath) {
13202
13251
  var _matchResult$;
13203
13252
  var matchResult = filePath.match(filePathRegex);
13204
- return (_matchResult$ = matchResult === null || matchResult === void 0 ? void 0 : matchResult[2]) !== null && _matchResult$ !== void 0 ? _matchResult$ : "";
13253
+ return (_matchResult$ = matchResult === null || matchResult === void 0 ? void 0 : matchResult[4]) !== null && _matchResult$ !== void 0 ? _matchResult$ : "";
13205
13254
  }
13206
13255
  function getFileName(filePath) {
13207
13256
  var fileTitle = getFileTitle(filePath);
13208
13257
  var fileSuffix = getFileSuffix(filePath);
13209
13258
  return fileSuffix ? "".concat(fileTitle, ".").concat(fileSuffix) : fileTitle;
13210
13259
  }
13260
+ function getFilePathNotQuery(filePath) {
13261
+ var _matchResult$;
13262
+ var matchResult = filePath.match(filePathRegex);
13263
+ return (_matchResult$ = matchResult === null || matchResult === void 0 ? void 0 : matchResult[1]) !== null && _matchResult$ !== void 0 ? _matchResult$ : "";
13264
+ }
13265
+ function queryStringToObject(queryString) {
13266
+ return queryString.split("&").filter(Boolean).map(function(str) {
13267
+ return str.split("=");
13268
+ }).reduce(function(obj, _ref) {
13269
+ var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1];
13270
+ obj[decodeURIComponent(key)] = decodeURIComponent(value);
13271
+ return obj;
13272
+ }, {});
13273
+ }
13274
+ function getFileQuery(filePath) {
13275
+ var _matchResult$;
13276
+ var matchResult = filePath.match(filePathRegex);
13277
+ return queryStringToObject((_matchResult$ = matchResult === null || matchResult === void 0 ? void 0 : matchResult[6]) !== null && _matchResult$ !== void 0 ? _matchResult$ : "");
13278
+ }
13211
13279
  function batchDownloadFile(_x, _x2) {
13212
13280
  return _batchDownloadFile.apply(this, arguments);
13213
13281
  }
@@ -13219,6 +13287,12 @@ function _batchDownloadFile() {
13219
13287
  case 0:
13220
13288
  fileList = fileList.map(function(_ref) {
13221
13289
  var filePath = _ref.filePath, fileName = _ref.fileName;
13290
+ var queryString = objectToQueryString(_objectSpread2(_objectSpread2({}, getFileQuery(filePath)), {}, {
13291
+ "response-content-type": "application/octet-stream"
13292
+ }));
13293
+ var filePathNotQuery = getFilePathNotQuery(filePath);
13294
+ filePath = checkEmpty(queryString) ? filePathNotQuery : "".concat(filePathNotQuery, "?").concat(queryString);
13295
+ fileName = checkEmpty(fileName) ? getFileName(filePath) : fileName;
13222
13296
  if (fileName) {
13223
13297
  return {
13224
13298
  filePath,
@@ -13227,7 +13301,7 @@ function _batchDownloadFile() {
13227
13301
  }
13228
13302
  return {
13229
13303
  filePath,
13230
- fileName: getFileName(filePath)
13304
+ fileName
13231
13305
  };
13232
13306
  });
13233
13307
  zip = new JSZip();
@@ -13392,22 +13466,26 @@ function singleDownloadFile(_x, _x2) {
13392
13466
  }
13393
13467
  function _singleDownloadFile() {
13394
13468
  _singleDownloadFile = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee(filePath, fileName) {
13395
- var _yield$axios$get, data2;
13469
+ var queryString, filePathNotQuery, _yield$axios$get, data2;
13396
13470
  return _regeneratorRuntime().wrap(function _callee$(_context) {
13397
13471
  while (1) switch (_context.prev = _context.next) {
13398
13472
  case 0:
13399
13473
  if (!fileName) {
13400
13474
  fileName = getFileName(filePath);
13401
13475
  }
13402
- _context.next = 3;
13403
- return axios.get("".concat(filePath, "?response-content-type=application/octet-stream"), {
13476
+ queryString = objectToQueryString(_objectSpread2(_objectSpread2({}, getFileQuery(filePath)), {}, {
13477
+ "response-content-type": "application/octet-stream"
13478
+ }));
13479
+ filePathNotQuery = getFilePathNotQuery(filePath);
13480
+ _context.next = 5;
13481
+ return axios.get(checkEmpty(queryString) ? filePathNotQuery : "".concat(filePathNotQuery, "?").concat(queryString), {
13404
13482
  responseType: "blob"
13405
13483
  });
13406
- case 3:
13484
+ case 5:
13407
13485
  _yield$axios$get = _context.sent;
13408
13486
  data2 = _yield$axios$get.data;
13409
13487
  FileSaver.saveAs(data2, fileName);
13410
- case 6:
13488
+ case 8:
13411
13489
  case "end":
13412
13490
  return _context.stop();
13413
13491
  }
@@ -13555,12 +13633,6 @@ function chunkString(str) {
13555
13633
  }
13556
13634
  return chunks;
13557
13635
  }
13558
- function objectToQueryString(obj) {
13559
- return Object.entries(obj).map(function(_ref) {
13560
- var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1];
13561
- return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
13562
- }).join("&");
13563
- }
13564
13636
  function getUuid() {
13565
13637
  return window.crypto.getRandomValues(new Uint32Array(1))[0].toString(36);
13566
13638
  }
@@ -13572,6 +13644,13 @@ function timeDelay(delay) {
13572
13644
  setTimeout(resolve2, delay);
13573
13645
  });
13574
13646
  }
13647
+ function isValidUrl(url) {
13648
+ if (!isString(url)) {
13649
+ return false;
13650
+ }
13651
+ var urlPattern = /^https?:\/\/(?:[\w-]+:[\w-]+@)?(?:localhost|(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}|(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))(?::\d{1,5})?(?:\/[^\s?#]*)?(?:\?[^\s#]*)?(?:#\S*)?$/i;
13652
+ return urlPattern.test(url.trim());
13653
+ }
13575
13654
  function createWebSocket(url) {
13576
13655
  return new WebSocket(url);
13577
13656
  }
@@ -13614,6 +13693,8 @@ export {
13614
13693
  getDecimalPlaces,
13615
13694
  getFileIcon,
13616
13695
  getFileName,
13696
+ getFilePathNotQuery,
13697
+ getFileQuery,
13617
13698
  getFileSuffix,
13618
13699
  getFileSuffixIcon,
13619
13700
  getFileTitle,
@@ -13634,11 +13715,13 @@ export {
13634
13715
  isPptFilePath,
13635
13716
  isString,
13636
13717
  isUndefined,
13718
+ isValidUrl,
13637
13719
  isVideoFilePath,
13638
13720
  isWebSocketSupported,
13639
13721
  multiply2 as multiply,
13640
13722
  objectToQueryString,
13641
13723
  pickObject,
13724
+ queryStringToObject,
13642
13725
  singleDownloadFile,
13643
13726
  subtract,
13644
13727
  throttle,
@@ -1,3 +1,4 @@
1
1
  import { default as chunkString } from './chunk-string';
2
2
  import { default as objectToQueryString } from './object-to-query-string';
3
- export { chunkString, objectToQueryString };
3
+ import { default as queryStringToObject } from './query-string-to-object';
4
+ export { chunkString, objectToQueryString, queryStringToObject };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 将 URL 查询字符串转换为对象
3
+ *
4
+ * @param queryString - 需要解析的 URL 查询字符串(例如:"a=1&b=2")。
5
+ * @returns 转换后的对象。
6
+ */
7
+ declare function queryStringToObject(queryString: string): Record<string, any>;
8
+ export default queryStringToObject;
@@ -0,0 +1,2 @@
1
+ import { default as isValidUrl } from './is-valid-url';
2
+ export { isValidUrl, };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 检查给定的URL是否符合标准网页地址格式。
3
+ * @param url - 需要验证的URL字符串。
4
+ * @returns 如果URL格式合格,返回true;否则返回false。
5
+ */
6
+ export declare function isValidUrl(url: string): boolean;
7
+ export default isValidUrl;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@minto-ai/tools",
3
3
  "type": "module",
4
- "version": "1.0.45",
4
+ "version": "1.0.47",
5
5
  "description": "明途公共工具库",
6
6
  "author": "hcc",
7
7
  "license": "ISC",