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
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 注入样式。
3
+ *
4
+ * @alias module:Browser.injectStyle
5
+ * @since 5.3.0
6
+ * @param {string} css 样式内容。
7
+ * @param {Object} [options] 配置项。
8
+ * @param {HTMLElement} [options.container=document.head] 要注入样式的容器。默认 `document.head`。如果 `document.head` 不存在,默认 `document.body`。
9
+ * @param {'top' | 'bottom'} [options.insertAt='top'] 注入容器内容前面还是后面。默认 `top`。
10
+ * @returns {HTMLStyleElement} `style` 元素。
11
+ */
12
+ declare function injectStyle(css: string, options?: {
13
+ container?: HTMLElement;
14
+ insertAt?: 'top' | 'bottom';
15
+ }): HTMLStyleElement;
16
+ export default injectStyle;
@@ -5,7 +5,6 @@ type Options = {
5
5
  /**
6
6
  * 检测值是否为银行卡号。正常模式(非0开头,10-21位数字)宽松模式(8-30位数字)
7
7
  *
8
- * @static
9
8
  * @alias module:Validator.isBankCard
10
9
  * @since 1.1.0
11
10
  * @see {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html | 常用银行账号位数参考}
@@ -4,7 +4,6 @@ type Options = {
4
4
  /**
5
5
  * 检测值是否为营业执照号,也叫工商注册号。由14位数字本体码和1位数字校验码组成,其中本体码从左至右依次为:6位首次登记机关码、8位顺序码。
6
6
  *
7
- * @static
8
7
  * @alias module:Validator.isBusinessLicense
9
8
  * @since 3.5.0
10
9
  * @see {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html | GS15—2006 工商行政管理市场主体注册号编制规则}
@@ -5,7 +5,6 @@ type Options = {
5
5
  /**
6
6
  * 检测值是否为中文
7
7
  *
8
- * @static
9
8
  * @alias module:Validator.isChinese
10
9
  * @since 1.1.0
11
10
  * @see {@link http://www.unicode.org/reports/tr38/#BlockListing | 4.4 Listing of Characters Covered by the Unihan Database}
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 检测值是否为Email
3
3
  *
4
- * @static
5
4
  * @alias module:Validator.isEmail
6
5
  * @since 1.1.0
7
6
  * @param {*} value 要检测的值
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 检测值是否为港澳居民来往内地通行证,俗称回乡证或回乡卡。
3
3
  *
4
- * @static
5
4
  * @alias module:Validator.isHMCard
6
5
  * @since 4.0.0
7
6
  * @see {@link https://zh.wikipedia.org/wiki/港澳居民来往内地通行证 | 港澳居民来往内地通行证}
package/types/isIPv4.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 检测值是否为ipv4
3
3
  *
4
- * @static
5
4
  * @alias module:Validator.isIPv4
6
5
  * @since 1.1.0
7
6
  * @param {*} value 要检测的值
package/types/isIPv6.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 检测值是否为ipv6
3
3
  *
4
- * @static
5
4
  * @alias module:Validator.isIPv6
6
5
  * @since 1.1.0
7
6
  * @param {*} value 要检测的值
@@ -7,7 +7,6 @@ type Options = {
7
7
  *
8
8
  * 宽松模式下,支持15位身份证号码。
9
9
  *
10
- * @static
11
10
  * @alias module:Validator.isIdCard
12
11
  * @since 1.1.0
13
12
  * @see {@link https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码 | 中华人民共和国公民身份号码}
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 检测值是否为手机号码
3
3
  *
4
- * @static
5
4
  * @alias module:Validator.isMobile
6
5
  * @since 1.1.0
7
6
  * @param {*} value 要检测的值
@@ -2,7 +2,6 @@
2
2
  * 检测值是否为护照号
3
3
  * 支持普通护照(E*)、外交护照(DE)、公务护照(SE)、公务普通护照(PE)、香港特区护照(K/KJ/H*)、澳门特区护照(MA/MB/M*),注意不区分大小写
4
4
  *
5
- * @static
6
5
  * @alias module:Validator.isPassport
7
6
  * @since 1.1.0
8
7
  * @see {@link https://zh.wikipedia.org/wiki/中华人民共和国护照#个人资料页 | 中华人民共和国护照#个人资料页}
@@ -4,7 +4,6 @@ import validatePassword from './validatePassword';
4
4
  * <p><strong>注意:该校验只校验是否存在不同字符(大小写字母、数字、特殊符号),不判断长度。</strong></p>
5
5
  * <p><i>如果需要更细致的验证,请使用 <a href="#.validatePassword">validatePassword</a></i></p>
6
6
  *
7
- * @static
8
7
  * @alias module:Validator.isPassword
9
8
  * @requires module:Validator.validatePassword
10
9
  * @since 1.1.0
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 检测值是否为邮政编码,6位数字
3
3
  *
4
- * @static
5
4
  * @alias module:Validator.isPostcode
6
5
  * @since 1.1.0
7
6
  * @param {*} value 要检测的值
package/types/isQQ.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 检测值是否为QQ号,非0开头,5至11位数字
3
3
  *
4
- * @static
5
4
  * @alias module:Validator.isQQ
6
5
  * @since 1.1.0
7
6
  * @param {*} value 要检测的值
@@ -4,7 +4,6 @@ type Options = {
4
4
  /**
5
5
  * 检测值是否为统一社会信用代码,也叫三证合一组织代码。由18位数字和大写字母组成,不使用I、O、Z、S、V。
6
6
  *
7
- * @static
8
7
  * @alias module:Validator.isSocialCreditCode
9
8
  * @since 1.1.0
10
9
  * @see {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则 | GB 32100-2015 法人和其他组织统一社会信用代码编码规则}
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 检测值是否为 Swift Code。8位或11位,前6位为大写字母,7-8位为大写字母或数字,9-11位为可选的大写字母或数字。
3
3
  *
4
- * @static
5
4
  * @alias module:Validator.isSwiftCode
6
5
  * @since 4.9.0
7
6
  * @see {@link https://zh.wikipedia.org/wiki/ISO_9362 | ISO 9362}
@@ -4,7 +4,6 @@ type Options = {
4
4
  /**
5
5
  * 检测值是否为台湾居民来往大陆通行证,俗称台胞证。
6
6
  *
7
- * @static
8
7
  * @alias module:Validator.isTWCard
9
8
  * @since 4.0.0
10
9
  * @see {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证 | 台湾居民来往大陆通行证}
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 检测值是否为固定电话
3
3
  *
4
- * @static
5
4
  * @alias module:Validator.isTelephone
6
5
  * @since 1.1.0
7
6
  * @param {*} value 要检测的值
package/types/isUrl.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 检测值是否为url
3
3
  *
4
- * @static
5
4
  * @alias module:Validator.isUrl
6
5
  * @since 3.4.0
7
6
  * @see {@link https://zh.wikipedia.org/wiki/统一资源定位符 | 统一资源定位符}
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 检测值是否为有效数值,支持隐式转换。如果返回 true ,表示可以通过 Number() 转为数字。
3
3
  *
4
- * @static
5
4
  * @alias module:Validator.isValidNumber
6
5
  * @since 4.17.2
7
6
  * @param {*} value 待检测的值
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 检测值是否为车牌号,支持新能源和非新能源车牌
3
3
  *
4
- * @static
5
4
  * @alias module:Validator.isVehicle
6
5
  * @since 1.1.0
7
6
  * @see {@link https://baike.baidu.com/item/车牌号 | 车牌号}
package/types/isWX.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 检测值是否为微信号
3
3
  *
4
- * @static
5
4
  * @alias module:Validator.isWX
6
5
  * @since 1.1.0
7
6
  * @param {*} value 要检测的值
package/types/lcm.d.ts CHANGED
@@ -11,7 +11,6 @@
11
11
  * 6. 如果参数为负数,将转为绝对值的正数。
12
12
  * 7. 如果参数包含小数点,将转为四舍五入的整数。
13
13
  *
14
- * @static
15
14
  * @alias module:Math.lcm
16
15
  * @since 4.20.0
17
16
  * @see {@link https://baike.baidu.com/item/最小公倍数 | 最小公倍数}
@@ -9,7 +9,6 @@ type Options = {
9
9
  /**
10
10
  * 列表数据转树结构
11
11
  *
12
- * @static
13
12
  * @alias module:Tree.listToTree
14
13
  * @since 4.14.0
15
14
  * @param {Object[]} list 列表数据
@@ -3,8 +3,7 @@
3
3
  *
4
4
  * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
5
5
  *
6
- * @static
7
- * @alias module:Other.loadImage
6
+ * @alias module:Browser.loadImage
8
7
  * @since 4.20.0
9
8
  * @param {string | Blob} img 图片地址或 blob 对象
10
9
  * @returns {Promise<HTMLImageElement>} HTML图片元素
@@ -12,7 +12,7 @@ import getFileBlob from './getFileBlob';
12
12
  * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
13
13
  *
14
14
  * @method
15
- * @alias module:Other.loadImageWithBlob
15
+ * @alias module:Browser.loadImageWithBlob
16
16
  * @since 4.20.0
17
17
  * @param {string | Blob} img 图片地址或 blob 对象
18
18
  * @param {AjaxOptions} [ajaxOptions] ajax 请求配置项,当传入的图片为字符串时才会触发请求。
@@ -7,8 +7,7 @@ type ScriptAttribute = Pick<HTMLScriptElement, 'async' | 'crossOrigin' | 'defer'
7
7
  *
8
8
  * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
9
9
  *
10
- * @static
11
- * @alias module:Other.loadScript
10
+ * @alias module:Browser.loadScript
12
11
  * @since 4.19.0
13
12
  * @param {string} src js 地址。
14
13
  * @param {Object} [options] script 标签属性。比如 `defer` `onload` `onerror` `id` 等,下面列举部分带有默认值或额外扩展的配置。
package/types/minus.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 精确减法,支持多个数相减,减数默认为 0 。
3
3
  *
4
- * @static
5
4
  * @alias module:Math.minus
6
5
  * @since 3.1.0
7
6
  * @param {...(number|string)} nums 相减的数
@@ -14,7 +14,6 @@ type Options = {
14
14
  *
15
15
  * 如果数字不在安全数字 -9007199254740991~9007199254740991 范围内,处理会有异常。
16
16
  *
17
- * @static
18
17
  * @alias module:Processor.numberToChinese
19
18
  * @since 1.2.0
20
19
  * @see {@link https://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=F5DAC3377DA99C8D78AE66735B6359C7 | 出版物上数字用法}
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 前置补零
3
3
  *
4
- * @static
5
4
  * @alias module:Processor.padZero
6
5
  * @since 4.7.0
7
6
  * @param {string|number} value 要处理的值
@@ -33,7 +33,6 @@ type IdCardInfo = {
33
33
  /**
34
34
  * 解析身份证号码,支持15、18位身份证号码
35
35
  *
36
- * @static
37
36
  * @alias module:Processor.parseIdCard
38
37
  * @since 4.0.0
39
38
  * @see {@link https://baike.baidu.com/item/居民身份证号码 | 居民身份证号码}
package/types/plus.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 精确加法,支持多个数相加,加数默认为 0 。
3
3
  *
4
- * @static
5
4
  * @alias module:Math.plus
6
5
  * @since 3.1.0
7
6
  * @param {...(number|string)} nums 相加的数
@@ -8,7 +8,6 @@ type Options = {
8
8
  /**
9
9
  * 替换字符,应用场景如:脱敏
10
10
  *
11
- * @static
12
11
  * @alias module:Processor.replaceChar
13
12
  * @since 1.1.0
14
13
  * @param {string} str 要处理的字符串
package/types/round.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 四舍五入,支持设置精度
3
3
  *
4
- * @static
5
4
  * @alias module:Math.round
6
5
  * @since 3.1.0
7
6
  * @param {number|string} num 要四舍五入的数字
@@ -3,7 +3,6 @@
3
3
  *
4
4
  * 如果你需要获取DataURL 的 MIME 类型和数据本身,推荐使用 <a href="https://www.npmjs.com/package/data-urls">data-urls</a>。
5
5
  *
6
- * @static
7
6
  * @alias module:Processor.setDataURLPrefix
8
7
  * @since 4.1.0
9
8
  * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/URI/Schemes/data | Data URLs}
package/types/strlen.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 获取字符长度。中文汉字占2个字符,英文占1个字符,特殊如emoji占4个字符。
3
3
  *
4
- * @static
5
4
  * @alias module:Other.strlen
6
5
  * @since 4.10.0
7
6
  * @param {string} str 字符串
package/types/times.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 精确乘法,支持多个数相乘,乘数默认为 1 。
3
3
  *
4
- * @static
5
4
  * @alias module:Math.times
6
5
  * @since 3.1.0
7
6
  * @param {...(number|string)} nums 相乘的数
@@ -6,7 +6,6 @@ type TransformFieldNames<D extends any, F extends Record<string, any>, C extends
6
6
  /**
7
7
  * 转换字段名,返回一个转换字段后的值,不改变原值。
8
8
  *
9
- * @static
10
9
  * @alias module:Tree.transformFieldNames
11
10
  * @since 4.14.0
12
11
  * @param {Object[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenField
@@ -10,7 +10,6 @@ interface TransformObjectValue {
10
10
  *
11
11
  * 例如 antd Form 中的设置表单值时,如果值为空字符串可能需要转为 `undefined` ,才不影响表单的初始值。
12
12
  *
13
- * @static
14
13
  * @alias module:Processor.transformObjectValue
15
14
  * @since 4.23.0
16
15
  * @param {Array | Object} data 要转换值的普通对象或数组
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 树结构转列表数据
3
3
  *
4
- * @static
5
4
  * @alias module:Tree.treeToList
6
5
  * @since 4.14.0
7
6
  * @param {Object[]} tree 树结构数据
@@ -3,7 +3,6 @@ declare const config: {
3
3
  };
4
4
  /**
5
5
  * 设置禁止warning提示
6
- * @static
7
6
  * @alias module:Debug.formatBankCard
8
7
  * @since 3.6.1
9
8
  * @param {boolean} bool 是否禁止warning提示
@@ -1,7 +1,11 @@
1
+ export declare function getExtname(name: string): string;
1
2
  export declare function testExt(name: string | undefined, ext: string): boolean;
2
3
  export type UploadFile = {
3
4
  name: string;
4
5
  type?: string;
5
6
  url?: string;
7
+ fileName?: string;
8
+ uid?: string;
9
+ originFileObj?: File;
6
10
  };
7
11
  export declare function isUploadFile(fileObj: UploadFile): boolean;
@@ -20,7 +20,6 @@ type Options = {
20
20
  /**
21
21
  * 验证密码(数字、大小写字母、特殊字符、非法字符)
22
22
  *
23
- * @static
24
23
  * @alias module:Validator.validatePassword
25
24
  * @since 3.7.0
26
25
  * @see {@link https://baike.baidu.com/item/ASCII#3 | ASCII}
@@ -1,41 +0,0 @@
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;