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.
- package/README.md +19 -17
- package/dist/util-helpers.js +101 -73
- package/dist/util-helpers.js.map +1 -1
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/VERSION.js +1 -1
- package/esm/checkFileType.js +6 -4
- package/esm/getMimeType.js +2 -2
- package/esm/index.js +4 -3
- package/esm/injectStyle.js +23 -0
- package/esm/loadScript.js +3 -3
- package/esm/utils/file.util.js +6 -3
- package/lib/VERSION.js +1 -1
- package/lib/checkFileType.js +6 -4
- package/lib/getMimeType.js +2 -2
- package/lib/index.js +8 -6
- package/lib/injectStyle.js +25 -0
- package/lib/loadScript.js +3 -3
- package/lib/utils/file.util.js +5 -1
- package/package.json +1 -1
- package/types/VERSION.d.ts +1 -2
- package/types/ajax.d.ts +2 -3
- package/types/bytesToSize.d.ts +0 -1
- package/types/calculateCursorPosition.d.ts +0 -1
- package/types/checkFileType.d.ts +3 -2
- package/types/compressImage.d.ts +1 -1
- package/types/dataURLToBlob.d.ts +1 -2
- package/types/divide.d.ts +0 -1
- package/types/download.d.ts +1 -2
- package/types/fileReader.d.ts +1 -1
- package/types/filterTree.d.ts +0 -1
- package/types/findTreeNode.d.ts +0 -1
- package/types/findTreeNodes.d.ts +0 -1
- package/types/findTreeSelect.d.ts +0 -1
- package/types/formatBankCard.d.ts +0 -1
- package/types/formatMobile.d.ts +0 -1
- package/types/formatMoney.d.ts +0 -1
- package/types/gcd.d.ts +0 -1
- package/types/getExtname.d.ts +0 -0
- package/types/getFileBlob.d.ts +1 -2
- package/types/getFileType.d.ts +1 -3
- package/types/getImageInfo.d.ts +1 -2
- package/types/getMimeType.d.ts +1 -1
- package/types/index.d.ts +13 -10
- package/types/injectStyle.d.ts +16 -0
- package/types/isBankCard.d.ts +0 -1
- package/types/isBusinessLicense.d.ts +0 -1
- package/types/isChinese.d.ts +0 -1
- package/types/isEmail.d.ts +0 -1
- package/types/isHMCard.d.ts +0 -1
- package/types/isIPv4.d.ts +0 -1
- package/types/isIPv6.d.ts +0 -1
- package/types/isIdCard.d.ts +0 -1
- package/types/isMobile.d.ts +0 -1
- package/types/isPassport.d.ts +0 -1
- package/types/isPassword.d.ts +0 -1
- package/types/isPostcode.d.ts +0 -1
- package/types/isQQ.d.ts +0 -1
- package/types/isSocialCreditCode.d.ts +0 -1
- package/types/isSwiftCode.d.ts +0 -1
- package/types/isTWCard.d.ts +0 -1
- package/types/isTelephone.d.ts +0 -1
- package/types/isUrl.d.ts +0 -1
- package/types/isValidNumber.d.ts +0 -1
- package/types/isVehicle.d.ts +0 -1
- package/types/isWX.d.ts +0 -1
- package/types/lcm.d.ts +0 -1
- package/types/listToTree.d.ts +0 -1
- package/types/loadImage.d.ts +1 -2
- package/types/loadImageWithBlob.d.ts +1 -1
- package/types/loadScript.d.ts +1 -2
- package/types/minus.d.ts +0 -1
- package/types/numberToChinese.d.ts +0 -1
- package/types/padZero.d.ts +0 -1
- package/types/parseIdCard.d.ts +0 -1
- package/types/plus.d.ts +0 -1
- package/types/replaceChar.d.ts +0 -1
- package/types/round.d.ts +0 -1
- package/types/setDataURLPrefix.d.ts +0 -1
- package/types/strlen.d.ts +0 -1
- package/types/times.d.ts +0 -1
- package/types/transformFieldNames.d.ts +0 -1
- package/types/transformObjectValue.d.ts +0 -1
- package/types/treeToList.d.ts +0 -1
- package/types/utils/config.d.ts +0 -1
- package/types/utils/file.util.d.ts +4 -0
- package/types/validatePassword.d.ts +0 -1
- 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;
|
package/types/isBankCard.d.ts
CHANGED
|
@@ -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 工商行政管理市场主体注册号编制规则}
|
package/types/isChinese.d.ts
CHANGED
package/types/isEmail.d.ts
CHANGED
package/types/isHMCard.d.ts
CHANGED
package/types/isIPv4.d.ts
CHANGED
package/types/isIPv6.d.ts
CHANGED
package/types/isIdCard.d.ts
CHANGED
package/types/isMobile.d.ts
CHANGED
package/types/isPassport.d.ts
CHANGED
package/types/isPassword.d.ts
CHANGED
|
@@ -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
|
package/types/isPostcode.d.ts
CHANGED
package/types/isQQ.d.ts
CHANGED
|
@@ -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 法人和其他组织统一社会信用代码编码规则}
|
package/types/isSwiftCode.d.ts
CHANGED
package/types/isTWCard.d.ts
CHANGED
package/types/isTelephone.d.ts
CHANGED
package/types/isUrl.d.ts
CHANGED
package/types/isValidNumber.d.ts
CHANGED
package/types/isVehicle.d.ts
CHANGED
package/types/isWX.d.ts
CHANGED
package/types/lcm.d.ts
CHANGED
package/types/listToTree.d.ts
CHANGED
package/types/loadImage.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import getFileBlob from './getFileBlob';
|
|
|
12
12
|
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
|
|
13
13
|
*
|
|
14
14
|
* @method
|
|
15
|
-
* @alias module:
|
|
15
|
+
* @alias module:Browser.loadImageWithBlob
|
|
16
16
|
* @since 4.20.0
|
|
17
17
|
* @param {string | Blob} img 图片地址或 blob 对象
|
|
18
18
|
* @param {AjaxOptions} [ajaxOptions] ajax 请求配置项,当传入的图片为字符串时才会触发请求。
|
package/types/loadScript.d.ts
CHANGED
|
@@ -7,8 +7,7 @@ type ScriptAttribute = Pick<HTMLScriptElement, 'async' | 'crossOrigin' | 'defer'
|
|
|
7
7
|
*
|
|
8
8
|
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
|
|
9
9
|
*
|
|
10
|
-
* @
|
|
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
|
@@ -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 | 出版物上数字用法}
|
package/types/padZero.d.ts
CHANGED
package/types/parseIdCard.d.ts
CHANGED
package/types/plus.d.ts
CHANGED
package/types/replaceChar.d.ts
CHANGED
package/types/round.d.ts
CHANGED
|
@@ -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
package/types/times.d.ts
CHANGED
package/types/treeToList.d.ts
CHANGED
package/types/utils/config.d.ts
CHANGED
|
@@ -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;
|
package/types/BlobUrl.d.ts
DELETED
|
@@ -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;
|