util-helpers 5.2.1 → 5.3.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 (88) hide show
  1. package/README.md +19 -17
  2. package/dist/util-helpers.js +101 -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/getMimeType.js +2 -2
  9. package/esm/index.js +4 -3
  10. package/esm/injectStyle.js +23 -0
  11. package/esm/loadScript.js +3 -3
  12. package/esm/utils/file.util.js +6 -3
  13. package/lib/VERSION.js +1 -1
  14. package/lib/checkFileType.js +6 -4
  15. package/lib/getMimeType.js +2 -2
  16. package/lib/index.js +8 -6
  17. package/lib/injectStyle.js +25 -0
  18. package/lib/loadScript.js +3 -3
  19. package/lib/utils/file.util.js +5 -1
  20. package/package.json +1 -1
  21. package/types/VERSION.d.ts +1 -2
  22. package/types/ajax.d.ts +2 -3
  23. package/types/bytesToSize.d.ts +0 -1
  24. package/types/calculateCursorPosition.d.ts +0 -1
  25. package/types/checkFileType.d.ts +3 -2
  26. package/types/compressImage.d.ts +1 -1
  27. package/types/dataURLToBlob.d.ts +1 -2
  28. package/types/divide.d.ts +0 -1
  29. package/types/download.d.ts +1 -2
  30. package/types/fileReader.d.ts +1 -1
  31. package/types/filterTree.d.ts +0 -1
  32. package/types/findTreeNode.d.ts +0 -1
  33. package/types/findTreeNodes.d.ts +0 -1
  34. package/types/findTreeSelect.d.ts +0 -1
  35. package/types/formatBankCard.d.ts +0 -1
  36. package/types/formatMobile.d.ts +0 -1
  37. package/types/formatMoney.d.ts +0 -1
  38. package/types/gcd.d.ts +0 -1
  39. package/types/getExtname.d.ts +0 -0
  40. package/types/getFileBlob.d.ts +1 -2
  41. package/types/getFileType.d.ts +1 -3
  42. package/types/getImageInfo.d.ts +1 -2
  43. package/types/getMimeType.d.ts +1 -1
  44. package/types/index.d.ts +13 -10
  45. package/types/injectStyle.d.ts +16 -0
  46. package/types/isBankCard.d.ts +0 -1
  47. package/types/isBusinessLicense.d.ts +0 -1
  48. package/types/isChinese.d.ts +0 -1
  49. package/types/isEmail.d.ts +0 -1
  50. package/types/isHMCard.d.ts +0 -1
  51. package/types/isIPv4.d.ts +0 -1
  52. package/types/isIPv6.d.ts +0 -1
  53. package/types/isIdCard.d.ts +0 -1
  54. package/types/isMobile.d.ts +0 -1
  55. package/types/isPassport.d.ts +0 -1
  56. package/types/isPassword.d.ts +0 -1
  57. package/types/isPostcode.d.ts +0 -1
  58. package/types/isQQ.d.ts +0 -1
  59. package/types/isSocialCreditCode.d.ts +0 -1
  60. package/types/isSwiftCode.d.ts +0 -1
  61. package/types/isTWCard.d.ts +0 -1
  62. package/types/isTelephone.d.ts +0 -1
  63. package/types/isUrl.d.ts +0 -1
  64. package/types/isValidNumber.d.ts +0 -1
  65. package/types/isVehicle.d.ts +0 -1
  66. package/types/isWX.d.ts +0 -1
  67. package/types/lcm.d.ts +0 -1
  68. package/types/listToTree.d.ts +0 -1
  69. package/types/loadImage.d.ts +1 -2
  70. package/types/loadImageWithBlob.d.ts +1 -1
  71. package/types/loadScript.d.ts +1 -2
  72. package/types/minus.d.ts +0 -1
  73. package/types/numberToChinese.d.ts +0 -1
  74. package/types/padZero.d.ts +0 -1
  75. package/types/parseIdCard.d.ts +0 -1
  76. package/types/plus.d.ts +0 -1
  77. package/types/replaceChar.d.ts +0 -1
  78. package/types/round.d.ts +0 -1
  79. package/types/setDataURLPrefix.d.ts +0 -1
  80. package/types/strlen.d.ts +0 -1
  81. package/types/times.d.ts +0 -1
  82. package/types/transformFieldNames.d.ts +0 -1
  83. package/types/transformObjectValue.d.ts +0 -1
  84. package/types/treeToList.d.ts +0 -1
  85. package/types/utils/config.d.ts +0 -1
  86. package/types/utils/file.util.d.ts +4 -0
  87. package/types/validatePassword.d.ts +0 -1
  88. package/types/BlobUrl.d.ts +0 -41
