util-helpers 5.1.2 → 5.2.0

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 (62) hide show
  1. package/README.md +1 -0
  2. package/dist/util-helpers.js +681 -72
  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 +2 -2
  8. package/esm/getMimeType.js +43 -0
  9. package/esm/index.js +1 -0
  10. package/lib/VERSION.js +1 -1
  11. package/lib/getFileType.js +2 -2
  12. package/lib/getMimeType.js +45 -0
  13. package/lib/index.js +2 -0
  14. package/package.json +18 -18
  15. package/types/AsyncMemo.d.ts +2 -2
  16. package/types/BlobUrl.d.ts +41 -0
  17. package/types/ajax.d.ts +2 -2
  18. package/types/bytesToSize.d.ts +2 -2
  19. package/types/calculateCursorPosition.d.ts +4 -4
  20. package/types/checkFileType.d.ts +2 -2
  21. package/types/compressImage.d.ts +7 -6
  22. package/types/dataURLToBlob.d.ts +1 -1
  23. package/types/download.d.ts +5 -3
  24. package/types/fileReader.d.ts +2 -2
  25. package/types/filterTree.d.ts +2 -2
  26. package/types/findTreeNode.d.ts +1 -1
  27. package/types/findTreeNodes.d.ts +1 -1
  28. package/types/findTreeSelect.d.ts +1 -1
  29. package/types/formatBankCard.d.ts +2 -2
  30. package/types/formatMobile.d.ts +1 -1
  31. package/types/formatMoney.d.ts +4 -4
  32. package/types/gcd.d.ts +1 -1
  33. package/types/getFileType.d.ts +1 -1
  34. package/types/getMimeType.d.ts +25 -0
  35. package/types/index.d.ts +3 -2
  36. package/types/isBankCard.d.ts +3 -3
  37. package/types/isBusinessLicense.d.ts +2 -2
  38. package/types/isChinese.d.ts +5 -5
  39. package/types/isHMCard.d.ts +1 -1
  40. package/types/isIdCard.d.ts +4 -4
  41. package/types/isPassport.d.ts +1 -1
  42. package/types/isPassword.d.ts +4 -4
  43. package/types/isSocialCreditCode.d.ts +1 -1
  44. package/types/isSwiftCode.d.ts +1 -1
  45. package/types/isTWCard.d.ts +2 -2
  46. package/types/isUrl.d.ts +1 -1
  47. package/types/isValidNumber.d.ts +1 -1
  48. package/types/isVehicle.d.ts +1 -1
  49. package/types/lcm.d.ts +1 -1
  50. package/types/listToTree.d.ts +5 -5
  51. package/types/loadScript.d.ts +3 -3
  52. package/types/numberToChinese.d.ts +8 -8
  53. package/types/padZero.d.ts +1 -1
  54. package/types/parseIdCard.d.ts +1 -1
  55. package/types/randomString.d.ts +2 -2
  56. package/types/replaceChar.d.ts +3 -3
  57. package/types/round.d.ts +1 -1
  58. package/types/safeDate.d.ts +1 -1
  59. package/types/setDataURLPrefix.d.ts +4 -4
  60. package/types/transformFieldNames.d.ts +1 -1
  61. package/types/transformObjectValue.d.ts +1 -1
  62. package/types/validatePassword.d.ts +4 -4
package/esm/VERSION.js CHANGED
@@ -1,4 +1,4 @@
1
- var VERSION = "5.1.2";
1
+ var VERSION = "5.2.0";
2
2
  var VERSION$1 = VERSION;
3
3
 
4
4
  export { VERSION$1 as default };
@@ -4,8 +4,8 @@ import { isUploadFile } from './utils/file.util.js';
4
4
 
5
5
  var config = {
6
6
  image: 'image/*,.jpeg,.jpg,.gif,.bmp,.png,.webp',
7
- audio: 'audio/*,.mp3,.wav',
8
- video: 'video/*,.mp4,.webm,.ogg,.ogv,.ogm',
7
+ audio: 'audio/*,.mp3,.wav,.aac,.flac',
8
+ video: 'video/*,.mp4,.webm,.ogg',
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) ? 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';
package/lib/VERSION.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var VERSION = "5.1.2";
3
+ var VERSION = "5.2.0";
4
4
  var VERSION$1 = VERSION;
