util-helpers 5.1.3 → 5.2.1

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 (51) hide show
  1. package/README.md +1 -0
  2. package/dist/util-helpers.js +683 -74
  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/getFileType.js +3 -3
  8. package/esm/getMimeType.js +43 -0
  9. package/esm/index.js +1 -0
  10. package/esm/utils/file.util.js +1 -1
  11. package/lib/VERSION.js +1 -1
  12. package/lib/getFileType.js +3 -3
  13. package/lib/getMimeType.js +45 -0
  14. package/lib/index.js +2 -0
  15. package/lib/utils/file.util.js +1 -1
  16. package/package.json +18 -18
  17. package/types/AsyncMemo.d.ts +2 -2
  18. package/types/BlobUrl.d.ts +41 -0
  19. package/types/VERSION.d.ts +1 -2
  20. package/types/ajax.d.ts +21 -4
  21. package/types/calculateCursorPosition.d.ts +2 -2
  22. package/types/checkFileType.d.ts +2 -2
  23. package/types/compressImage.d.ts +1 -1
  24. package/types/dataURLToBlob.d.ts +1 -1
  25. package/types/download.d.ts +9 -22
  26. package/types/fileReader.d.ts +1 -1
  27. package/types/gcd.d.ts +1 -1
  28. package/types/getFileType.d.ts +12 -1
  29. package/types/getImageInfo.d.ts +13 -3
  30. package/types/getMimeType.d.ts +62 -0
  31. package/types/index.d.ts +3 -2
  32. package/types/isBankCard.d.ts +1 -1
  33. package/types/isBusinessLicense.d.ts +1 -1
  34. package/types/isChinese.d.ts +3 -3
  35. package/types/isHMCard.d.ts +1 -1
  36. package/types/isIdCard.d.ts +2 -2
  37. package/types/isPassport.d.ts +1 -1
  38. package/types/isPassword.d.ts +1 -1
  39. package/types/isSocialCreditCode.d.ts +1 -1
  40. package/types/isSwiftCode.d.ts +1 -1
  41. package/types/isTWCard.d.ts +1 -1
  42. package/types/isUrl.d.ts +1 -1
  43. package/types/isVehicle.d.ts +1 -1
  44. package/types/lcm.d.ts +1 -1
  45. package/types/loadImageWithBlob.d.ts +2 -1
  46. package/types/numberToChinese.d.ts +1 -1
  47. package/types/parseIdCard.d.ts +1 -1
  48. package/types/safeDate.d.ts +1 -1
  49. package/types/setDataURLPrefix.d.ts +2 -2
  50. package/types/utils/file.util.d.ts +0 -1
  51. package/types/validatePassword.d.ts +1 -1
package/esm/VERSION.js CHANGED
@@ -1,4 +1,4 @@
1
- var VERSION = "5.1.3";
1
+ var VERSION = "5.2.1";
2
2
  var VERSION$1 = VERSION;
3
3
 
4
4
  export { VERSION$1 as default };
