util-helpers 5.2.0 → 5.2.2

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 (85) hide show
  1. package/README.md +18 -17
  2. package/dist/util-helpers.js +78 -73
  3. package/dist/util-helpers.js.map +1 -1
  4. package/dist/util-helpers.min.js +1 -1
  5. package/dist/util-helpers.min.js.map +1 -1
  6. package/esm/VERSION.js +1 -1
  7. package/esm/checkFileType.js +6 -4
  8. package/esm/getFileType.js +2 -2
  9. package/esm/getMimeType.js +2 -2
  10. package/esm/index.js +3 -3
  11. package/esm/utils/file.util.js +7 -4
  12. package/lib/VERSION.js +1 -1
  13. package/lib/checkFileType.js +6 -4
  14. package/lib/getFileType.js +2 -2
  15. package/lib/getMimeType.js +2 -2
  16. package/lib/index.js +6 -6
  17. package/lib/utils/file.util.js +6 -2
  18. package/package.json +1 -1
  19. package/types/AsyncMemo.d.ts +1 -1
  20. package/types/VERSION.d.ts +1 -3
  21. package/types/ajax.d.ts +19 -3
  22. package/types/bytesToSize.d.ts +0 -1
  23. package/types/calculateCursorPosition.d.ts +0 -1
  24. package/types/checkFileType.d.ts +3 -2
  25. package/types/compressImage.d.ts +1 -1
  26. package/types/dataURLToBlob.d.ts +1 -2
  27. package/types/divide.d.ts +0 -1
  28. package/types/download.d.ts +7 -21
  29. package/types/fileReader.d.ts +1 -1
  30. package/types/filterTree.d.ts +0 -1
  31. package/types/findTreeNode.d.ts +0 -1
  32. package/types/findTreeNodes.d.ts +0 -1
  33. package/types/findTreeSelect.d.ts +0 -1
  34. package/types/formatBankCard.d.ts +0 -1
  35. package/types/formatMobile.d.ts +0 -1
  36. package/types/formatMoney.d.ts +0 -1
  37. package/types/gcd.d.ts +0 -1
  38. package/types/getFileBlob.d.ts +1 -2
  39. package/types/getFileType.d.ts +13 -4
  40. package/types/getImageInfo.d.ts +14 -5
  41. package/types/getMimeType.d.ts +41 -4
  42. package/types/index.d.ts +12 -10
  43. package/types/isBankCard.d.ts +0 -1
  44. package/types/isBusinessLicense.d.ts +0 -1
  45. package/types/isChinese.d.ts +0 -1
  46. package/types/isEmail.d.ts +0 -1
  47. package/types/isHMCard.d.ts +0 -1
  48. package/types/isIPv4.d.ts +0 -1
  49. package/types/isIPv6.d.ts +0 -1
  50. package/types/isIdCard.d.ts +0 -1
  51. package/types/isMobile.d.ts +0 -1
  52. package/types/isPassport.d.ts +0 -1
  53. package/types/isPassword.d.ts +0 -1
  54. package/types/isPostcode.d.ts +0 -1
  55. package/types/isQQ.d.ts +0 -1
  56. package/types/isSocialCreditCode.d.ts +0 -1
  57. package/types/isSwiftCode.d.ts +0 -1
  58. package/types/isTWCard.d.ts +0 -1
  59. package/types/isTelephone.d.ts +0 -1
  60. package/types/isUrl.d.ts +0 -1
  61. package/types/isValidNumber.d.ts +0 -1
  62. package/types/isVehicle.d.ts +0 -1
  63. package/types/isWX.d.ts +0 -1
  64. package/types/lcm.d.ts +0 -1
  65. package/types/listToTree.d.ts +0 -1
  66. package/types/loadImage.d.ts +1 -2
  67. package/types/loadImageWithBlob.d.ts +3 -2
  68. package/types/loadScript.d.ts +1 -2
  69. package/types/minus.d.ts +0 -1
  70. package/types/numberToChinese.d.ts +0 -1
  71. package/types/padZero.d.ts +0 -1
  72. package/types/parseIdCard.d.ts +0 -1
  73. package/types/plus.d.ts +0 -1
  74. package/types/replaceChar.d.ts +0 -1
  75. package/types/round.d.ts +0 -1
  76. package/types/setDataURLPrefix.d.ts +0 -1
  77. package/types/strlen.d.ts +0 -1
  78. package/types/times.d.ts +0 -1
  79. package/types/transformFieldNames.d.ts +0 -1
  80. package/types/transformObjectValue.d.ts +0 -1
  81. package/types/treeToList.d.ts +0 -1
  82. package/types/utils/config.d.ts +0 -1
  83. package/types/utils/file.util.d.ts +4 -1
  84. package/types/validatePassword.d.ts +0 -1
  85. package/types/BlobUrl.d.ts +0 -41
