util-helpers 5.2.0 → 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.
package/esm/VERSION.js CHANGED
@@ -1,4 +1,4 @@
1
- var VERSION = "5.2.0";
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',
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'
@@ -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 = isString(fileName) && fileName.indexOf('.') > 0 ? nth(fileName.split('.'), -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
 
@@ -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.2.0";
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',
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'
@@ -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 = ut2.isString(fileName) && fileName.indexOf('.') > 0 ? ut2.nth(fileName.split('.'), -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
 
@@ -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.2.0",
3
+ "version": "5.2.1",
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,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
@@ -49,8 +49,25 @@ type AjaxOptions = {
49
49
  * @since 4.16.0
50
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
@@ -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
  *
@@ -44,7 +26,12 @@ type DownloadOptions = {
44
26
  * @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展 | MIME}
45
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
  * // 文本
@@ -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=>{
@@ -1,7 +1,5 @@
1
1
  /**
2
- * 获取常用的 MIME 类型。
3
- *
4
- * 通过文件名后缀查找对于的 MIME 类型。
2
+ * @summary 获取常用的 MIME 类型。通过文件名后缀查找对应的 MIME 类型。
5
3
  *
6
4
  * @alias module:Other.getMimeType
7
5
  * @since 5.2.0
@@ -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;
@@ -20,7 +20,8 @@ import getFileBlob from './getFileBlob';
20
20
  * @example
21
21
  *
22
22
  * loadImage(file).then(({image, blob})=>{
23
- * // do something
23
+ * console.log(image, blob);
24
+ * // HTMLImageElement {} Blob {}
24
25
  * });
25
26
  *
26
27
  * loadImage('https://dummyimage.com/200x300').then(({image, blob})=>{
@@ -1,6 +1,5 @@
1
1
  export declare function testExt(name: string | undefined, ext: string): boolean;
2
2
  export type UploadFile = {
3
- uid: string;
4
3
  name: string;
5
4
  type?: string;
6
5
  url?: string;