@@ -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',
7
- audio: 'audio/*,.mp3,.wav',
8
- video: 'video/*,.mp4,.webm,.ogg,.ogv,.ogm',
6
+ image: 'image/*,.jpeg,.jpg,.gif,.bmp,.png,.webp,.svg,.apng,.avif,.ico,.tif,.tiff',
7
+ audio: 'audio/*,.mp3,.wav,.aac,.flac',
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'
@@ -0,0 +1,43 @@
1
+ import { isString, nth } from 'ut2';
2
+ import { nativeUndefined } from './utils/native.js';
3
+
4
+ var mimeTypes = [
5
+ ['text/plain', ['txt']],
6
+ ['text/css', ['css']],
7
+ ['text/html', ['htm', 'html']],
8
+ ['text/javascript', ['js', 'mjs']],
9
+ ['text/csv', ['csv']],
10
+ ['text/markdown', ['md', 'markdown']],
11
+ ['image/gif', ['gif']],
12
+ ['image/jpeg', ['jpg', 'jpeg', 'jfif', 'pjpeg', 'pjp']],
13
+ ['image/png', ['png']],
14
+ ['image/svg+xml', ['svg']],
15
+ ['image/webp', ['webp']],
16
+ ['image/apng', ['apng']],
17
+ ['image/avif', ['avif']],
18
+ ['image/bmp', ['bmp']],
19
+ ['image/x-icon', ['ico', 'cur']],
20
+ ['image/tiff', ['tif', 'tiff']],
21
+ ['application/xml', ['xml']],
22
+ ['application/zip', ['zip']],
23
+ ['application/pdf', ['pdf']],
24
+ ['application/json', ['json']],
25
+ ['application/yaml', ['yaml', 'yml']],
26
+ ['application/vnd.openxmlformats-officedocument.wordprocessingml.document', ['doc', 'docx']],
27
+ ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ['xls', 'xlsx']],
28
+ ['audio/mp3', ['mp3']],
29
+ ['audio/wav', ['wav']],
30
+ ['audio/aac', ['aac']],
31
+ ['audio/flac', ['flac']],
32
+ ['video/mp4', ['mp4']],
33
+ ['video/ogg', ['ogg']],
34
+ ['video/webm', ['webm']],
35
+ ['video/quicktime', ['mov']]
36
+ ];
37
+ function getMimeType(fileName) {
38
+ var _a;
39
+ var ext = isString(fileName) && fileName.indexOf('.') > 0 ? nth(fileName.split('.'), -1) : '';
40
+ return ext ? (_a = mimeTypes.find(function (item) { return item[1].includes(ext); })) === null || _a === void 0 ? void 0 : _a[0] : nativeUndefined;
41
+ }
42
+
43
+ export { getMimeType as default };
package/esm/index.js CHANGED
@@ -48,6 +48,7 @@ export { default as download } from './download.js';
48
48
  export { default as getFileBlob } from './getFileBlob.js';
49
49
  export { default as getFileType } from './getFileType.js';
50
50
  export { default as getImageInfo } from './getImageInfo.js';
51
+ export { default as getMimeType } from './getMimeType.js';
51
52
  export { default as loadImage } from './loadImage.js';
52
53
  export { default as loadImageWithBlob } from './loadImageWithBlob.js';
53
54
  export { default as loadScript } from './loadScript.js';
@@ -4,7 +4,7 @@ function testExt(name, ext) {
4
4
  return !!name && name.slice(-ext.length) === ext;
5
5
  }