package/esm/VERSION.js CHANGED
@@ -1,4 +1,4 @@
1
- var VERSION = "5.2.0";
1
+ var VERSION = "5.2.2";
2
2
  var VERSION$1 = VERSION;
3
3
 
4
4
  export { VERSION$1 as default };
@@ -2,7 +2,9 @@ import { isFile, isString, toString } from 'ut2';
2
2
  import { isUploadFile, testExt } from './utils/file.util.js';
3
3
 
4
4
  function checkFileType(file, accept) {
5
- if (!isFile(file) && !isUploadFile(file)) {
5
+ var _a, _b;
6
+ var isFileType = isFile(file);
7
+ if (!isFileType && !isUploadFile(file)) {
6
8
  return false;
7
9
  }
8
10
  if (!isString(accept)) {
@@ -14,9 +16,9 @@ function checkFileType(file, accept) {
14
16
  }
15
17
  var ret = false;
16
18
  var types = accept.toLowerCase().split(/,(?:\s+)?/);
17
- var fileName = file.name.toLowerCase();
18
- var fileType = file.type || '';
19
- var fileUrl = file.url || '';
19
+ var fileName = (file.name || (!isFileType && (file.fileName || ((_a = file.originFileObj) === null || _a === void 0 ? void 0 : _a.name))) || '').toLowerCase();
20
+ var fileType = file.type || (!isFileType && ((_b = file.originFileObj) === null || _b === void 0 ? void 0 : _b.type)) || '';
21
+ var fileUrl = (!isFileType && file.url) || '';
20
22
  types.some(function (type) {
21
23
  if (type === '*' || fileType === type || (type.indexOf('.') === 0 && (testExt(fileName, type) || testExt(fileUrl, type)))) {
22
24
  ret = true;
@@ -3,9 +3,9 @@ import checkFileType from './checkFileType.js';
3
3
  import { isUploadFile } from './utils/file.util.js';
4
4
 
5
5
  var config = {
6
- image: 'image/*,.jpeg,.jpg,.gif,.bmp,.png,.webp',
6
+ image: 'image/*,.jpeg,.jpg,.gif,.bmp,.png,.webp,.svg,.apng,.avif,.ico,.tif,.tiff',
7
7
  audio: 'audio/*,.mp3,.wav,.aac,.flac',
8
- video: 'video/*,.mp4,.webm,.ogg',
8
+ video: 'video/*,.mp4,.webm,.ogg,.mov',
9
9
  pdf: 'application/pdf,.pdf',
10
10
  word: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document,.doc,.docx',
11
11
  excel: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,.xls,.xlsx'
@@ -1,5 +1,5 @@
1
- import { isString, nth } from 'ut2';
2
1
  import { nativeUndefined } from './utils/native.js';
2
+ import { getFileNameExt } from './utils/file.util.js';
3
3
 
4
4
  var mimeTypes = [
5
5
  ['text/plain', ['txt']],
@@ -36,7 +36,7 @@ var mimeTypes = [
36
36
  ];
37
37
  function getMimeType(fileName) {
38
38
  var _a;
39
- var ext = isString(fileName) ? nth(fileName.split('.'), -1) : '';
39
+ var ext = getFileNameExt(fileName).slice(1);
40
40
  return ext ? (_a = mimeTypes.find(function (item) { return item[1].includes(ext); })) === null || _a === void 0 ? void 0 : _a[0] : nativeUndefined;
41
41
  }
42
42
 
package/esm/index.js CHANGED
@@ -26,8 +26,6 @@ export { default as replaceChar } from './replaceChar.js';
26
26
  export { default as numberToChinese } from './numberToChinese.js';
27
27
  export { default as bytesToSize } from './bytesToSize.js';
28
28
  export { default as parseIdCard } from './parseIdCard.js';
29
- export { default as fileReader } from './fileReader.js';
30
- export { default as dataURLToBlob } from './dataURLToBlob.js';
31
29
  export { default as setDataURLPrefix } from './setDataURLPrefix.js';
32
30
  export { default as safeDate } from './safeDate.js';
33
31
  export { default as formatMobile } from './formatMobile.js';
@@ -41,10 +39,11 @@ export { default as round } from './round.js';
41
39
  export { default as gcd } from './gcd.js';
42
40
  export { default as lcm } from './lcm.js';
43
41
  export { default as ajax } from './ajax.js';
44
- export { default as calculateCursorPosition } from './calculateCursorPosition.js';
45
42
  export { default as checkFileType } from './checkFileType.js';
46
43
  export { default as compressImage } from './compressImage.js';
44
+ export { default as dataURLToBlob } from './dataURLToBlob.js';
47
45
  export { default as download } from './download.js';
46
+ export { default as fileReader } from './fileReader.js';
48
47
  export { default as getFileBlob } from './getFileBlob.js';
49
48
  export { default as getFileType } from './getFileType.js';
50
49
  export { default as getImageInfo } from './getImageInfo.js';
@@ -52,6 +51,7 @@ export { default as getMimeType } from './getMimeType.js';
52
51
  export { default as loadImage } from './loadImage.js';
53
52
  export { default as loadImageWithBlob } from './loadImageWithBlob.js';
54
53
  export { default as loadScript } from './loadScript.js';
54
+ export { default as calculateCursorPosition } from './calculateCursorPosition.js';
55
55
  export { default as randomString } from './randomString.js';
56
56
  export { default as strlen } from './strlen.js';
57
57
  export { default as transformFieldNames } from './transformFieldNames.js';
@@ -1,13 +1,16 @@
1
- import { isObjectLike, isString } from 'ut2';
1
+ import { isString, nth, isObjectLike } from 'ut2';
2
2
 
3
+ function getFileNameExt(name) {
4
+ return isString(name) && name.indexOf('.') > 0 ? '.' + nth(name.split('.'), -1) : '';
5
+ }
3
6
  function testExt(name, ext) {
4
- return !!name && name.slice(-ext.length) === ext;
7
+ return !!name && getFileNameExt(name) === ext;
5
8
  }
6
9
  function isUploadFile(fileObj) {
7
- if (isObjectLike(fileObj) && isString(fileObj.uid) && isString(fileObj.name)) {
10
+ if (isObjectLike(fileObj) && isString(fileObj.name)) {
8
11
  return true;
9
12
  }
10
13
  return false;
11
14
  }
12
15
 
13
- export { isUploadFile, testExt };
16
+ export { getFileNameExt, isUploadFile, testExt };
package/lib/VERSION.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var VERSION = "5.2.0";
3
+ var VERSION = "5.2.2";
4
4
  var VERSION$1 = VERSION;
5
5
 
6
6
  module.exports = VERSION$1;
@@ -4,7 +4,9 @@ var ut2 = require('ut2');
4
4
  var file_util = require('./utils/file.util.js');
5
5
 
6
6
  function checkFileType(file, accept) {
7
- if (!ut2.isFile(file) && !file_util.isUploadFile(file)) {
7
+ var _a, _b;
8
+ var isFileType = ut2.isFile(file);
9
+ if (!isFileType && !file_util.isUploadFile(file)) {
8
10
  return false;
9
11
  }
10
12
  if (!ut2.isString(accept)) {
@@ -16,9 +18,9 @@ function checkFileType(file, accept) {
16
18
  }
17
19
  var ret = false;
18
20
  var types = accept.toLowerCase().split(/,(?:\s+)?/);
19
- var fileName = file.name.toLowerCase();
20
- var fileType = file.type || '';
21
- var fileUrl = file.url || '';
21
+ var fileName = (file.name || (!isFileType && (file.fileName || ((_a = file.originFileObj) === null || _a === void 0 ? void 0 : _a.name))) || '').toLowerCase();
22
+ var fileType = file.type || (!isFileType && ((_b = file.originFileObj) === null || _b === void 0 ? void 0 : _b.type)) || '';
23
+ var fileUrl = (!isFileType && file.url) || '';
22
24
  types.some(function (type) {
23
25
  if (type === '*' || fileType === type || (type.indexOf('.') === 0 && (file_util.testExt(fileName, type) || file_util.testExt(fileUrl, type)))) {
24
26
  ret = true;
@@ -5,9 +5,9 @@ var checkFileType = require('./checkFileType.js');
5
5
  var file_util = require('./utils/file.util.js');
6
6
 
7
7
  var config = {
8
- image: 'image/*,.jpeg,.jpg,.gif,.bmp,.png,.webp',
8
+ image: 'image/*,.jpeg,.jpg,.gif,.bmp,.png,.webp,.svg,.apng,.avif,.ico,.tif,.tiff',
9
9
  audio: 'audio/*,.mp3,.wav,.aac,.flac',
10
- video: 'video/*,.mp4,.webm,.ogg',
10
+ video: 'video/*,.mp4,.webm,.ogg,.mov',
11
11
  pdf: 'application/pdf,.pdf',
12
12
  word: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document,.doc,.docx',
13
13
  excel: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,.xls,.xlsx'
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var ut2 = require('ut2');
4
3
  var native = require('./utils/native.js');
4
+ var file_util = require('./utils/file.util.js');
5
5
 
6
6
  var mimeTypes = [
7
7
  ['text/plain', ['txt']],
@@ -38,7 +38,7 @@ var mimeTypes = [
38
38
  ];
39
39
  function getMimeType(fileName) {
40
40
  var _a;
41
- var ext = ut2.isString(fileName) ? ut2.nth(fileName.split('.'), -1) : '';
41
+ var ext = file_util.getFileNameExt(fileName).slice(1);
42
42
  return ext ? (_a = mimeTypes.find(function (item) { return item[1].includes(ext); })) === null || _a === void 0 ? void 0 : _a[0] : native.nativeUndefined;
43
43
  }
44
44
 
package/lib/index.js CHANGED
@@ -28,8 +28,6 @@ var replaceChar = require('./replaceChar.js');
28
28
  var numberToChinese = require('./numberToChinese.js');
29
29
  var bytesToSize = require('./bytesToSize.js');
30
30
  var parseIdCard = require('./parseIdCard.js');
31
- var fileReader = require('./fileReader.js');
32
- var dataURLToBlob = require('./dataURLToBlob.js');
33
31
  var setDataURLPrefix = require('./setDataURLPrefix.js');
34
32
  var safeDate = require('./safeDate.js');
35
33
  var formatMobile = require('./formatMobile.js');
@@ -43,10 +41,11 @@ var round = require('./round.js');
43
41
  var gcd = require('./gcd.js');
44
42
  var lcm = require('./lcm.js');
45
43
  var ajax = require('./ajax.js');
46
- var calculateCursorPosition = require('./calculateCursorPosition.js');
47
44
  var checkFileType = require('./checkFileType.js');
48
45
  var compressImage = require('./compressImage.js');
46
+ var dataURLToBlob = require('./dataURLToBlob.js');
49
47
  var download = require('./download.js');
48
+ var fileReader = require('./fileReader.js');
50
49
  var getFileBlob = require('./getFileBlob.js');
51
50
  var getFileType = require('./getFileType.js');
52
51
  var getImageInfo = require('./getImageInfo.js');
@@ -54,6 +53,7 @@ var getMimeType = require('./getMimeType.js');
54
53
  var loadImage = require('./loadImage.js');
55
54
  var loadImageWithBlob = require('./loadImageWithBlob.js');
56
55
  var loadScript = require('./loadScript.js');
56
+ var calculateCursorPosition = require('./calculateCursorPosition.js');
57
57
  var randomString = require('./randomString.js');
58
58
  var strlen = require('./strlen.js');
59
59
  var transformFieldNames = require('./transformFieldNames.js');
@@ -97,8 +97,6 @@ exports.replaceChar = replaceChar;
97
97
  exports.numberToChinese = numberToChinese;
98
98
  exports.bytesToSize = bytesToSize;
99
99
  exports.parseIdCard = parseIdCard;
100
- exports.fileReader = fileReader;
101
- exports.dataURLToBlob = dataURLToBlob;
102
100
  exports.setDataURLPrefix = setDataURLPrefix;
103
101
  exports.safeDate = safeDate;
104
102
  exports.formatMobile = formatMobile;
@@ -112,10 +110,11 @@ exports.round = round;
112
110
  exports.gcd = gcd;
113
111
  exports.lcm = lcm;
114
112
  exports.ajax = ajax;
115
- exports.calculateCursorPosition = calculateCursorPosition;
116
113
  exports.checkFileType = checkFileType;
117
114
  exports.compressImage = compressImage;
115
+ exports.dataURLToBlob = dataURLToBlob;
118
116
  exports.download = download;
117
+ exports.fileReader = fileReader;
119
118
  exports.getFileBlob = getFileBlob;
120
119
  exports.getFileType = getFileType;
121
120
  exports.getImageInfo = getImageInfo;
@@ -123,6 +122,7 @@ exports.getMimeType = getMimeType;
123
122
  exports.loadImage = loadImage;
124
123
  exports.loadImageWithBlob = loadImageWithBlob;
125
124
  exports.loadScript = loadScript;
125
+ exports.calculateCursorPosition = calculateCursorPosition;
126
126
  exports.randomString = randomString;
127
127
  exports.strlen = strlen;
128
128
  exports.transformFieldNames = transformFieldNames;
@@ -2,15 +2,19 @@
2
2
 
3
3
  var ut2 = require('ut2');
4
4
 
5
+ function getFileNameExt(name) {
6
+ return ut2.isString(name) && name.indexOf('.') > 0 ? '.' + ut2.nth(name.split('.'), -1) : '';
7
+ }
5
8
  function testExt(name, ext) {
6
- return !!name && name.slice(-ext.length) === ext;
9
+ return !!name && getFileNameExt(name) === ext;
7
10
  }
8
11
  function isUploadFile(fileObj) {
9
- if (ut2.isObjectLike(fileObj) && ut2.isString(fileObj.uid) && ut2.isString(fileObj.name)) {
12
+ if (ut2.isObjectLike(fileObj) && ut2.isString(fileObj.name)) {
10
13
  return true;
11
14
  }
12
15
  return false;
13
16
  }
14
17
 
18
+ exports.getFileNameExt = getFileNameExt;
15
19
  exports.isUploadFile = isUploadFile;
16
20
  exports.testExt = testExt;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "util-helpers",
3
- "version": "5.2.0",
3
+ "version": "5.2.2",
4
4
  "description": "一个基于业务场景的工具方法库",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -25,7 +25,7 @@ import { Cache, CacheOptions } from 'cache2';
25
25
  declare class AsyncMemo<DataType = any> {
26
26
  private promiseCache;
27
27
  /**
28
- * cache2 实例,用于管理缓存
28
+ * @summary cache2 实例,用于管理缓存
29
29
  */
30
30
  cache: Cache<DataType>;
31
31
  constructor(options?: Partial<CacheOptions>);
@@ -1,7 +1,5 @@
1
1
  /**
2
- * util-helpers 版本号
3
- *
4
- * @static
2
+ * @summary util-helpers 版本号。
5
3
  * @since 4.18.0
6
4
  */
7
5
  declare const VERSION: string;
package/types/ajax.d.ts CHANGED
@@ -44,13 +44,29 @@ type AjaxOptions = {
44
44
  *
45
45
  * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
46
46
  *
47
- * @static
48
- * @alias module:Other.ajax
47
+ * @alias module:Browser.ajax
49
48
  * @since 4.16.0
50
49
  * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest | XMLHttpRequest}
51
50
  * @param {string} url 地址
52
51
  * @param {AjaxOptions} [options] 配置项
53
- * @returns {Promise<object>} XHR 事件对象
52
+ * @param {string} [options.method="get"] 创建请求时使用的方法。默认 `'get'`。
53
+ * @param {boolean} [options.async=true] 是否异步执行操作。默认 `true`。
54
+ * @param {string|null} [options.user=null] 用户名,用于认证用途。默认 `null`。
55
+ * @param {string|null} [options.password=null] 密码,用于认证用途。默认 `null`。
56
+ * @param {Object} [options.headers] 自定义请求头。
57
+ * @param {string} [options.responseType] 响应类型。
58
+ * @param {number} [options.timeout] 请求超时的毫秒数。
59
+ * @param {boolean} [options.withCredentials=false] 跨域请求时是否需要使用凭证。默认 `false`。
60
+ * @param {*} [options.data=null] 请求体被发送的数据。默认 `null`。
61
+ * @param {function} [options.onReadyStateChange] 当 readyState 属性发生变化时触发。
62
+ * @param {function} [options.onLoadStart] 接收到响应数据时触发。
63
+ * @param {function} [options.onProgress] 请求接收到更多数据时,周期性地触发。
64
+ * @param {function} [options.onAbort] 当 request 被停止时触发,例如当程序调用 XMLHttpRequest.abort() 时。
65
+ * @param {function} [options.onTimeout] 在预设时间内没有接收到响应时触发。
66
+ * @param {function} [options.onError] 当 request 遭遇错误时触发。
67
+ * @param {function} [options.onLoad] 请求成功完成时触发。
68
+ * @param {function} [options.onLoadEnd] 请求结束时触发,无论请求成功 (load) 还是失败 (abort 或 error)。
69
+ * @returns {Promise<object>} XHR 事件对象。
54
70
  * @example
55
71
  * ajax('/somefile').then(res=>{
56
72
  * // do something
@@ -5,7 +5,6 @@ type BytesToSizeOptions = {
5
5
  /**
6
6
  * 字节转换存储单位
7
7
  *
8
- * @static
9
8
  * @alias module:Processor.bytesToSize
10
9
  * @since 3.8.0
11
10
  * @param {number} bytes 字节大小
@@ -6,7 +6,6 @@ type CalculateCursorPositionOptions = {
6
6
  /**
7
7
  * 计算输入框的值格式化后光标位置
8
8
  *
9
- * @static
10
9
  * @alias module:Other.calculateCursorPosition
11
10
  * @since 4.6.0
12
11
  * @see {@link https://2950v9.csb.app/ | h5示例}
@@ -2,8 +2,9 @@ import { UploadFile } from './utils/file.util';
2
2
  /**
3
3
  * 检查文件是否符合 `accept` 类型说明符。
4
4
  *
5
- * @static
6
- * @alias module:Other.checkFileType
5
+ * 通过 `file.type` `file.name` `file.url` 与 `accept` 进行匹配。
6
+ *
7
+ * @alias module:Browser.checkFileType
7
8
  * @since 5.1.0
8
9
  * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/input/file#唯一文件类型说明符 | 唯一文件类型说明符}
9
10
  * @see {@link https://www.iana.org/assignments/media-types/media-types.xhtml | Media Types}
@@ -35,7 +35,7 @@ interface CompressImage {
35
35
  * <em style="font-weight: bold;">如果是半透明图片并且导出 `image/png` 格式,建议将背景变成透明 `background=transparent`,避免出现白边。注意正常图片压缩导出 `image/png` 格式后文件可能会比原图大。</em>
36
36
  *
37
37
  * @function
38
- * @alias module:Other.compressImage
38
+ * @alias module:Browser.compressImage
39
39
  * @since 4.20.0
40
40
  * @see {@link https://sytpwg.csb.app/ | 在线示例}
41
41
  * @param {string | Blob} img 图片地址或 blob 对象
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * 将 DataURL 转为 Blob 对象
3
3
  *
4
- * @static
5
- * @alias module:Processor.dataURLToBlob
4
+ * @alias module:Browser.dataURLToBlob
6
5
  * @since 4.1.0
7
6
  * @see {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64 | Base64}
8
7
  * @param {string} data data: 协议的URL
package/types/divide.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 精确除法,支持多个数相除,除数默认为 1 。
3
3
  *
4
- * @static
5
4
  * @alias module:Math.divide
6
5
  * @since 3.1.0
7
6
  * @param {...(number|string)} nums 被除数和除数
@@ -10,24 +10,6 @@ type DownloadOptions = {
10
10
  transformRequest?: TransformRequest;
11
11
  transformResponse?: TransformResponse;
12
12
  };
13
- /**
14
- * @callback TransformRequest
15
- * @param {AjaxOptions} options ajax 配置项
16
- * @returns {AjaxOptions | Promise<AjaxOptions>}
17
- */
18
- /**
19
- * @callback TransformResponse
20
- * @param {Blob} res 响应的Blob对象。如果你通过 transformRequest 修改了 responseType ,该参数将是该类型响应值。
21
- * @returns {Blob | Promise<Blob>}
22
- */
23
- /**
24
- * @typedef {Object} DownloadOptions 下载配置项
25
- * @property {string} [fileName] 文件名称
26
- * @property {string} [type] MIME 类型
27
- * @property {'url'|'text'} [dataType] 手动设置数据类型,默认会根据传入的数据判断类型,主要是为了区分 url 和 text 。<br/>如果你要下载的文本是 url ,请设置 'text' ;如果你要下载的 url 是绝对/相对路径,请设置 'url' 。
28
- * @property {TransformRequest} [transformRequest] 请求前触发,XHR 对象或配置调整
29
- * @property {TransformResponse} [transformResponse] 请求成功后触发,在传递给 then/catch 前,允许修改响应数据
30
- */
31
13
  /**
32
14
  * 下载
33
15
  *
@@ -37,14 +19,18 @@ type DownloadOptions = {
37
19
  *
38
20
  * <em>响应头中有 "Content-Disposition" 字段,客户端获取不到?</em> 请参考查阅 [Access-Control-Expose-Headers](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers) 。
39
21
  *
40
- * @static
41
- * @alias module:Other.download
22
+ * @alias module:Browser.download
42
23
  * @since 4.16.0
43
24
  * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers | Access-Control-Expose-Headers}
44
25
  * @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展 | MIME}
45
26
  * @see {@link https://9ykc9s.csb.app/ | 在线示例}
46
27
  * @param {string|Blob|ArrayBuffer|TypedArray} data 字符串、blob数据或url地址
47
- * @param {string|DownloadOptions} [options] 文件名称 或 配置项
28
+ * @param {string|Object} [options] 文件名称 或 配置项。
29
+ * @param {string} [options.fileName] 文件名称。
30
+ * @param {string} [options.type] MIME 类型。
31
+ * @param {'url'|'text'} [options.dataType] 手动设置数据类型,主要是为了区分 `url` 和 `text`,默认会根据传入的数据判断类型。<br/>如果你要下载的文本是 `url` ,请设置 `'text'` ;如果你要下载的 url 是绝对/相对路径,请设置 'url' 。
32
+ * @param {Function} [options.transformRequest] 请求前触发,XHR 对象或配置调整。
33
+ * @param {Function} [options.transformResponse] 请求成功后触发,在传递给 then/catch 前,允许修改响应数据。
48
34
  * @returns {Promise<void>}
49
35
  * @example
50
36
  * // 文本
@@ -15,7 +15,7 @@ interface FileReader {
15
15
  * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
16
16
  *
17
17
  * @function
18
- * @alias module:Processor.fileReader
18
+ * @alias module:Browser.fileReader
19
19
  * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader | FileReader}
20
20
  * @since 4.16.0
21
21
  * @param {Blob} blob Blob 或 File 对象
@@ -4,7 +4,6 @@ type NodeAssign = 'spread' | 'self';
4
4
  *
5
5
  * 如果某节点被过滤掉,它的子节点也一并抛弃。
6
6
  *
7
- * @static
8
7
  * @alias module:Tree.filterTree
9
8
  * @since 4.15.0
10
9
  * @param {Object[]} tree 树结构数据
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 查找树结构数据节点
3
3
  *
4
- * @static
5
4
  * @alias module:Tree.findTreeNode
6
5
  * @since 4.14.0
7
6
  * @param {Object[]} tree 树结构数据
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 查找树结构数据多个节点
3
3
  *
4
- * @static
5
4
  * @alias module:Tree.findTreeNodes
6
5
  * @since 4.15.0
7
6
  * @param {Object[]} tree 树结构数据
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 查找包含当前节点的所有父级节点
3
3
  *
4
- * @static
5
4
  * @alias module:Tree.findTreeSelect
6
5
  * @since 4.14.0
7
6
  * @param {Object[]} tree 树结构数据
@@ -5,7 +5,6 @@ type Options = {
5
5
  /**
6
6
  * 格式化银行卡号
7
7
  *
8
- * @static
9
8
  * @alias module:Processor.formatBankCard
10
9
  * @since 1.1.0
11
10
  * @param {string} bankCardNo 要处理的字符串
@@ -4,7 +4,6 @@ type Options = {
4
4
  /**
5
5
  * 格式化手机号码
6
6
  *
7
- * @static
8
7
  * @alias module:Processor.formatMobile
9
8
  * @since 4.5.0
10
9
  * @param {string} mobileNo 手机号码
@@ -8,7 +8,6 @@ type Options = {
8
8
  /**
9
9
  * 格式化金额
10
10
  *
11
- * @static
12
11
  * @alias module:Processor.formatMoney
13
12
  * @since 1.1.0
14
13
  * @param {string | number} num 需转换金额 (最大:9007199254740991 最小: -9007199254740991)
package/types/gcd.d.ts CHANGED
@@ -9,7 +9,6 @@
9
9
  * 4. 如果参数为负数,将转为绝对值的正数。
10
10
  * 5. 如果参数包含小数点,将转为四舍五入的整数。
11
11
  *
12
- * @static
13
12
  * @alias module:Math.gcd
14
13
  * @since 4.20.0
15
14
  * @see {@link https://baike.baidu.com/item/最大公约数 | 最大公约数}
@@ -2,8 +2,7 @@ import ajax from './ajax';
2
2
  /**
3
3
  * 获取文件 Blob 。
4
4
  *
5
- * @static
6
- * @alias module:Other.getFileBlob
5
+ * @alias module:Browser.getFileBlob
7
6
  * @since 4.21.0
8
7
  * @param {string | Blob} file 文件地址或对象。
9
8
  * @param {AjaxOptions} [ajaxOptions] ajax 请求配置项,当传入的图片为字符串时才会触发请求。
@@ -1,9 +1,7 @@
1
1
  import { UploadFile } from './utils/file.util';
2
2
  /**
3
- * 获取文件类型。
4
- *
5
- * @static
6
- * @alias module:Other.getFileType
3
+ * @summary 获取文件类型。
4
+ * @alias module:Browser.getFileType
7
5
  * @since 5.1.0
8
6
  * @requires Other.checkFileType
9
7
  * @param {File} file 文件对象。支持 antd `UploadFile` 对象。
@@ -16,6 +14,17 @@ import { UploadFile } from './utils/file.util';
16
14
  * getFileType(pdf); // 'pdf'
17
15
  * getFileType(jpeg); // 'image'
18
16
  *
17
+ * @description 内置文件类型和文件类型说明符
18
+ *
19
+ * | 类型 | 说明符 |
20
+ * |---|---|
21
+ * | `image` | `image/*,.jpeg,.jpg,.gif,.bmp,.png,.webp,.svg,.apng,.avif,.ico,.tif,.tiff` |
22
+ * | `audio` | `audio/*,.mp3,.wav,.aac,.flac` |
23
+ * | `video` | `video/*,.mp4,.webm,.ogg,.mov` |
24
+ * | `pdf` | `application/pdf,.pdf` |
25
+ * | `word` | `application/vnd.openxmlformats-officedocument.wordprocessingml.document,.doc,.docx` |
26
+ * | `excel` | `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,.xls,.xlsx` |
27
+ *
19
28
  */
20
29
  declare function getFileType(file: File | UploadFile): "image" | "audio" | "video" | "pdf" | "word" | "excel" | undefined;
21
30
  export default getFileType;
@@ -15,16 +15,25 @@ import loadImageWithBlob from './loadImageWithBlob';
15
15
  *
16
16
  * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
17
17
  *
18
- * @static
19
- * @alias module:Other.getImageInfo
18
+ * @alias module:Browser.getImageInfo
20
19
  * @since 4.20.0
21
- * @param {string | Blob} img 图片地址或 blob 对象
20
+ * @param {string | Blob} img 图片地址或 blob 对象。
22
21
  * @param {AjaxOptions} [ajaxOptions] ajax 请求配置项,当传入的图片为字符串时才会触发请求。
23
- * @returns {Promise<ImageInfo>} 图片信息
22
+ * @returns {Promise<ImageInfo>} 图片信息。
24
23
  * @example
25
24
  *
26
25
  * getImageInfo(file).then(imageInfo=>{
27
- * // do something
26
+ * console.log(imageInfo);
27
+ * // {
28
+ * // width: 100,
29
+ * // height: 100,
30
+ * // contrast: '1:1',
31
+ * // measure: '100 × 100 px',
32
+ * // size: '11 B',
33
+ * // bytes: 11,
34
+ * // image: HTMLImageElement {},
35
+ * // blob: Blob {}
36
+ * // }
28
37
  * });
29
38
  *
30
39
  * getImageInfo('https://dummyimage.com/200x300').then(imageInfo=>{
@@ -1,9 +1,7 @@
1
1
  /**
2
- * 获取常用的 MIME 类型。
2
+ * @summary 获取常用的 MIME 类型。通过文件名后缀查找对应的 MIME 类型。
3
3
  *
4
- * 通过文件名后缀查找对于的 MIME 类型。
5
- *
6
- * @alias module:Other.getMimeType
4
+ * @alias module:Browser.getMimeType
7
5
  * @since 5.2.0
8
6
  * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/MIME_types | MIME 类型(IANA 媒体类型)}
9
7
  * @see {@link https://www.iana.org/assignments/media-types/media-types.xhtml | Media Types}
@@ -20,6 +18,45 @@
20
18
  *
21
19
  * // 不常用或未知类型
22
20
  * getMimeTye('xxx.ci'); // undefined
21
+ *
22
+ * // 非法文件名
23
+ * getMimeType('.zip'); // undefined
24
+ *
25
+ * @description 内置常用的 MIME 类型和文件名后缀映射
26
+ *
27
+ * | MIME 类型 | 文件名后缀 |
28
+ * |---|---|
29
+ * | `text/plain` | `txt` |
30
+ * | `text/css` | `css` |
31
+ * | `text/html` | `htm` `html` |
32
+ * | `text/javascript` | `js` `mjs` |
33
+ * | `text/csv` | `csv` |
34
+ * | `text/markdown` | `md` `markdown` |
35
+ * | `image/gif` | `gif` |
36
+ * | `image/jpeg` | `jpg` `jpeg` `jfif` `pjpeg` `pjp` |
37
+ * | `image/png` | `png` |
38
+ * | `image/svg+xml` | `svg` |
39
+ * | `image/webp` | `webp` |
40
+ * | `image/apng` | `apng` |
41
+ * | `image/avif` | `avif` |
42
+ * | `image/bmp` | `bmp` |
43
+ * | `image/x-icon` | `ico` `cur` |
44
+ * | `image/tiff` | `tif` `tiff` |
45
+ * | `application/xml` | `xml` |
46
+ * | `application/zip` | `zip` |
47
+ * | `application/pdf` | `pdf` |
48
+ * | `application/json` | `json` |
49
+ * | `application/yaml` | `yaml` `yml` |
50
+ * | `application/vnd.openxmlformats-officedocument.wordprocessingml.document` | `doc` `docx` |
51
+ * | `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet` | `xls` `xlsx` |
52
+ * | `audio/mp3` | `mp3` |
53
+ * | `audio/wav` | `wav` |
54
+ * | `audio/aac` | `aac` |
55
+ * | `audio/flac` | `flac` |
56
+ * | `video/mp4` | `mp4` |
57
+ * | `video/ogg` | `ogg` |
58
+ * | `video/webm` | `webm` |
59
+ * | `video/quicktime` | `mov` |
23
60
  */
24
61
  declare function getMimeType(fileName: string): string | undefined;
25
62
  export default getMimeType;