5
5
 
6
6
  module.exports = VERSION$1;
@@ -6,8 +6,8 @@ var file_util = require('./utils/file.util.js');
6
6
 
7
7
  var config = {
8
8
  image: 'image/*,.jpeg,.jpg,.gif,.bmp,.png,.webp',
9
- audio: 'audio/*,.mp3,.wav',
10
- video: 'video/*,.mp4,.webm,.ogg,.ogv,.ogm',
9
+ audio: 'audio/*,.mp3,.wav,.aac,.flac',
10
+ video: 'video/*,.mp4,.webm,.ogg',
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) ? 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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "util-helpers",
3
- "version": "5.1.2",
3
+ "version": "5.2.0",
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] 缓存策略
@@ -36,7 +36,7 @@ declare class AsyncMemo<DataType = any> {
36
36
  * @param {string} [key] 缓存键,如果没有该值将直接执行异步方法。
37
37
  * @param {Object} [options] 配置项
38
38
  * @param {number} [options.ttl] 数据存活时间
39
- * @param {boolean} [options.persisted=true] 数据持久化,如果存在缓存数据,直接返回缓存数据,不再执行异步方法。<br/>即使不开启该配置,不影响在异步执行成功后缓存数据。
39
+ * @param {boolean} [options.persisted=true] 数据持久化,默认`true`。如果存在缓存数据,直接返回缓存数据,不再执行异步方法。<br/>即使不开启该配置,不影响在异步执行成功后缓存数据。
40
40
  * @returns {Promise<*>} 异步结果
41
41
  */
42
42
  run(asyncFn: (...args: any[]) => Promise<DataType>, key?: string, options?: {
@@ -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;
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,7 +47,7 @@ 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
52
  * @param {AjaxOptions} [options] 配置项
53
53
  * @returns {Promise<object>} XHR 事件对象
@@ -10,8 +10,8 @@ type BytesToSizeOptions = {
10
10
  * @since 3.8.0
11
11
  * @param {number} bytes 字节大小
12
12
  * @param {Object} [options] 配置项
13
- * @param {string} [options.spaceMark=' '] 间隔字符
14
- * @param {number} [options.precision=2] 精度
13
+ * @param {string} [options.spaceMark=' '] 间隔字符,默认`' '`
14
+ * @param {number} [options.precision=2] 精度,默认`2`
15
15
  * @returns {string} 存储单位值
16
16
  * @example
17
17
  *
@@ -9,15 +9,15 @@ 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 当前输入原值
17
17
  * @param {string} ctrlValue 当前格式化后的值
18
18
  * @param {Object} [options] 配置项
19
- * @param {string|string[]} [options.placeholderChar=' '] 占位符
20
- * @param {RegExp} [options.maskReg=/\D/g] 需要遮盖的字符规则。默认去掉非数字,意味着 ctrlValue 需要去掉非数字。
19
+ * @param {string|string[]} [options.placeholderChar=' '] 占位符,默认`' '`
20
+ * @param {RegExp} [options.maskReg=/\D/g] 需要遮盖的字符规则。默认`/\D/g` 去掉非数字,意味着 ctrlValue 需要去掉非数字。
21
21
  * @param {'mobile'|'bankCard'} [options.type] 格式化类型,内置手机号码和银行卡号特殊处理
22
22
  * @returns {number} 格式化后的光标位置
23
23
  */
@@ -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,19 +37,19 @@ 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] 自定义图片宽度,默认图片自身宽度
44
44
  * @param {number} [options.height] 自定义图片高度,默认图片自身高度
45
45
  * @param {number} [options.rotate] 旋转
46
- * @param {Array | function} [options.offset=[0, 0]] x,y轴偏移值
47
- * @param {string} [options.background=#fff] 背景颜色
46
+ * @param {Array | function} [options.offset=[0, 0]] x,y轴偏移值,默认`[0, 0]`
47
+ * @param {string} [options.background=#fff] 背景颜色,默认`#fff`
48
48
  * @param {number | function} [options.canvasWidth] 画布宽度,默认图片宽度
49
49
  * @param {number | function} [options.canvasHeight] 画布高度,默认图片高度
50
- * @param {'blob' | 'dataURL'} [options.format='blob'] 导出格式
51
- * @param {string} [options.type='image/jpeg'] 图片类型
52
- * @param {number} [options.quality=0.8] 图片质量
50
+ * @param {'blob' | 'dataURL'} [options.format='blob'] 导出格式,默认`blob`
51
+ * @param {string} [options.type='image/jpeg'] 图片类型,默认`image/jpeg`
52
+ * @param {number} [options.quality=0.8] 图片质量,默认`0.8`
53
53
  * @param {function} [options.beforeCompress] 图片加载完成,画布创建之前调用
54
54
  * @param {function} [options.beforeDraw] 图片载入画布之前调用
55
55
  * @param {function} [options.afterDraw] 图片载入画布之后调用
@@ -60,6 +60,7 @@ interface CompressImage {
60
60
  * // 默认返回压缩后的 blob 对象
61
61
  * compressImage(file).then(blob=>{
62
62
  * // do something
63
+ * // 转为文件对象 new File([blob], file.name, { type: file.type })
63
64
  * });
64
65
  *
65
66
  * // 设置返回格式 data url
@@ -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
@@ -35,12 +35,14 @@ type DownloadOptions = {
35
35
  *
36
36
  * <em style="font-weight: bold;">注意:微信浏览器不支持H5下载文件。</em>
37
37
  *
38
+ * <em>响应头中有 "Content-Disposition" 字段,客户端获取不到?</em> 请参考查阅 [Access-Control-Expose-Headers](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers) 。
39
+ *
38
40
  * @static
39
41
  * @alias module:Other.download
40
42
  * @since 4.16.0
41
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers Access-Control-Expose-Headers}
42
- * @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展 MIME}
43
- * @see {@link https://9ykc9s.csb.app/ 在线示例}
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/ | 在线示例}
44
46
  * @param {string|Blob|ArrayBuffer|TypedArray} data 字符串、blob数据或url地址
45
47
  * @param {string|DownloadOptions} [options] 文件名称 或 配置项
46
48
  * @returns {Promise<void>}
@@ -16,10 +16,10 @@ 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
- * @param {'arrayBuffer'|'binaryString'|'dataURL'|'text'} [type='dataURL'] 读取类型
22
+ * @param {'arrayBuffer'|'binaryString'|'dataURL'|'text'} [type='dataURL'] 读取类型,默认`dataURL`。可选 `arrayBuffer` `binaryString` `dataURL` `text` 。
23
23
  * @returns {Promise<string|ArrayBuffer>} 文件内容
24
24
  * @example
25
25
  * const aFileParts = ['<a id="a"><b id="b">hey!</b></a>']; // 一个包含DOMString的数组
@@ -9,8 +9,8 @@ type NodeAssign = 'spread' | 'self';
9
9
  * @since 4.15.0
10
10
  * @param {Object[]} tree 树结构数据
11
11
  * @param {function} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 `Truthy` ,结果将包含该节点
12
- * @param {string} [childrenField='children'] 子级字段名
13
- * @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
12
+ * @param {string} [childrenField='children'] 子级字段名,默认`children`
13
+ * @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式,默认`spread`。`spread`表示使用展开运算符创建新值,`self`-表示使用自身对象。
14
14
  * @returns {Object[]}
15
15
  * @example
16
16
  * const menus = [{ id: '1', name: '首页', code: 'trade', pid: null }, { id: '2', name: '交易管理', code: 'trade', pid: null, children: [{ id: '3', name: '交易查询', code: 'trade-1', pid: '2', children: [{ id: '4', name: '交易查询-查询操作', code: 'trade-1-1', pid: '3' }]}]}, { id: '5', name: '权限管理', code: 'authorization', pid: null, children: [{ id: '6', name: '角色管理', code: 'authorization-1', pid: '5' }, { id: '7', name: '用户管理', code: 'authorization-2', pid: '5' }]}];
@@ -6,7 +6,7 @@
6
6
  * @since 4.14.0
7
7
  * @param {Object[]} tree 树结构数据
8
8
  * @param {function} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 `Truthy` ,将返回该节点
9
- * @param {string} [childrenField='children'] 子级字段名
9
+ * @param {string} [childrenField='children'] 子级字段名,默认`children`
10
10
  * @returns {Object|undefined}
11
11
  * @example
12
12
  * const menus = [{ id: '1', name: '首页', code: 'trade', pid: null }, { id: '2', name: '交易管理', code: 'trade', pid: null, children: [{ id: '3', name: '交易查询', code: 'trade-1', pid: '2', children: [{ id: '4', name: '交易查询-查询操作', code: 'trade-1-1', pid: '3' }]}]}, { id: '5', name: '权限管理', code: 'authorization', pid: null, children: [{ id: '6', name: '角色管理', code: 'authorization-1', pid: '5' }, { id: '7', name: '用户管理', code: 'authorization-2', pid: '5' }]}];
@@ -6,7 +6,7 @@
6
6
  * @since 4.15.0
7
7
  * @param {Object[]} tree 树结构数据
8
8
  * @param {function} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy ,返回结果将包含该节点
9
- * @param {string} [childrenField='children'] 子级字段名
9
+ * @param {string} [childrenField='children'] 子级字段名,默认`children`
10
10
  * @returns {Object[]}
11
11
  * @example
12
12
  * const menus = [{ id: '1', name: '首页', code: 'trade', pid: null }, { id: '2', name: '交易管理', code: 'trade', pid: null, children: [{ id: '3', name: '交易查询', code: 'trade-1', pid: '2', children: [{ id: '4', name: '交易查询-查询操作', code: 'trade-1-1', pid: '3' }]}]}, { id: '5', name: '权限管理', code: 'authorization', pid: null, children: [{ id: '6', name: '角色管理', code: 'authorization-1', pid: '5' }, { id: '7', name: '用户管理', code: 'authorization-2', pid: '5' }]}];
@@ -6,7 +6,7 @@
6
6
  * @since 4.14.0
7
7
  * @param {Object[]} tree 树结构数据
8
8
  * @param {function} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy 将返回包含该节点的所有父级节点
9
- * @param {string} [childrenField='children'] 子级字段名
9
+ * @param {string} [childrenField='children'] 子级字段名,默认`children`
10
10
  * @returns {Object[]}
11
11
  * @example
12
12
  * const menus = [{ id: '1', name: '首页', code: 'trade', pid: null }, { id: '2', name: '交易管理', code: 'trade', pid: null, children: [{ id: '3', name: '交易查询', code: 'trade-1', pid: '2', children: [{ id: '4', name: '交易查询-查询操作', code: 'trade-1-1', pid: '3' }]}]}, { id: '5', name: '权限管理', code: 'authorization', pid: null, children: [{ id: '6', name: '角色管理', code: 'authorization-1', pid: '5' }, { id: '7', name: '用户管理', code: 'authorization-2', pid: '5' }]}];
@@ -10,8 +10,8 @@ type Options = {
10
10
  * @since 1.1.0
11
11
  * @param {string} bankCardNo 要处理的字符串
12
12
  * @param {Object} [options] 配置项
13
- * @param {string} [options.spaceMark=' '] 间隔字符
14
- * @param {number} [options.length=4] 间隔长度
13
+ * @param {string} [options.spaceMark=' '] 间隔字符,默认`' '`
14
+ * @param {number} [options.length=4] 间隔长度,默认`4`
15
15
  * @returns {string} 格式化的银行卡号
16
16
  * @example
17
17
  *
@@ -9,7 +9,7 @@ type Options = {
9
9
  * @since 4.5.0
10
10
  * @param {string} mobileNo 手机号码
11
11
  * @param {Object} [options] 配置项
12
- * @param {string} [options.spaceMark=' '] 间隔字符
12
+ * @param {string} [options.spaceMark=' '] 间隔字符,默认`' '`
13
13
  * @returns {string} 格式化后的手机号码
14
14
  * @example
15
15
  *
@@ -13,11 +13,11 @@ type Options = {
13
13
  * @since 1.1.0
14
14
  * @param {string | number} num 需转换金额 (最大:9007199254740991 最小: -9007199254740991)
15
15
  * @param {Object} [options] 金额格式化配置
16
- * @param {number} [options.precision=2] 保留位数 (最高:10位)
16
+ * @param {number} [options.precision=2] 保留位数,默认`2`。最高`10`。
17
17
  * @param {string} [options.symbol] 货币符号
18
- * @param {string} [options.thousand=","] 千分位符号
19
- * @param {string} [options.decimal="."] 小数位符号
20
- * @param {boolean} [options.strict=ture] 严格模式。开启后,只支持非空字符串和数字格式化,其他类型值如`null` `undefined` `true` `false`等将返回空字符串。
18
+ * @param {string} [options.thousand=","] 千分位符号, 默认`,`
19
+ * @param {string} [options.decimal="."] 小数位符号,默认`.`
20
+ * @param {boolean} [options.strict=ture] 严格模式,默认`true`。开启后,只支持非空字符串和数字格式化,其他类型值如`null` `undefined` `true` `false`等将返回空字符串。
21
21
  * @returns {string} 格式化的金额
22
22
  * @example
23
23
  *
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
+ * 获取文件类型。
4
4
  *
5
5
  * @static
6
6
  * @alias module:Other.getFileType
@@ -0,0 +1,25 @@
1
+ /**
2
+ * 获取常用的 MIME 类型。
3
+ *
4
+ * 通过文件名后缀查找对于的 MIME 类型。
5
+ *
6
+ * @alias module:Other.getMimeType
7
+ * @since 5.2.0
8
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/MIME_types | MIME 类型(IANA 媒体类型)}
9
+ * @see {@link https://www.iana.org/assignments/media-types/media-types.xhtml | Media Types}
10
+ * @param {string} fileName 文件名。
11
+ * @returns 如果找到,返回 MIME 类型字符串,否则返回 `undefined`。
12
+ * @example
13
+ * getMimeType('xxx.png'); // 'image/png'
14
+ * getMimeType('xxx.jpg'); // 'image/jpeg'
15
+ * getMimeType('xxx.mp3'); // 'audio/mp3'
16
+ * getMimeType('xxx.mp4'); // 'video/mp4'
17
+ * getMimeType('xxx.pdf'); // 'application/pdf'
18
+ * getMimeType('xxx.zip'); // 'application/zip'
19
+ * getMimeType('xxx.doc'); // 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
20
+ *
21
+ * // 不常用或未知类型
22
+ * getMimeTye('xxx.ci'); // undefined
23
+ */
24
+ declare function getMimeType(fileName: string): string | undefined;
25
+ 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,11 +8,11 @@ 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
- * @param {boolean} [options.loose=false] 宽松模式,8-30位数字
15
- * @param {boolean} [options.luhn=false] 使用 Luhn 算法校验校验码
14
+ * @param {boolean} [options.loose=false] 宽松模式,默认`false`。正常模式10-21位数字(个人账户),宽松模式8-30位数字(企业账户)。
15
+ * @param {boolean} [options.luhn=false] 使用 Luhn 算法校验校验码,默认`false`
16
16
  * @returns {boolean} 值是否为银行卡号
17
17
  * @example
18
18
  *
@@ -7,10 +7,10 @@ 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
- * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
13
+ * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,默认`true`。如果为false,不校验校验位。
14
14
  * @returns {boolean} 值是否为营业执照号
15
15
  * @example
16
16
  *