6
6
  function isUploadFile(fileObj) {
7
- if (isObjectLike(fileObj) && isString(fileObj.uid) && isString(fileObj.name)) {
7
+ if (isObjectLike(fileObj) && isString(fileObj.name)) {
8
8
  return true;
9
9
  }
10
10
  return false;
package/lib/VERSION.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var VERSION = "5.1.3";
3
+ var VERSION = "5.2.1";
4
4
  var VERSION$1 = VERSION;
5
5
 
6
6
  module.exports = VERSION$1;
@@ -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',
9
- audio: 'audio/*,.mp3,.wav',
10
- video: 'video/*,.mp4,.webm,.ogg,.ogv,.ogm',
8
+ image: 'image/*,.jpeg,.jpg,.gif,.bmp,.png,.webp,.svg,.apng,.avif,.ico,.tif,.tiff',
9
+ audio: 'audio/*,.mp3,.wav,.aac,.flac',
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'
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ var ut2 = require('ut2');
4
+ var native = require('./utils/native.js');
5
+
6
+ var mimeTypes = [
7
+ ['text/plain', ['txt']],
8
+ ['text/css', ['css']],
9
+ ['text/html', ['htm', 'html']],
10
+ ['text/javascript', ['js', 'mjs']],
11
+ ['text/csv', ['csv']],
12
+ ['text/markdown', ['md', 'markdown']],
13
+ ['image/gif', ['gif']],
14
+ ['image/jpeg', ['jpg', 'jpeg', 'jfif', 'pjpeg', 'pjp']],
15
+ ['image/png', ['png']],
16
+ ['image/svg+xml', ['svg']],
17
+ ['image/webp', ['webp']],
18
+ ['image/apng', ['apng']],
19
+ ['image/avif', ['avif']],
20
+ ['image/bmp', ['bmp']],
21
+ ['image/x-icon', ['ico', 'cur']],
22
+ ['image/tiff', ['tif', 'tiff']],
23
+ ['application/xml', ['xml']],
24
+ ['application/zip', ['zip']],
25
+ ['application/pdf', ['pdf']],
26
+ ['application/json', ['json']],
27
+ ['application/yaml', ['yaml', 'yml']],
28
+ ['application/vnd.openxmlformats-officedocument.wordprocessingml.document', ['doc', 'docx']],
29
+ ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', ['xls', 'xlsx']],
30
+ ['audio/mp3', ['mp3']],
31
+ ['audio/wav', ['wav']],
32
+ ['audio/aac', ['aac']],
33
+ ['audio/flac', ['flac']],
34
+ ['video/mp4', ['mp4']],
35
+ ['video/ogg', ['ogg']],
36
+ ['video/webm', ['webm']],
37
+ ['video/quicktime', ['mov']]
38
+ ];
39
+ function getMimeType(fileName) {
40
+ var _a;
41
+ var ext = ut2.isString(fileName) && fileName.indexOf('.') > 0 ? ut2.nth(fileName.split('.'), -1) : '';
42
+ return ext ? (_a = mimeTypes.find(function (item) { return item[1].includes(ext); })) === null || _a === void 0 ? void 0 : _a[0] : native.nativeUndefined;
43
+ }
44
+
45
+ module.exports = getMimeType;
package/lib/index.js CHANGED
@@ -50,6 +50,7 @@ var download = require('./download.js');
50
50
  var getFileBlob = require('./getFileBlob.js');
51
51
  var getFileType = require('./getFileType.js');
52
52
  var getImageInfo = require('./getImageInfo.js');
53
+ var getMimeType = require('./getMimeType.js');
53
54
  var loadImage = require('./loadImage.js');
54
55
  var loadImageWithBlob = require('./loadImageWithBlob.js');
55
56
  var loadScript = require('./loadScript.js');
@@ -118,6 +119,7 @@ exports.download = download;
118
119
  exports.getFileBlob = getFileBlob;
119
120
  exports.getFileType = getFileType;
120
121
  exports.getImageInfo = getImageInfo;
122
+ exports.getMimeType = getMimeType;
121
123
  exports.loadImage = loadImage;
122
124
  exports.loadImageWithBlob = loadImageWithBlob;
123
125
  exports.loadScript = loadScript;
@@ -6,7 +6,7 @@ function testExt(name, ext) {
6
6
  return !!name && name.slice(-ext.length) === ext;
7
7
  }
8
8
  function isUploadFile(fileObj) {
9
- if (ut2.isObjectLike(fileObj) && ut2.isString(fileObj.uid) && ut2.isString(fileObj.name)) {
9
+ if (ut2.isObjectLike(fileObj) && ut2.isString(fileObj.name)) {
10
10
  return true;
11
11
  }
12
12
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "util-helpers",
3
- "version": "5.1.3",
3
+ "version": "5.2.1",
4
4
  "description": "一个基于业务场景的工具方法库",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -51,36 +51,36 @@
51
51
  },
52
52
  "homepage": "https://doly-dev.github.io/util-helpers/index.html",
53
53
  "devDependencies": {
54
- "@babel/core": "^7.24.7",
55
- "@babel/preset-env": "^7.24.7",
56
- "@babel/preset-typescript": "^7.24.7",
54
+ "@babel/core": "^7.25.8",
55
+ "@babel/preset-env": "^7.25.8",
56
+ "@babel/preset-typescript": "^7.25.7",
57
57
  "@commitlint/cli": "^17.8.1",
58
58
  "@commitlint/config-conventional": "^17.8.1",
59
59
  "@commitlint/cz-commitlint": "^17.8.1",
60
60
  "@rollup/plugin-commonjs": "^25.0.8",
61
- "@rollup/plugin-node-resolve": "^15.2.3",
61
+ "@rollup/plugin-node-resolve": "^15.3.0",
62
62
  "@rollup/plugin-replace": "^5.0.7",
63
63
  "@rollup/plugin-terser": "^0.4.4",
64
64
  "@rollup/plugin-typescript": "^11.1.6",
65
- "@types/jest": "^29.5.12",
66
- "@typescript-eslint/eslint-plugin": "^7.16.0",
67
- "@typescript-eslint/parser": "^7.16.0",
65
+ "@types/jest": "^29.5.13",
66
+ "@typescript-eslint/eslint-plugin": "^7.18.0",
67
+ "@typescript-eslint/parser": "^7.18.0",
68
68
  "babel-jest": "^29.7.0",
69
69
  "babel-plugin-minify-replace": "^0.5.0",
70
- "commitizen": "^4.3.0",
70
+ "commitizen": "^4.3.1",
71
71
  "cross-env": "^7.0.3",
72
72
  "docdash": "^2.0.2",
73
- "eslint": "^8.57.0",
74
- "husky": "^9.0.11",
73
+ "eslint": "^8.57.1",
74
+ "husky": "^9.1.6",
75
75
  "inquirer": "^8.2.6",
76
76
  "jest": "^29.7.0",
77
77
  "jest-canvas-mock": "^2.5.2",
78
78
  "jest-environment-jsdom": "^29.7.0",
79
- "jsdoc": "^4.0.3",
79
+ "jsdoc": "^4.0.4",
80
80
  "lint-staged": "^13.3.0",
81
- "prettier": "^3.3.2",
82
- "rollup": "^4.18.1",
83
- "typescript": "^5.5.3"
81
+ "prettier": "^3.3.3",
82
+ "rollup": "^4.24.0",
83
+ "typescript": "^5.6.3"
84
84
  },
85
85
  "lint-staged": {
86
86
  "**/*.ts": "eslint",
@@ -92,9 +92,9 @@
92
92
  }
93
93
  },
94
94
  "dependencies": {
95
- "cache2": "^3.0.0",
96
- "tslib": "^2.6.3",
97
- "ut2": "^1.11.0"
95
+ "cache2": "^3.1.1",
96
+ "tslib": "^2.8.0",
97
+ "ut2": "^1.13.0"
98
98
  },
99
99
  "publishConfig": {
100
100
  "registry": "https://registry.npmjs.org/"
@@ -8,7 +8,7 @@ import { Cache, CacheOptions } from 'cache2';
8
8
  * 3. 每个实例都有独立的缓存空间。相互之间隔离,缓存灵活配置,更多配置请查阅 [`cache2`](https://www.npmjs.com/package/cache2)。
9
9
  *
10
10
  * @class
11
- * @see {@link https://www.npmjs.com/package/cache2 cache2}
11
+ * @see {@link https://www.npmjs.com/package/cache2 | cache2}
12
12
  * @param {Object} [options] 缓存配置项,更多配置项可参考 [`cache2`](https://www.npmjs.com/package/cache2)
13
13
  * @param {number} [options.max] 最大缓存数量
14
14
  * @param {'replaced' | 'limited'} [options.maxStrategy] 缓存策略
@@ -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>);
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Blob 对象 URL 记录。
3
+ *
4
+ * 便于管理项目中上传文件通过 `URL.createObjectURL` 生成的对象URL。
5
+ *
6
+ * 特点:
7
+ * 1. 避免重复创建,相同的 `Blob` 对象只会生成一个 URL 字符串
8
+ * 2. 当清除缓存时,自动释放内存
9
+ *
10
+ * @class
11
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/URL/createObjectURL_static | URL:createObjectURL()}
12
+ * @example
13
+ * const blobUrl = new BlobUrl();
14
+ *
15
+ */
16
+ declare class BlobUrl {
17
+ protected cache: Map<Blob, string>;
18
+ constructor();
19
+ /**
20
+ * 同 `URL.createObjectURL` 方法,创建一个对象 URL 字符串。
21
+ *
22
+ * 生成时内部会记录一个缓存,相同的 `Blob` 对象最多只会产生一个 URL 字符串。
23
+ *
24
+ * @param {Blob} obj 用于创建 URL 的 File、Blob 对象。
25
+ * @returns 一个包含对象 URL 的字符串,可用于引用指定源 object 的内容。
26
+ */
27
+ createObjectURL(obj: Blob): string | undefined;
28
+ /**
29
+ * 同 `URL.revokeObjectURL` 方法,释放对象 URL 。
30
+ *
31
+ * @param {string} url 通过调用 `createObjectURL()` 方法创建的对象 URL 的字符串。
32
+ */
33
+ revokeObjectURL(url: string): void;
34
+ /**
35
+ * 清理缓存。
36
+ *
37
+ * 迭代调用 `URL.revokeObjectURL` 来释放内存。
38
+ */
39
+ clear(): void;
40
+ }
41
+ export default BlobUrl;
@@ -1,6 +1,5 @@
1
1
  /**
2
- * util-helpers 版本号
3
- *
2
+ * @summary 版本号
4
3
  * @static
5
4
  * @since 4.18.0
6
5
  */
package/types/ajax.d.ts CHANGED
@@ -19,7 +19,7 @@ type AjaxOptions = {
19
19
  onLoadEnd?: XMLHttpRequestListener;
20
20
  };
21
21
  /**
22
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest XMLHttpRequest}
22
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest | XMLHttpRequest}
23
23
  * @typedef {Object} AjaxOptions ajax 配置项
24
24
  * @property {string} [method="get"] 创建请求时使用的方法
25
25
  * @property {boolean} [async=true] 是否异步执行操作
@@ -47,10 +47,27 @@ type AjaxOptions = {
47
47
  * @static
48
48
  * @alias module:Other.ajax
49
49
  * @since 4.16.0
50
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest XMLHttpRequest}
50
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest | XMLHttpRequest}
51
51
  * @param {string} url 地址
52
- * @param {AjaxOptions} [options] 配置项
53
- * @returns {Promise<object>} XHR 事件对象
52
+ * @param {Object} [options] 配置项
53
+ * @param {string} [options.method="get"] 创建请求时使用的方法。默认 `'get'`。
54
+ * @param {boolean} [options.async=true] 是否异步执行操作。默认 `true`。
55
+ * @param {string|null} [options.user=null] 用户名,用于认证用途。默认 `null`。
56
+ * @param {string|null} [options.password=null] 密码,用于认证用途。默认 `null`。
57
+ * @param {Object} [options.headers] 自定义请求头。
58
+ * @param {string} [options.responseType] 响应类型。
59
+ * @param {number} [options.timeout] 请求超时的毫秒数。
60
+ * @param {boolean} [options.withCredentials=false] 跨域请求时是否需要使用凭证。默认 `false`。
61
+ * @param {*} [options.data=null] 请求体被发送的数据。默认 `null`。
62
+ * @param {function} [options.onReadyStateChange] 当 readyState 属性发生变化时触发。
63
+ * @param {function} [options.onLoadStart] 接收到响应数据时触发。
64
+ * @param {function} [options.onProgress] 请求接收到更多数据时,周期性地触发。
65
+ * @param {function} [options.onAbort] 当 request 被停止时触发,例如当程序调用 XMLHttpRequest.abort() 时。
66
+ * @param {function} [options.onTimeout] 在预设时间内没有接收到响应时触发。
67
+ * @param {function} [options.onError] 当 request 遭遇错误时触发。
68
+ * @param {function} [options.onLoad] 请求成功完成时触发。
69
+ * @param {function} [options.onLoadEnd] 请求结束时触发,无论请求成功 (load) 还是失败 (abort 或 error)。
70
+ * @returns {Promise<object>} XHR 事件对象。
54
71
  * @example
55
72
  * ajax('/somefile').then(res=>{
56
73
  * // do something
@@ -9,8 +9,8 @@ type CalculateCursorPositionOptions = {
9
9
  * @static
10
10
  * @alias module:Other.calculateCursorPosition
11
11
  * @since 4.6.0
12
- * @see {@link https://2950v9.csb.app/ h5示例}
13
- * @see {@link https://33ccy9.csb.app/ react示例}
12
+ * @see {@link https://2950v9.csb.app/ | h5示例}
13
+ * @see {@link https://33ccy9.csb.app/ | react示例}
14
14
  * @param {number} prevPos 赋值前的光标位置,onChange/onInput的光标位置 e.target.selectionEnd
15
15
  * @param {string} prevCtrlValue 上一个格式化后的值
16
16
  * @param {string} rawValue 当前输入原值
@@ -5,8 +5,8 @@ import { UploadFile } from './utils/file.util';
5
5
  * @static
6
6
  * @alias module:Other.checkFileType
7
7
  * @since 5.1.0
8
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/input/file#唯一文件类型说明符 唯一文件类型说明符}
9
- * @see {@link https://www.iana.org/assignments/media-types/media-types.xhtml Media Types}
8
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/input/file#唯一文件类型说明符 | 唯一文件类型说明符}
9
+ * @see {@link https://www.iana.org/assignments/media-types/media-types.xhtml | Media Types}
10
10
  * @param {File} file 文件对象。支持 antd `UploadFile` 对象。
11
11
  * @param {string} [accept] 文件类型说明符。
12
12
  * @returns {boolean} 如果 `file` 符合 `accept` 返回 `true`, 否则返回 `false`。
@@ -37,7 +37,7 @@ interface CompressImage {
37
37
  * @function
38
38
  * @alias module:Other.compressImage
39
39
  * @since 4.20.0
40
- * @see {@link https://sytpwg.csb.app/ 在线示例}
40
+ * @see {@link https://sytpwg.csb.app/ | 在线示例}
41
41
  * @param {string | Blob} img 图片地址或 blob 对象
42
42
  * @param {Object} [options] 配置项
43
43
  * @param {number} [options.width] 自定义图片宽度,默认图片自身宽度
@@ -4,7 +4,7 @@
4
4
  * @static
5
5
  * @alias module:Processor.dataURLToBlob
6
6
  * @since 4.1.0
7
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64 Base64}
7
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64 | Base64}
8
8
  * @param {string} data data: 协议的URL
9
9
  * @returns {Blob} Blob 对象
10
10
  * @example
@@ -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
  *
@@ -40,11 +22,16 @@ type DownloadOptions = {
40
22
  * @static
41
23
  * @alias module:Other.download
42
24
  * @since 4.16.0
43
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers Access-Control-Expose-Headers}
44
- * @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展 MIME}
45
- * @see {@link https://9ykc9s.csb.app/ 在线示例}
25
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers | Access-Control-Expose-Headers}
26
+ * @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展 | MIME}
27
+ * @see {@link https://9ykc9s.csb.app/ | 在线示例}
46
28
  * @param {string|Blob|ArrayBuffer|TypedArray} data 字符串、blob数据或url地址
47
- * @param {string|DownloadOptions} [options] 文件名称 或 配置项
29
+ * @param {string|Object} [options] 文件名称 或 配置项。
30
+ * @param {string} [options.fileName] 文件名称。
31
+ * @param {string} [options.type] MIME 类型。
32
+ * @param {'url'|'text'} [options.dataType] 手动设置数据类型,主要是为了区分 `url` 和 `text`,默认会根据传入的数据判断类型。<br/>如果你要下载的文本是 `url` ,请设置 `'text'` ;如果你要下载的 url 是绝对/相对路径,请设置 'url' 。
33
+ * @param {Function} [options.transformRequest] 请求前触发,XHR 对象或配置调整。
34
+ * @param {Function} [options.transformResponse] 请求成功后触发,在传递给 then/catch 前,允许修改响应数据。
48
35
  * @returns {Promise<void>}
49
36
  * @example
50
37
  * // 文本
@@ -16,7 +16,7 @@ interface FileReader {
16
16
  *
17
17
  * @function
18
18
  * @alias module:Processor.fileReader
19
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader FileReader}
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 对象
22
22
  * @param {'arrayBuffer'|'binaryString'|'dataURL'|'text'} [type='dataURL'] 读取类型,默认`dataURL`。可选 `arrayBuffer` `binaryString` `dataURL` `text` 。
package/types/gcd.d.ts CHANGED
@@ -12,7 +12,7 @@
12
12
  * @static
13
13
  * @alias module:Math.gcd
14
14
  * @since 4.20.0
15
- * @see {@link https://baike.baidu.com/item/最大公约数 最大公约数}
15
+ * @see {@link https://baike.baidu.com/item/最大公约数 | 最大公约数}
16
16
  * @param {...(number|string)} nums 两个或多个整数。
17
17
  * @returns {number} 最大公约数。
18
18
  * @example
@@ -1,6 +1,6 @@
1
1
  import { UploadFile } from './utils/file.util';
2
2
  /**
3
- * 获取文件类型
3
+ * @summary 获取文件类型。
4
4
  *
5
5
  * @static
6
6
  * @alias module:Other.getFileType
@@ -16,6 +16,17 @@ import { UploadFile } from './utils/file.util';
16
16
  * getFileType(pdf); // 'pdf'
17
17
  * getFileType(jpeg); // 'image'
18
18
  *
19
+ * @description 内置文件类型和文件类型说明符
20
+ *
21
+ * | 类型 | 说明符 |
22
+ * |---|---|
23
+ * | `image` | `image/*,.jpeg,.jpg,.gif,.bmp,.png,.webp,.svg,.apng,.avif,.ico,.tif,.tiff` |
24
+ * | `audio` | `audio/*,.mp3,.wav,.aac,.flac` |
25
+ * | `video` | `video/*,.mp4,.webm,.ogg,.mov` |
26
+ * | `pdf` | `application/pdf,.pdf` |
27
+ * | `word` | `application/vnd.openxmlformats-officedocument.wordprocessingml.document,.doc,.docx` |
28
+ * | `excel` | `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,.xls,.xlsx` |
29
+ *
19
30
  */
20
31
  declare function getFileType(file: File | UploadFile): "image" | "audio" | "video" | "pdf" | "word" | "excel" | undefined;
21
32
  export default getFileType;
@@ -18,13 +18,23 @@ import loadImageWithBlob from './loadImageWithBlob';
18
18
  * @static
19
19
  * @alias module:Other.getImageInfo
20
20
  * @since 4.20.0
21
- * @param {string | Blob} img 图片地址或 blob 对象
21
+ * @param {string | Blob} img 图片地址或 blob 对象。
22
22
  * @param {AjaxOptions} [ajaxOptions] ajax 请求配置项,当传入的图片为字符串时才会触发请求。
23
- * @returns {Promise<ImageInfo>} 图片信息
23
+ * @returns {Promise<ImageInfo>} 图片信息。
24
24
  * @example
25
25
  *
26
26
  * getImageInfo(file).then(imageInfo=>{
27
- * // do something
27
+ * console.log(imageInfo);
28
+ * // {
29
+ * // width: 100,
30
+ * // height: 100,
31
+ * // contrast: '1:1',
32
+ * // measure: '100 × 100 px',
33
+ * // size: '11 B',
34
+ * // bytes: 11,
35
+ * // image: HTMLImageElement {},
36
+ * // blob: Blob {}
37
+ * // }
28
38
  * });
29
39
  *
30
40
  * getImageInfo('https://dummyimage.com/200x300').then(imageInfo=>{
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @summary 获取常用的 MIME 类型。通过文件名后缀查找对应的 MIME 类型。
3
+ *
4
+ * @alias module:Other.getMimeType
5
+ * @since 5.2.0
6
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/MIME_types | MIME 类型(IANA 媒体类型)}
7
+ * @see {@link https://www.iana.org/assignments/media-types/media-types.xhtml | Media Types}
8
+ * @param {string} fileName 文件名。
9
+ * @returns 如果找到,返回 MIME 类型字符串,否则返回 `undefined`。
10
+ * @example
11
+ * getMimeType('xxx.png'); // 'image/png'
12
+ * getMimeType('xxx.jpg'); // 'image/jpeg'
13
+ * getMimeType('xxx.mp3'); // 'audio/mp3'
14
+ * getMimeType('xxx.mp4'); // 'video/mp4'
15
+ * getMimeType('xxx.pdf'); // 'application/pdf'
16
+ * getMimeType('xxx.zip'); // 'application/zip'
17
+ * getMimeType('xxx.doc'); // 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
18
+ *
19
+ * // 不常用或未知类型
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` |
60
+ */
61
+ declare function getMimeType(fileName: string): string | undefined;
62
+ export default getMimeType;
package/types/index.d.ts CHANGED
@@ -50,8 +50,8 @@ export { default as transformObjectValue } from './transformObjectValue';
50
50
  *
51
51
  * @module Math
52
52
  * @since 3.1.0
53
- * @see {@link https://github.com/camsong/blog/issues/9 JavaScript 浮点数陷阱及解法}
54
- * @see {@link https://2zbuy.csb.app/ JS浮点数计算测试}
53
+ * @see {@link https://github.com/camsong/blog/issues/9 | JavaScript 浮点数陷阱及解法}
54
+ * @see {@link https://2zbuy.csb.app/ | JS浮点数计算测试}
55
55
  * @example
56
56
  * // 从 4.12.0 版本开始,规范了有效数值。(注意:4.12.3 对有效数值重新定义)
57
57
  * // 有效数值即能通过 Number(value) 转为数字,且不能为 NaN 。
@@ -105,6 +105,7 @@ export { default as download } from './download';
105
105
  export { default as getFileBlob } from './getFileBlob';
106
106
  export { default as getFileType } from './getFileType';
107
107
  export { default as getImageInfo } from './getImageInfo';
108
+ export { default as getMimeType } from './getMimeType';
108
109
  export { default as loadImage } from './loadImage';
109
110
  export { default as loadImageWithBlob } from './loadImageWithBlob';
110
111
  export { default as loadScript } from './loadScript';
@@ -8,7 +8,7 @@ type Options = {
8
8
  * @static
9
9
  * @alias module:Validator.isBankCard
10
10
  * @since 1.1.0
11
- * @see {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html 常用银行账号位数参考}
11
+ * @see {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html | 常用银行账号位数参考}
12
12
  * @param {*} value 要检测的值
13
13
  * @param {Object} [options] 配置项
14
14
  * @param {boolean} [options.loose=false] 宽松模式,默认`false`。正常模式10-21位数字(个人账户),宽松模式8-30位数字(企业账户)。
@@ -7,7 +7,7 @@ type Options = {
7
7
  * @static
8
8
  * @alias module:Validator.isBusinessLicense
9
9
  * @since 3.5.0
10
- * @see {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html GS15—2006 工商行政管理市场主体注册号编制规则}
10
+ * @see {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html | GS15—2006 工商行政管理市场主体注册号编制规则}
11
11
  * @param {*} value 要检测的值
12
12
  * @param {Object} [options] 配置项
13
13
  * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,默认`true`。如果为false,不校验校验位。