@polyv/utils 2.0.0-beta.4 → 2.1.0-beta.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/dist/cjs/boolean.d.ts +1 -1
- package/dist/cjs/image.d.ts +49 -0
- package/dist/cjs/image.js +1 -0
- package/dist/cjs/net.d.ts +12 -1
- package/dist/cjs/net.js +1 -1
- package/dist/es/boolean.d.ts +1 -1
- package/dist/es/image.d.ts +49 -0
- package/dist/es/image.js +1 -0
- package/dist/es/net.d.ts +12 -1
- package/dist/es/net.js +1 -1
- package/package.json +1 -1
package/dist/cjs/boolean.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare function ynToBool(value: YOrN): boolean;
|
|
|
24
24
|
* @param defaultValue 当 value 为非法值时的默认值。
|
|
25
25
|
* @return 布尔值。
|
|
26
26
|
*/
|
|
27
|
-
export declare function ynToBool(value: unknown, defaultValue
|
|
27
|
+
export declare function ynToBool(value: unknown, defaultValue: YOrN): boolean;
|
|
28
28
|
/**
|
|
29
29
|
* 检查指定数组元素的值是否都为 Y。
|
|
30
30
|
* @param values 指定数组。
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 本模块提供图片操作相关方法。
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 检查当前浏览器是否支持 WebP 格式。
|
|
7
|
+
* @returns 当前浏览器是否支持 WebP 格式。
|
|
8
|
+
*/
|
|
9
|
+
export declare function supportWebP(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* 检查当前浏览器是否支持 AVIF 格式(注意,本函数是异步函数)。
|
|
12
|
+
* @returns 当前浏览器是否支持 AVIF 格式。
|
|
13
|
+
*/
|
|
14
|
+
export declare function supportAVIF(): Promise<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* 压缩选项。
|
|
17
|
+
*/
|
|
18
|
+
export interface IOSSCompressOptions {
|
|
19
|
+
/**
|
|
20
|
+
* 压缩后的图片宽度。
|
|
21
|
+
*/
|
|
22
|
+
width?: number;
|
|
23
|
+
/**
|
|
24
|
+
* 压缩后的图片高度。
|
|
25
|
+
*/
|
|
26
|
+
height?: number;
|
|
27
|
+
/**
|
|
28
|
+
* 是否允许转换为 WebP。
|
|
29
|
+
*/
|
|
30
|
+
allowWebP?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 是否允许转换为 AVIF。
|
|
33
|
+
*/
|
|
34
|
+
allowAVIF?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 如果指定图片 URL 的域名是 OSS 域名,则追加 OSS 图片压缩参数。
|
|
38
|
+
* @param url 指定图片 URL。
|
|
39
|
+
* @param options 压缩选项。
|
|
40
|
+
* @returns 处理后的图片 URL。
|
|
41
|
+
* @example
|
|
42
|
+
* ```javascript
|
|
43
|
+
* ossCompress(url, {
|
|
44
|
+
* width: 300,
|
|
45
|
+
* allowWebp: true
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function ossCompress(url: string, options: IOSSCompressOptions): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function supportWebP(){var A=document.createElement("canvas");if(A.getContext&&A.getContext("2d")){var e="image/webp";return 0===A.toDataURL(e).indexOf("data:"+e)}return!1}function supportAVIF(){return new Promise((function(A){var e=new Image;e.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=",e.onerror=function(){A(!1)},e.onload=function(){A(!0)},setTimeout((function(){A(!1)}),1e3)}))}function ossCompress(A,e){var t=document.createElement("a");t.href=A;var o=t.search;if("liveimages.videocc.net"!==t.hostname.toLowerCase()||/(?:\?|&)x-oss-process(?:=|&|$)/.test(o))return A;var s="";return null==e.width&&null==e.height||(s+="/resize,mfit",e.width&&(s+=",w_"+e.width),e.height&&(s+=",h_"+e.height),s+=",limit_1"),e.allowAVIF?s+="/format,avif":e.allowWebP&&(s+="/format,webp"),s&&(s="x-oss-process=image"+s,A+=(-1===A.indexOf("?")?"?":"&")+s),A}Object.defineProperty(exports,"__esModule",{value:!0}),exports.ossCompress=exports.supportAVIF=exports.supportWebP=void 0,exports.supportWebP=supportWebP,exports.supportAVIF=supportAVIF,exports.ossCompress=ossCompress;
|
package/dist/cjs/net.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare function startsWithProtocol(str: string, protocols?: string[]): b
|
|
|
21
21
|
/**
|
|
22
22
|
* 替换目标字符串中的 URL 协议。如果字符串中不包含协议,则加上协议。
|
|
23
23
|
* @param url 目标字符串。
|
|
24
|
-
* @param protocol
|
|
24
|
+
* @param protocol 协议(不含冒号和斜杠)。
|
|
25
25
|
* @return 替换结果。
|
|
26
26
|
* @example
|
|
27
27
|
* ```javascript
|
|
@@ -30,3 +30,14 @@ export declare function startsWithProtocol(str: string, protocols?: string[]): b
|
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
32
|
export declare function changeProtocol(url: string, protocol: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* 标准化(如果当前页面协议为 http,则为 http,否则为 https)目标字符串中的 URL 协议。
|
|
35
|
+
* @param url 目标字符串。
|
|
36
|
+
* @returns 标准化结果。
|
|
37
|
+
* ```javascript
|
|
38
|
+
* // 当前页面协议为 http 时,结果是 'http://abc.com'
|
|
39
|
+
* // 否则结果是 'https://abc.com'
|
|
40
|
+
* normalizeProtocol('http://abc.com');
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function normalizeProtocol(url: string): string;
|
package/dist/cjs/net.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.changeProtocol=exports.startsWithProtocol=void 0;var reProtocol=/^(?:([a-z]+):)?\/{2,3}/i;function startsWithProtocol(o,t){var r=reProtocol.test(o);if(r&&t){for(var e=(RegExp.$1||"").toLowerCase(),c=t.length-1;c>=0;c--)if(e===t[c].toLowerCase())return!0;return!1}return r}function changeProtocol(o,t){return reProtocol.test(t)||(t+="://"),startsWithProtocol(o)?o.replace(reProtocol,t):t+o}exports.startsWithProtocol=startsWithProtocol,exports.changeProtocol=changeProtocol;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.normalizeProtocol=exports.changeProtocol=exports.startsWithProtocol=void 0;var reProtocol=/^(?:([a-z]+):)?\/{2,3}/i;function startsWithProtocol(o,t){var r=reProtocol.test(o);if(r&&t){for(var e=(RegExp.$1||"").toLowerCase(),c=t.length-1;c>=0;c--)if(e===t[c].toLowerCase())return!0;return!1}return r}function changeProtocol(o,t){return reProtocol.test(t)||(t+="://"),startsWithProtocol(o)?o.replace(reProtocol,t):t+o}function normalizeProtocol(o){return changeProtocol(o,"http:"===window.location.protocol?"http":"https")}exports.startsWithProtocol=startsWithProtocol,exports.changeProtocol=changeProtocol,exports.normalizeProtocol=normalizeProtocol;
|
package/dist/es/boolean.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare function ynToBool(value: YOrN): boolean;
|
|
|
24
24
|
* @param defaultValue 当 value 为非法值时的默认值。
|
|
25
25
|
* @return 布尔值。
|
|
26
26
|
*/
|
|
27
|
-
export declare function ynToBool(value: unknown, defaultValue
|
|
27
|
+
export declare function ynToBool(value: unknown, defaultValue: YOrN): boolean;
|
|
28
28
|
/**
|
|
29
29
|
* 检查指定数组元素的值是否都为 Y。
|
|
30
30
|
* @param values 指定数组。
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 本模块提供图片操作相关方法。
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 检查当前浏览器是否支持 WebP 格式。
|
|
7
|
+
* @returns 当前浏览器是否支持 WebP 格式。
|
|
8
|
+
*/
|
|
9
|
+
export declare function supportWebP(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* 检查当前浏览器是否支持 AVIF 格式(注意,本函数是异步函数)。
|
|
12
|
+
* @returns 当前浏览器是否支持 AVIF 格式。
|
|
13
|
+
*/
|
|
14
|
+
export declare function supportAVIF(): Promise<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* 压缩选项。
|
|
17
|
+
*/
|
|
18
|
+
export interface IOSSCompressOptions {
|
|
19
|
+
/**
|
|
20
|
+
* 压缩后的图片宽度。
|
|
21
|
+
*/
|
|
22
|
+
width?: number;
|
|
23
|
+
/**
|
|
24
|
+
* 压缩后的图片高度。
|
|
25
|
+
*/
|
|
26
|
+
height?: number;
|
|
27
|
+
/**
|
|
28
|
+
* 是否允许转换为 WebP。
|
|
29
|
+
*/
|
|
30
|
+
allowWebP?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 是否允许转换为 AVIF。
|
|
33
|
+
*/
|
|
34
|
+
allowAVIF?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 如果指定图片 URL 的域名是 OSS 域名,则追加 OSS 图片压缩参数。
|
|
38
|
+
* @param url 指定图片 URL。
|
|
39
|
+
* @param options 压缩选项。
|
|
40
|
+
* @returns 处理后的图片 URL。
|
|
41
|
+
* @example
|
|
42
|
+
* ```javascript
|
|
43
|
+
* ossCompress(url, {
|
|
44
|
+
* width: 300,
|
|
45
|
+
* allowWebp: true
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function ossCompress(url: string, options: IOSSCompressOptions): string;
|
package/dist/es/image.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function supportWebP(){const A=document.createElement("canvas");if(A.getContext&&A.getContext("2d")){const e="image/webp";return 0===A.toDataURL(e).indexOf("data:"+e)}return!1}export function supportAVIF(){return new Promise((A=>{const e=new Image;e.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=",e.onerror=()=>{A(!1)},e.onload=()=>{A(!0)},setTimeout((()=>{A(!1)}),1e3)}))}export function ossCompress(A,e){const t=document.createElement("a");t.href=A;const o=t.search;if("liveimages.videocc.net"!==t.hostname.toLowerCase()||/(?:\?|&)x-oss-process(?:=|&|$)/.test(o))return A;let a="";return null==e.width&&null==e.height||(a+="/resize,mfit",e.width&&(a+=",w_"+e.width),e.height&&(a+=",h_"+e.height),a+=",limit_1"),e.allowAVIF?a+="/format,avif":e.allowWebP&&(a+="/format,webp"),a&&(a="x-oss-process=image"+a,A+=(-1===A.indexOf("?")?"?":"&")+a),A}
|
package/dist/es/net.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare function startsWithProtocol(str: string, protocols?: string[]): b
|
|
|
21
21
|
/**
|
|
22
22
|
* 替换目标字符串中的 URL 协议。如果字符串中不包含协议,则加上协议。
|
|
23
23
|
* @param url 目标字符串。
|
|
24
|
-
* @param protocol
|
|
24
|
+
* @param protocol 协议(不含冒号和斜杠)。
|
|
25
25
|
* @return 替换结果。
|
|
26
26
|
* @example
|
|
27
27
|
* ```javascript
|
|
@@ -30,3 +30,14 @@ export declare function startsWithProtocol(str: string, protocols?: string[]): b
|
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
32
|
export declare function changeProtocol(url: string, protocol: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* 标准化(如果当前页面协议为 http,则为 http,否则为 https)目标字符串中的 URL 协议。
|
|
35
|
+
* @param url 目标字符串。
|
|
36
|
+
* @returns 标准化结果。
|
|
37
|
+
* ```javascript
|
|
38
|
+
* // 当前页面协议为 http 时,结果是 'http://abc.com'
|
|
39
|
+
* // 否则结果是 'https://abc.com'
|
|
40
|
+
* normalizeProtocol('http://abc.com');
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function normalizeProtocol(url: string): string;
|
package/dist/es/net.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const reProtocol=/^(?:([a-z]+):)?\/{2,3}/i;export function startsWithProtocol(o,t){const r=reProtocol.test(o);if(r&&t){const o=(RegExp.$1||"").toLowerCase();for(let r=t.length-1;r>=0;r--)if(o===t[r].toLowerCase())return!0;return!1}return r}export function changeProtocol(o,t){return reProtocol.test(t)||(t+="://"),startsWithProtocol(o)?o.replace(reProtocol,t):t+o}
|
|
1
|
+
const reProtocol=/^(?:([a-z]+):)?\/{2,3}/i;export function startsWithProtocol(o,t){const r=reProtocol.test(o);if(r&&t){const o=(RegExp.$1||"").toLowerCase();for(let r=t.length-1;r>=0;r--)if(o===t[r].toLowerCase())return!0;return!1}return r}export function changeProtocol(o,t){return reProtocol.test(t)||(t+="://"),startsWithProtocol(o)?o.replace(reProtocol,t):t+o}export function normalizeProtocol(o){return changeProtocol(o,"http:"===window.location.protocol?"http":"https")}
|