package/esm/VERSION.js CHANGED
@@ -1,4 +1,4 @@
1
- var VERSION = "5.2.1";
1
+ var VERSION = "5.3.0";
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;
@@ -1,5 +1,5 @@
1
- import { isString, nth } from 'ut2';
2
1
  import { nativeUndefined } from './utils/native.js';
2
+ import { getExtname } 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) && fileName.indexOf('.') > 0 ? nth(fileName.split('.'), -1) : '';
39
+ var ext = getExtname(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,17 +39,20 @@ 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';
51
50
  export { default as getMimeType } from './getMimeType.js';
51
+ export { default as injectStyle } from './injectStyle.js';
52
52
  export { default as loadImage } from './loadImage.js';
53
53
  export { default as loadImageWithBlob } from './loadImageWithBlob.js';
54
54
  export { default as loadScript } from './loadScript.js';
55
+ export { default as calculateCursorPosition } from './calculateCursorPosition.js';
55
56
  export { default as randomString } from './randomString.js';
56
57
  export { default as strlen } from './strlen.js';
57
58
  export { default as transformFieldNames } from './transformFieldNames.js';
@@ -0,0 +1,23 @@
1
+ function injectStyle(css, options) {
2
+ var _a = options || {}, _b = _a.container, container = _b === void 0 ? document.head || document.getElementsByTagName('head')[0] || document.body : _b, _c = _a.insertAt, insertAt = _c === void 0 ? 'top' : _c;
3
+ var style = document.createElement('style');
4
+ if (style.styleSheet) {
5
+ style.styleSheet.cssText = css;
6
+ }
7
+ else {
8
+ style.appendChild(document.createTextNode(css));
9
+ }
10
+ var atTop = insertAt === 'top';
11
+ if (atTop && container.prepend) {
12
+ container.prepend(style);
13
+ }
14
+ else if (atTop && container.firstChild) {
15
+ container.insertBefore(style, container.firstChild);
16
+ }
17
+ else {
18
+ container.appendChild(style);
19
+ }
20
+ return style;
21
+ }
22
+
23
+ export { injectStyle as default };
package/esm/loadScript.js CHANGED
@@ -3,7 +3,7 @@ import { objectKeys } from './utils/native.js';
3
3
 
4
4
  function loadScript(src, options) {
5
5
  return new Promise(function (resolve, reject) {
6
- var head = document.head;
6
+ var container = document.head || document.getElementsByTagName('head')[0] || document.body;
7
7
  var script = document.createElement('script');
8
8
  var _a = options || {}, attrs = _a.attrs, _b = _a.destroyOnError, destroyOnError = _b === void 0 ? true : _b, restOptions = __rest(_a, ["attrs", "destroyOnError"]);
9
9
  var props = __assign(__assign({ async: true, type: 'text/javascript' }, restOptions), { src: src });
@@ -29,11 +29,11 @@ function loadScript(src, options) {
29
29
  this.onerror = this.onload = null;
30
30
  (_a = props.onerror) === null || _a === void 0 ? void 0 : _a.call(this, ev);
31
31
  if (destroyOnError) {
32
- head.removeChild(script);
32
+ container.removeChild(script);
33
33
  }
34
34
  reject(new URIError('Failed to load ' + this.src));
35
35
  };
36
- head.appendChild(script);
36
+ container.appendChild(script);
37
37
  });
38
38
  }
39
39
 
@@ -1,7 +1,10 @@
1
- import { isObjectLike, isString } from 'ut2';
1
+ import { isString, nth, isObjectLike } from 'ut2';
2
2
 
3
+ function getExtname(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 && getExtname(name) === ext;
5
8
  }
6
9
  function isUploadFile(fileObj) {
7
10
  if (isObjectLike(fileObj) && isString(fileObj.name)) {
@@ -10,4 +13,4 @@ function isUploadFile(fileObj) {
10
13
  return false;
11
14
  }
12
15
 
13
- export { isUploadFile, testExt };
16
+ export { getExtname, isUploadFile, testExt };
package/lib/VERSION.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var VERSION = "5.2.1";
3
+ var VERSION = "5.3.0";
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;
@@ -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) && fileName.indexOf('.') > 0 ? ut2.nth(fileName.split('.'), -1) : '';
41
+ var ext = file_util.getExtname(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,17 +41,20 @@ 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');
53
52
  var getMimeType = require('./getMimeType.js');
53
+ var injectStyle = require('./injectStyle.js');
54
54
  var loadImage = require('./loadImage.js');
55
55
  var loadImageWithBlob = require('./loadImageWithBlob.js');
56
56
  var loadScript = require('./loadScript.js');
57
+ var calculateCursorPosition = require('./calculateCursorPosition.js');
57
58
  var randomString = require('./randomString.js');
58
59
  var strlen = require('./strlen.js');
59
60
  var transformFieldNames = require('./transformFieldNames.js');
@@ -97,8 +98,6 @@ exports.replaceChar = replaceChar;
97
98
  exports.numberToChinese = numberToChinese;
98
99
  exports.bytesToSize = bytesToSize;
99
100
  exports.parseIdCard = parseIdCard;
100
- exports.fileReader = fileReader;
101
- exports.dataURLToBlob = dataURLToBlob;
102
101
  exports.setDataURLPrefix = setDataURLPrefix;
103
102
  exports.safeDate = safeDate;
104
103
  exports.formatMobile = formatMobile;
@@ -112,17 +111,20 @@ exports.round = round;
112
111
  exports.gcd = gcd;
113
112
  exports.lcm = lcm;
114
113
  exports.ajax = ajax;
115
- exports.calculateCursorPosition = calculateCursorPosition;
116
114
  exports.checkFileType = checkFileType;
117
115
  exports.compressImage = compressImage;
116
+ exports.dataURLToBlob = dataURLToBlob;
118
117
  exports.download = download;
118
+ exports.fileReader = fileReader;
119
119
  exports.getFileBlob = getFileBlob;
120
120
  exports.getFileType = getFileType;
121
121
  exports.getImageInfo = getImageInfo;
122
122
  exports.getMimeType = getMimeType;
123
+ exports.injectStyle = injectStyle;
123
124
  exports.loadImage = loadImage;
124
125
  exports.loadImageWithBlob = loadImageWithBlob;
125
126
  exports.loadScript = loadScript;
127
+ exports.calculateCursorPosition = calculateCursorPosition;
126
128
  exports.randomString = randomString;
127
129
  exports.strlen = strlen;
128
130
  exports.transformFieldNames = transformFieldNames;
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ function injectStyle(css, options) {
4
+ var _a = options || {}, _b = _a.container, container = _b === void 0 ? document.head || document.getElementsByTagName('head')[0] || document.body : _b, _c = _a.insertAt, insertAt = _c === void 0 ? 'top' : _c;
5
+ var style = document.createElement('style');
6
+ if (style.styleSheet) {
7
+ style.styleSheet.cssText = css;
8
+ }
9
+ else {
10
+ style.appendChild(document.createTextNode(css));
11
+ }
12
+ var atTop = insertAt === 'top';
13
+ if (atTop && container.prepend) {
14
+ container.prepend(style);
15
+ }
16
+ else if (atTop && container.firstChild) {
17
+ container.insertBefore(style, container.firstChild);
18
+ }
19
+ else {
20
+ container.appendChild(style);
21
+ }
22
+ return style;
23
+ }
24
+
25
+ module.exports = injectStyle;
package/lib/loadScript.js CHANGED
@@ -5,7 +5,7 @@ var native = require('./utils/native.js');
5
5
 
6
6
  function loadScript(src, options) {
7
7
  return new Promise(function (resolve, reject) {
8
- var head = document.head;
8
+ var container = document.head || document.getElementsByTagName('head')[0] || document.body;
9
9
  var script = document.createElement('script');
10
10
  var _a = options || {}, attrs = _a.attrs, _b = _a.destroyOnError, destroyOnError = _b === void 0 ? true : _b, restOptions = tslib.__rest(_a, ["attrs", "destroyOnError"]);
11
11
  var props = tslib.__assign(tslib.__assign({ async: true, type: 'text/javascript' }, restOptions), { src: src });
@@ -31,11 +31,11 @@ function loadScript(src, options) {
31
31
  this.onerror = this.onload = null;
32
32
  (_a = props.onerror) === null || _a === void 0 ? void 0 : _a.call(this, ev);
33
33
  if (destroyOnError) {
34
- head.removeChild(script);
34
+ container.removeChild(script);
35
35
  }
36
36
  reject(new URIError('Failed to load ' + this.src));
37
37
  };
38
- head.appendChild(script);
38
+ container.appendChild(script);
39
39
  });
40
40
  }
41
41
 
@@ -2,8 +2,11 @@
2
2
 
3
3
  var ut2 = require('ut2');
4
4
 
5
+ function getExtname(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 && getExtname(name) === ext;
7
10
  }
8
11
  function isUploadFile(fileObj) {
9
12
  if (ut2.isObjectLike(fileObj) && ut2.isString(fileObj.name)) {
@@ -12,5 +15,6 @@ function isUploadFile(fileObj) {
12
15
  return false;
13
16
  }
14
17
 
18
+ exports.getExtname = getExtname;
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.1",
3
+ "version": "5.3.0",
4
4
  "description": "一个基于业务场景的工具方法库",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -1,6 +1,5 @@
1
1
  /**
2
- * @summary 版本号
3
- * @static
2
+ * @summary util-helpers 版本号。
4
3
  * @since 4.18.0
5
4
  */
6
5
  declare const VERSION: string;
package/types/ajax.d.ts CHANGED
@@ -44,12 +44,11 @@ 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
- * @param {Object} [options] 配置项
51
+ * @param {AjaxOptions} [options] 配置项
53
52
  * @param {string} [options.method="get"] 创建请求时使用的方法。默认 `'get'`。
54
53
  * @param {boolean} [options.async=true] 是否异步执行操作。默认 `true`。
55
54
  * @param {string|null} [options.user=null] 用户名,用于认证用途。默认 `null`。
@@ -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 被除数和除数
@@ -19,8 +19,7 @@ type DownloadOptions = {
19
19
  *
20
20
  * <em>响应头中有 "Content-Disposition" 字段,客户端获取不到?</em> 请参考查阅 [Access-Control-Expose-Headers](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers) 。
21
21
  *
22
- * @static
23
- * @alias module:Other.download
22
+ * @alias module:Browser.download
24
23
  * @since 4.16.0
25
24
  * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers | Access-Control-Expose-Headers}
26
25
  * @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展 | MIME}
@@ -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/最大公约数 | 最大公约数}
File without changes
@@ -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
3
  * @summary 获取文件类型。
4
- *
5
- * @static
6
- * @alias module:Other.getFileType
4
+ * @alias module:Browser.getFileType
7
5
  * @since 5.1.0
8
6
  * @requires Other.checkFileType
9
7
  * @param {File} file 文件对象。支持 antd `UploadFile` 对象。
@@ -15,8 +15,7 @@ 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
20
  * @param {string | Blob} img 图片地址或 blob 对象。
22
21
  * @param {AjaxOptions} [ajaxOptions] ajax 请求配置项,当传入的图片为字符串时才会触发请求。
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @summary 获取常用的 MIME 类型。通过文件名后缀查找对应的 MIME 类型。
3
3
  *
4
- * @alias module:Other.getMimeType
4
+ * @alias module:Browser.getMimeType
5
5
  * @since 5.2.0
6
6
  * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/MIME_types | MIME 类型(IANA 媒体类型)}
7
7
  * @see {@link https://www.iana.org/assignments/media-types/media-types.xhtml | Media Types}
package/types/index.d.ts CHANGED
@@ -2,7 +2,6 @@
2
2
  * 数据验证
3
3
  *
4
4
  * @module Validator
5
- * @since 1.1.0
6
5
  */
7
6
  export { default as isMobile } from './isMobile';
8
7
  export { default as isTelephone } from './isTelephone';
@@ -30,7 +29,6 @@ export { default as isValidNumber } from './isValidNumber';
30
29
  * 数据处理
31
30
  *
32
31
  * @module Processor
33
- * @since 1.1.0
34
32
  */
35
33
  export { default as formatMoney } from './formatMoney';
36
34
  export { default as formatBankCard } from './formatBankCard';
@@ -38,8 +36,6 @@ export { default as replaceChar } from './replaceChar';
38
36
  export { default as numberToChinese } from './numberToChinese';
39
37
  export { default as bytesToSize } from './bytesToSize';
40
38
  export { default as parseIdCard } from './parseIdCard';
41
- export { default as fileReader } from './fileReader';
42
- export { default as dataURLToBlob } from './dataURLToBlob';
43
39
  export { default as setDataURLPrefix } from './setDataURLPrefix';
44
40
  export { default as safeDate } from './safeDate';
45
41
  export { default as formatMobile } from './formatMobile';
@@ -49,7 +45,6 @@ export { default as transformObjectValue } from './transformObjectValue';
49
45
  * 数学计算,修正浮点数计算问题
50
46
  *
51
47
  * @module Math
52
- * @since 3.1.0
53
48
  * @see {@link https://github.com/camsong/blog/issues/9 | JavaScript 浮点数陷阱及解法}
54
49
  * @see {@link https://2zbuy.csb.app/ | JS浮点数计算测试}
55
50
  * @example
@@ -92,30 +87,38 @@ export { default as round } from './round';
92
87
  export { default as gcd } from './gcd';
93
88
  export { default as lcm } from './lcm';
94
89
  /**
95
- * 其他
90
+ * 浏览器
96
91
  *
97
- * @module Other
98
- * @since 4.2.0
92
+ * <em style="font-weight: bold;">下列方法仅适用于浏览器端。</em>
93
+ *
94
+ * @module Browser
99
95
  */
100
96
  export { default as ajax } from './ajax';
101
- export { default as calculateCursorPosition } from './calculateCursorPosition';
102
97
  export { default as checkFileType } from './checkFileType';
103
98
  export { default as compressImage } from './compressImage';
99
+ export { default as dataURLToBlob } from './dataURLToBlob';
104
100
  export { default as download } from './download';
101
+ export { default as fileReader } from './fileReader';
105
102
  export { default as getFileBlob } from './getFileBlob';
106
103
  export { default as getFileType } from './getFileType';
107
104
  export { default as getImageInfo } from './getImageInfo';
108
105
  export { default as getMimeType } from './getMimeType';
106
+ export { default as injectStyle } from './injectStyle';
109
107
  export { default as loadImage } from './loadImage';
110
108
  export { default as loadImageWithBlob } from './loadImageWithBlob';
111
109
  export { default as loadScript } from './loadScript';
110
+ /**
111
+ * 其他
112
+ *
113
+ * @module Other
114
+ */
115
+ export { default as calculateCursorPosition } from './calculateCursorPosition';
112
116
  export { default as randomString } from './randomString';
113
117
  export { default as strlen } from './strlen';
114
118
  /**
115
119
  * 树结构数据查询、过滤、转换等处理方法
116
120
  *
117
121
  * @module Tree
118
- * @since 4.14.0
119
122
  */
120
123
  export { default as transformFieldNames } from './transformFieldNames';
121
124
  export { default as listToTree } from './listToTree';