@polyv/utils 2.11.0 → 2.12.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/cjs/image.js CHANGED
@@ -1 +1 @@
1
- "use strict";function getExtname(e){var A=(e||"").split("."),t=A[A.length-1];return t?t.toLowerCase():""}function handleCompressOptions(e){var A,t,r="number"==typeof e?{width:e}:e;return r.allowJPG=null===(A=r.allowJPG)||void 0===A||A,r.allowWebP=null!==(t=r.allowWebP)&&void 0!==t?t:"auto",r}function createURLObject(e){var A;if("undefined"!=typeof document){var t=document.createElement("a");t.href=e,A=t}else if("function"==typeof URL)try{A=new URL(/^\/\//.test(e)?"https:"+e:e)}catch(e){}return A}function genOSSCompressParams(e,A){var t="";return null==A.width&&null==A.height||(t+="/resize",A.width&&(t+=",w_"+A.width),A.height&&(t+=",h_"+A.height),t+=",limit_1"),A.allowAVIF&&"gif"!==e?t+="/format,avif":!0===A.allowWebP||"auto"===A.allowWebP&&(0,exports.supportWebP)()?t+="/format,webp/quality,Q_80":A.allowJPG&&"gif"!==e&&(t+="/format,jpg/quality,Q_80"),t}function setOSSCompressParams(e,A){var t=!1;return e=e.replace(/([?&]x-oss-process)(?:=([^&]*))?/,(function(e,r,o){return t=!0,/^image/.test(o)?r+"="+o.replace(/\/(?:resize|format|quality)[^/]*/gi,"")+A:e})),t?e:e+(-1===e.indexOf("?")?"?":"&")+"x-oss-process=image"+A}function ossCompress(e,A){var t=createURLObject(e);if(!t)return e;if(!/\.videocc\.net$/i.test(t.hostname))return e;var r=genOSSCompressParams(getExtname(t.pathname.split("/").pop()),handleCompressOptions(A));return r&&(t.search=setOSSCompressParams(t.search,r)),t.href}function genCOSCompressParams(e,A){var t="";return null!=A.width&&null!=A.height?t+="/thumbnail/".concat(A.width,"x").concat(A.height):null!=A.width?t+="/thumbnail/".concat(A.width,"x"):null!=A.height&&(t+="/thumbnail/x".concat(A.height)),A.allowAVIF&&"gif"!==e?t+="/format/avif":!0===A.allowWebP||"auto"===A.allowWebP&&(0,exports.supportWebP)()?t+="/format/webp/quality/80":A.allowJPG&&"gif"!==e&&(t+="/format/jpg/quality/80"),t}function setCOSCompressParams(e,A){var t=!1;return e=e.replace(/([?&]imageMogr2)(\/[^&]*)/,(function(e,r,o){return t=!0,r+"="+o.replace(/\/(?:thumbnail|format|quality)\/[^/]+/gi,"")+A})),t?e:e+(-1===e.indexOf("?")?"?":"&")+"imageMogr2"+A}function cosCompress(e,A){var t=createURLObject(e);if(!t)return e;if(!/(?:\.videocc\.net|\.kingswayvideo\.com)$/i.test(t.hostname))return e;var r=genCOSCompressParams(getExtname(t.pathname.split("/").pop()),handleCompressOptions(A));return r&&(t.search=setCOSCompressParams(t.search,r)),t.href}function compressHTMLImgs(e,A,t){return void 0===t&&(t=ossCompress),e?e.replace(/(<img.*?\ssrc=)(["']?)(.+?)\2(.*?>)/gi,(function(e,r,o,a,n){return r+'"'+t(a,A)+'" data-src="'+a+'"'+n})):""}Object.defineProperty(exports,"__esModule",{value:!0}),exports.supportAVIF=exports.supportWebP=void 0,exports.ossCompress=ossCompress,exports.cosCompress=cosCompress,exports.compressHTMLImgs=compressHTMLImgs,exports.supportWebP=function(){var e;return function(){if(null==e)try{e=function(){var e=document.createElement("canvas");if(e.getContext&&e.getContext("2d")){var A="image/webp";return 0===e.toDataURL(A).indexOf("data:"+A)}return!1}()}catch(A){e=!1}return e}}(),exports.supportAVIF=function(){var e;return function(){return e||(e=new Promise((function(e){var A=new Image;A.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=",A.onerror=function(){e(!1)},A.onload=function(){e(!0)},setTimeout((function(){e(!1)}),1e3)}))),e}}();
1
+ "use strict";function getExtname(e){var A=(e||"").split("."),t=A[A.length-1];return t?t.toLowerCase():""}function handleCompressOptions(e){var A,t,r="number"==typeof e?{width:e}:e;return r.allowJPG=null===(A=r.allowJPG)||void 0===A||A,r.allowWebP=null!==(t=r.allowWebP)&&void 0!==t?t:"auto",r}function createURLObject(e){var A;if("undefined"!=typeof document){var t=document.createElement("a");t.href=e,A=t}else if("function"==typeof URL)try{A=new URL(/^\/\//.test(e)?"https:"+e:e)}catch(e){}return A}function genOSSCompressParams(e,A){var t="";return null==A.width&&null==A.height||(t+="/resize",A.width&&(t+=",w_"+A.width),A.height&&(t+=",h_"+A.height),t+=",limit_1"),A.allowAVIF&&"gif"!==e?t+="/format,avif":!0===A.allowWebP||"auto"===A.allowWebP&&(0,exports.supportWebP)()?t+="/format,webp/quality,Q_80":A.allowJPG&&"gif"!==e&&(t+="/format,jpg/quality,Q_80"),t}function setOSSCompressParams(e,A){var t=!1;return e=e.replace(/([?&]x-oss-process)(?:=([^&]*))?/,(function(e,r,o){return t=!0,/^image/.test(o)?r+"="+o.replace(/\/(?:resize|format|quality)[^/]*/gi,"")+A:e})),t?e:e+(-1===e.indexOf("?")?"?":"&")+"x-oss-process=image"+A}function ossCompress(e,A){var t=createURLObject(e);if(!t)return e;if(!/\.videocc\.net$/i.test(t.hostname))return e;var r=genOSSCompressParams(getExtname(t.pathname.split("/").pop()),handleCompressOptions(A));return r&&(t.search=setOSSCompressParams(t.search,r)),t.href}function genCOSCompressParams(e,A){var t="";return null!=A.width&&null!=A.height?t+="/thumbnail/".concat(A.width,"x").concat(A.height):null!=A.width?t+="/thumbnail/".concat(A.width,"x"):null!=A.height&&(t+="/thumbnail/x".concat(A.height)),A.allowAVIF&&"gif"!==e?t+="/format/avif":!0===A.allowWebP||"auto"===A.allowWebP&&(0,exports.supportWebP)()?t+="/format/webp/quality/80":A.allowJPG&&"gif"!==e&&(t+="/format/jpg/quality/80"),t}function setCOSCompressParams(e,A){var t=!1;return e=e.replace(/([?&]imageMogr2)(\/[^&]*)/,(function(e,r,o){return t=!0,r+"="+o.replace(/\/(?:thumbnail|format|quality)\/[^/]+/gi,"")+A})),t?e:e+(-1===e.indexOf("?")?"?":"&")+"imageMogr2"+A}function cosCompress(e,A){var t=createURLObject(e);if(!t)return e;var r=getExtname(t.pathname.split("/").pop());if(!/(?:\.videocc\.net|\.kingswayvideo\.com)$/i.test(t.hostname)||"svg"===r)return e;var o=genCOSCompressParams(r,handleCompressOptions(A));return o&&(t.search=setCOSCompressParams(t.search,o)),t.href}function compressHTMLImgs(e,A,t){return void 0===t&&(t=ossCompress),e?e.replace(/(<img.*?\ssrc=)(["']?)(.+?)\2(.*?>)/gi,(function(e,r,o,a,n){return r+'"'+t(a,A)+'" data-src="'+a+'"'+n})):""}Object.defineProperty(exports,"__esModule",{value:!0}),exports.supportAVIF=exports.supportWebP=void 0,exports.ossCompress=ossCompress,exports.cosCompress=cosCompress,exports.compressHTMLImgs=compressHTMLImgs,exports.supportWebP=function(){var e;return function(){if(null==e)try{e=function(){var e=document.createElement("canvas");if(e.getContext&&e.getContext("2d")){var A="image/webp";return 0===e.toDataURL(A).indexOf("data:"+A)}return!1}()}catch(A){e=!1}return e}}(),exports.supportAVIF=function(){var e;return function(){return e||(e=new Promise((function(e){var A=new Image;A.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=",A.onerror=function(){e(!1)},A.onload=function(){e(!0)},setTimeout((function(){e(!1)}),1e3)}))),e}}();
package/cjs/string.js CHANGED
@@ -1 +1 @@
1
- "use strict";function strLen(n,e){var r,t;"number"==typeof e?e={enLen:1,nonEnLen:e}:((e=e||{}).enLen=null!==(r=e.enLen)&&void 0!==r?r:1,e.nonEnLen=null!==(t=e.nonEnLen)&&void 0!==t?t:2);for(var i=0,s=n.length-1;s>=0;s--)i+=n.charCodeAt(s)>255?e.nonEnLen||0:e.enLen||0;return i}function cutStr(n,e,r){(r=r||{}).enLen=Number(r.enLen)||1,r.nonEnLen=Number(r.nonEnLen)||2,r.ellipsis=r.ellipsis||"...";var t=strLen(n=String(n),r);if(t<=e)return n;e-=strLen(r.ellipsis,r);for(var i="",s=-1;e>0&&++s<t;)(e-=n.charCodeAt(s)>255?r.nonEnLen:r.enLen)>=0&&(i+=n.charAt(s));return i+=r.ellipsis}Object.defineProperty(exports,"__esModule",{value:!0}),exports.strLen=strLen,exports.cutStr=cutStr,exports.escapeHTML=escapeHTML,exports.unescapeHTML=unescapeHTML,exports.removeTags=removeTags,exports.nl2br=nl2br,exports.randomStr=randomStr,exports.uuidV4=uuidV4,exports.compareVersions=compareVersions,exports.maskChars=maskChars;var htmlChars=['"',"'","&","<",">"],htmlEntities=["&quot;","&#39;","&amp;","&lt;","&gt;"],charsToEntities=Object.create(null),entitiesToChars=Object.create(null);htmlChars.forEach((function(n,e){charsToEntities[n]=htmlEntities[e],entitiesToChars[htmlEntities[e]]=n}));var reHTMLChars=new RegExp("["+htmlChars.join("")+"]","g"),reHTMLEntities=new RegExp("("+htmlEntities.join("|")+")","g");function escapeHTML(n){return null==n?n:String(n).replace(reHTMLChars,(function(n){return charsToEntities[n]}))}function unescapeHTML(n){return null==n?n:String(n).replace(reHTMLEntities,(function(n){return entitiesToChars[n]}))}function removeTags(n){return null==n?"":String(n).replace(/<.+?>/g,"")}function nl2br(n){return null==n?n:String(n).replace(/\r?\n/g,"<br />")}function randomStr(n,e){if(!(n|=0)||n<0)throw new Error('"length" must be a number greater than 0');var r="";do{r+=Math.random().toString(36).substr(2)}while(r.length<n);return r=r.substr(0,n),null!=e&&(r=e+r),r}function uuidV4(){var n=Date.now();return"undefined"!=typeof performance&&"function"==typeof performance.now&&(n+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var r=(n+16*Math.random())%16|0;return n=Math.floor(n/16),("x"===e?r:3&r|8).toString(16)}))}function compareVersions(n,e){if(!n||!e)throw new Error("Please specify both verA and verB");for(var r=/(\.0+)+$/,t=String(n).replace(r,"").split("."),i=String(e).replace(r,"").split("."),s=Math.min(t.length,i.length),o=0;o<s;o++){var a=parseInt(t[o])-parseInt(i[o]);if(a)return a}return t.length-i.length}function maskChars(n,e){var r,t,i;e=e||{};var s=n.length,o=null!==(r=e.start)&&void 0!==r?r:0,a=null!==(t=e.end)&&void 0!==t?t:s-1,u=null!==(i=e.maskChar)&&void 0!==i?i:"*";if(o>=0&&a>=0&&o<=a&&a<s){var l=n.substring(0,o);return l+=new Array(a-o+2).join(u),a<s-1&&(l+=n.substring(a+1)),l}if(o>=0)return o>=s?n:n.substring(0,o)+new Array(s-o+1).join(u);if(a>=0){l=new Array(Math.min(a,s)+2).join(u);return a<s-1&&(l+=n.substring(a+1)),l}return n}
1
+ "use strict";function strLen(n,e){var r,t;"number"==typeof e?e={enLen:1,nonEnLen:e}:((e=e||{}).enLen=null!==(r=e.enLen)&&void 0!==r?r:1,e.nonEnLen=null!==(t=e.nonEnLen)&&void 0!==t?t:2);for(var s=0,i=n.length-1;i>=0;i--)s+=n.charCodeAt(i)>255?e.nonEnLen||0:e.enLen||0;return s}function cutStr(n,e,r){(r=r||{}).enLen=Number(r.enLen)||1,r.nonEnLen=Number(r.nonEnLen)||2,r.ellipsis=r.ellipsis||"...";var t=strLen(n=String(n),r);if(t<=e)return n;e-=strLen(r.ellipsis,r);for(var s="",i=-1;e>0&&++i<t;)(e-=n.charCodeAt(i)>255?r.nonEnLen:r.enLen)>=0&&(s+=n.charAt(i));return s+=r.ellipsis}Object.defineProperty(exports,"__esModule",{value:!0}),exports.strLen=strLen,exports.cutStr=cutStr,exports.escapeHTML=escapeHTML,exports.unescapeHTML=unescapeHTML,exports.removeTags=removeTags,exports.nl2br=nl2br,exports.randomStr=randomStr,exports.uuidV4=uuidV4,exports.compareVersions=compareVersions,exports.maskChars=maskChars;var htmlChars=['"',"'","&","<",">"," "],htmlEntities=["&quot;","&#39;","&amp;","&lt;","&gt;","&nbsp;"],charsToEntities=Object.create(null),entitiesToChars=Object.create(null);htmlChars.forEach((function(n,e){charsToEntities[n]=htmlEntities[e],entitiesToChars[htmlEntities[e]]=n}));var reHTMLChars=new RegExp("["+htmlChars.join("")+"]","g"),reHTMLEntities=new RegExp("("+htmlEntities.join("|")+")","g");function escapeHTML(n){return null==n?n:String(n).replace(reHTMLChars,(function(n){return charsToEntities[n]}))}function unescapeHTML(n){return null==n?n:String(n).replace(reHTMLEntities,(function(n){return entitiesToChars[n]}))}function removeTags(n){return null==n?"":String(n).replace(/<.+?>/g,"")}function nl2br(n){return null==n?n:String(n).replace(/\r?\n/g,"<br />")}function randomStr(n,e){if(!(n|=0)||n<0)throw new Error('"length" must be a number greater than 0');var r="";do{r+=Math.random().toString(36).substr(2)}while(r.length<n);return r=r.substr(0,n),null!=e&&(r=e+r),r}function uuidV4(){var n=Date.now();return"undefined"!=typeof performance&&"function"==typeof performance.now&&(n+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var r=(n+16*Math.random())%16|0;return n=Math.floor(n/16),("x"===e?r:3&r|8).toString(16)}))}function compareVersions(n,e){if(!n||!e)throw new Error("Please specify both verA and verB");for(var r=/(\.0+)+$/,t=String(n).replace(r,"").split("."),s=String(e).replace(r,"").split("."),i=Math.min(t.length,s.length),o=0;o<i;o++){var a=parseInt(t[o])-parseInt(s[o]);if(a)return a}return t.length-s.length}function maskChars(n,e){var r,t,s;e=e||{};var i=n.length,o=null!==(r=e.start)&&void 0!==r?r:0,a=null!==(t=e.end)&&void 0!==t?t:i-1,u=null!==(s=e.maskChar)&&void 0!==s?s:"*";if(o>=0&&a>=0&&o<=a&&a<i){var l=n.substring(0,o);return l+=new Array(a-o+2).join(u),a<i-1&&(l+=n.substring(a+1)),l}if(o>=0)return o>=i?n:n.substring(0,o)+new Array(i-o+1).join(u);if(a>=0){l=new Array(Math.min(a,i)+2).join(u);return a<i-1&&(l+=n.substring(a+1)),l}return n}
package/es/image.js CHANGED
@@ -1 +1 @@
1
- export const supportWebP=(()=>{let A;return()=>{if(null==A)try{A=function(){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}()}catch(e){A=!1}return A}})();export const supportAVIF=(()=>{let A;return()=>(A||(A=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)}))),A)})();function getExtname(A){const e=(A||"").split("."),t=e[e.length-1];return t?t.toLowerCase():""}function handleCompressOptions(A){var e,t;const r="number"==typeof A?{width:A}:A;return r.allowJPG=null===(e=r.allowJPG)||void 0===e||e,r.allowWebP=null!==(t=r.allowWebP)&&void 0!==t?t:"auto",r}function createURLObject(A){let e;if("undefined"!=typeof document){const t=document.createElement("a");t.href=A,e=t}else if("function"==typeof URL)try{e=new URL(/^\/\//.test(A)?"https:"+A:A)}catch(A){}return e}function genOSSCompressParams(A,e){let t="";return null==e.width&&null==e.height||(t+="/resize",e.width&&(t+=",w_"+e.width),e.height&&(t+=",h_"+e.height),t+=",limit_1"),e.allowAVIF&&"gif"!==A?t+="/format,avif":!0===e.allowWebP||"auto"===e.allowWebP&&supportWebP()?t+="/format,webp/quality,Q_80":e.allowJPG&&"gif"!==A&&(t+="/format,jpg/quality,Q_80"),t}function setOSSCompressParams(A,e){let t=!1;return A=A.replace(/([?&]x-oss-process)(?:=([^&]*))?/,((A,r,o)=>(t=!0,/^image/.test(o)?r+"="+o.replace(/\/(?:resize|format|quality)[^/]*/gi,"")+e:A))),t?A:A+(-1===A.indexOf("?")?"?":"&")+"x-oss-process=image"+e}export function ossCompress(A,e){const t=createURLObject(A);if(!t)return A;if(!/\.videocc\.net$/i.test(t.hostname))return A;const r=genOSSCompressParams(getExtname(t.pathname.split("/").pop()),handleCompressOptions(e));return r&&(t.search=setOSSCompressParams(t.search,r)),t.href}function genCOSCompressParams(A,e){let t="";return null!=e.width&&null!=e.height?t+=`/thumbnail/${e.width}x${e.height}`:null!=e.width?t+=`/thumbnail/${e.width}x`:null!=e.height&&(t+=`/thumbnail/x${e.height}`),e.allowAVIF&&"gif"!==A?t+="/format/avif":!0===e.allowWebP||"auto"===e.allowWebP&&supportWebP()?t+="/format/webp/quality/80":e.allowJPG&&"gif"!==A&&(t+="/format/jpg/quality/80"),t}function setCOSCompressParams(A,e){let t=!1;return A=A.replace(/([?&]imageMogr2)(\/[^&]*)/,((A,r,o)=>(t=!0,r+"="+o.replace(/\/(?:thumbnail|format|quality)\/[^/]+/gi,"")+e))),t?A:A+(-1===A.indexOf("?")?"?":"&")+"imageMogr2"+e}export function cosCompress(A,e){const t=createURLObject(A);if(!t)return A;if(!/(?:\.videocc\.net|\.kingswayvideo\.com)$/i.test(t.hostname))return A;const r=genCOSCompressParams(getExtname(t.pathname.split("/").pop()),handleCompressOptions(e));return r&&(t.search=setCOSCompressParams(t.search,r)),t.href}export function compressHTMLImgs(A,e,t=ossCompress){return A?A.replace(/(<img.*?\ssrc=)(["']?)(.+?)\2(.*?>)/gi,((A,r,o,a,n)=>r+'"'+t(a,e)+'" data-src="'+a+'"'+n)):""}
1
+ export const supportWebP=(()=>{let A;return()=>{if(null==A)try{A=function(){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}()}catch(e){A=!1}return A}})();export const supportAVIF=(()=>{let A;return()=>(A||(A=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)}))),A)})();function getExtname(A){const e=(A||"").split("."),t=e[e.length-1];return t?t.toLowerCase():""}function handleCompressOptions(A){var e,t;const o="number"==typeof A?{width:A}:A;return o.allowJPG=null===(e=o.allowJPG)||void 0===e||e,o.allowWebP=null!==(t=o.allowWebP)&&void 0!==t?t:"auto",o}function createURLObject(A){let e;if("undefined"!=typeof document){const t=document.createElement("a");t.href=A,e=t}else if("function"==typeof URL)try{e=new URL(/^\/\//.test(A)?"https:"+A:A)}catch(A){}return e}function genOSSCompressParams(A,e){let t="";return null==e.width&&null==e.height||(t+="/resize",e.width&&(t+=",w_"+e.width),e.height&&(t+=",h_"+e.height),t+=",limit_1"),e.allowAVIF&&"gif"!==A?t+="/format,avif":!0===e.allowWebP||"auto"===e.allowWebP&&supportWebP()?t+="/format,webp/quality,Q_80":e.allowJPG&&"gif"!==A&&(t+="/format,jpg/quality,Q_80"),t}function setOSSCompressParams(A,e){let t=!1;return A=A.replace(/([?&]x-oss-process)(?:=([^&]*))?/,((A,o,r)=>(t=!0,/^image/.test(r)?o+"="+r.replace(/\/(?:resize|format|quality)[^/]*/gi,"")+e:A))),t?A:A+(-1===A.indexOf("?")?"?":"&")+"x-oss-process=image"+e}export function ossCompress(A,e){const t=createURLObject(A);if(!t)return A;if(!/\.videocc\.net$/i.test(t.hostname))return A;const o=genOSSCompressParams(getExtname(t.pathname.split("/").pop()),handleCompressOptions(e));return o&&(t.search=setOSSCompressParams(t.search,o)),t.href}function genCOSCompressParams(A,e){let t="";return null!=e.width&&null!=e.height?t+=`/thumbnail/${e.width}x${e.height}`:null!=e.width?t+=`/thumbnail/${e.width}x`:null!=e.height&&(t+=`/thumbnail/x${e.height}`),e.allowAVIF&&"gif"!==A?t+="/format/avif":!0===e.allowWebP||"auto"===e.allowWebP&&supportWebP()?t+="/format/webp/quality/80":e.allowJPG&&"gif"!==A&&(t+="/format/jpg/quality/80"),t}function setCOSCompressParams(A,e){let t=!1;return A=A.replace(/([?&]imageMogr2)(\/[^&]*)/,((A,o,r)=>(t=!0,o+"="+r.replace(/\/(?:thumbnail|format|quality)\/[^/]+/gi,"")+e))),t?A:A+(-1===A.indexOf("?")?"?":"&")+"imageMogr2"+e}export function cosCompress(A,e){const t=createURLObject(A);if(!t)return A;const o=getExtname(t.pathname.split("/").pop());if(!/(?:\.videocc\.net|\.kingswayvideo\.com)$/i.test(t.hostname)||"svg"===o)return A;const r=genCOSCompressParams(o,handleCompressOptions(e));return r&&(t.search=setCOSCompressParams(t.search,r)),t.href}export function compressHTMLImgs(A,e,t=ossCompress){return A?A.replace(/(<img.*?\ssrc=)(["']?)(.+?)\2(.*?>)/gi,((A,o,r,a,n)=>o+'"'+t(a,e)+'" data-src="'+a+'"'+n)):""}
package/es/string.js CHANGED
@@ -1 +1 @@
1
- export function strLen(n,e){var t,r;"number"==typeof e?e={enLen:1,nonEnLen:e}:((e=e||{}).enLen=null!==(t=e.enLen)&&void 0!==t?t:1,e.nonEnLen=null!==(r=e.nonEnLen)&&void 0!==r?r:2);let o=0;for(let t=n.length-1;t>=0;t--)o+=n.charCodeAt(t)>255?e.nonEnLen||0:e.enLen||0;return o}export function cutStr(n,e,t){(t=t||{}).enLen=Number(t.enLen)||1,t.nonEnLen=Number(t.nonEnLen)||2,t.ellipsis=t.ellipsis||"...";const r=strLen(n=String(n),t);if(r<=e)return n;e-=strLen(t.ellipsis,t);let o="",i=-1;for(;e>0&&++i<r;)(e-=n.charCodeAt(i)>255?t.nonEnLen:t.enLen)>=0&&(o+=n.charAt(i));return o+=t.ellipsis,o}const htmlChars=['"',"'","&","<",">"],htmlEntities=["&quot;","&#39;","&amp;","&lt;","&gt;"],charsToEntities=Object.create(null),entitiesToChars=Object.create(null);htmlChars.forEach(((n,e)=>{charsToEntities[n]=htmlEntities[e],entitiesToChars[htmlEntities[e]]=n}));const reHTMLChars=new RegExp("["+htmlChars.join("")+"]","g"),reHTMLEntities=new RegExp("("+htmlEntities.join("|")+")","g");export function escapeHTML(n){return null==n?n:String(n).replace(reHTMLChars,(n=>charsToEntities[n]))}export function unescapeHTML(n){return null==n?n:String(n).replace(reHTMLEntities,(n=>entitiesToChars[n]))}export function removeTags(n){return null==n?"":String(n).replace(/<.+?>/g,"")}export function nl2br(n){return null==n?n:String(n).replace(/\r?\n/g,"<br />")}export function randomStr(n,e){if(!(n|=0)||n<0)throw new Error('"length" must be a number greater than 0');let t="";do{t+=Math.random().toString(36).substr(2)}while(t.length<n);return t=t.substr(0,n),null!=e&&(t=e+t),t}export function uuidV4(){let n=Date.now();return"undefined"!=typeof performance&&"function"==typeof performance.now&&(n+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){const t=(n+16*Math.random())%16|0;return n=Math.floor(n/16),("x"===e?t:3&t|8).toString(16)}))}export function compareVersions(n,e){if(!n||!e)throw new Error("Please specify both verA and verB");const t=/(\.0+)+$/,r=String(n).replace(t,"").split("."),o=String(e).replace(t,"").split("."),i=Math.min(r.length,o.length);for(let n=0;n<i;n++){const e=parseInt(r[n])-parseInt(o[n]);if(e)return e}return r.length-o.length}export function maskChars(n,e){var t,r,o;e=e||{};const i=n.length,l=null!==(t=e.start)&&void 0!==t?t:0,s=null!==(r=e.end)&&void 0!==r?r:i-1,a=null!==(o=e.maskChar)&&void 0!==o?o:"*";if(l>=0&&s>=0&&l<=s&&s<i){let e=n.substring(0,l);return e+=new Array(s-l+2).join(a),s<i-1&&(e+=n.substring(s+1)),e}if(l>=0)return l>=i?n:n.substring(0,l)+new Array(i-l+1).join(a);if(s>=0){let e=new Array(Math.min(s,i)+2).join(a);return s<i-1&&(e+=n.substring(s+1)),e}return n}
1
+ export function strLen(n,e){var t,r;"number"==typeof e?e={enLen:1,nonEnLen:e}:((e=e||{}).enLen=null!==(t=e.enLen)&&void 0!==t?t:1,e.nonEnLen=null!==(r=e.nonEnLen)&&void 0!==r?r:2);let o=0;for(let t=n.length-1;t>=0;t--)o+=n.charCodeAt(t)>255?e.nonEnLen||0:e.enLen||0;return o}export function cutStr(n,e,t){(t=t||{}).enLen=Number(t.enLen)||1,t.nonEnLen=Number(t.nonEnLen)||2,t.ellipsis=t.ellipsis||"...";const r=strLen(n=String(n),t);if(r<=e)return n;e-=strLen(t.ellipsis,t);let o="",i=-1;for(;e>0&&++i<r;)(e-=n.charCodeAt(i)>255?t.nonEnLen:t.enLen)>=0&&(o+=n.charAt(i));return o+=t.ellipsis,o}const htmlChars=['"',"'","&","<",">"," "],htmlEntities=["&quot;","&#39;","&amp;","&lt;","&gt;","&nbsp;"],charsToEntities=Object.create(null),entitiesToChars=Object.create(null);htmlChars.forEach(((n,e)=>{charsToEntities[n]=htmlEntities[e],entitiesToChars[htmlEntities[e]]=n}));const reHTMLChars=new RegExp("["+htmlChars.join("")+"]","g"),reHTMLEntities=new RegExp("("+htmlEntities.join("|")+")","g");export function escapeHTML(n){return null==n?n:String(n).replace(reHTMLChars,(n=>charsToEntities[n]))}export function unescapeHTML(n){return null==n?n:String(n).replace(reHTMLEntities,(n=>entitiesToChars[n]))}export function removeTags(n){return null==n?"":String(n).replace(/<.+?>/g,"")}export function nl2br(n){return null==n?n:String(n).replace(/\r?\n/g,"<br />")}export function randomStr(n,e){if(!(n|=0)||n<0)throw new Error('"length" must be a number greater than 0');let t="";do{t+=Math.random().toString(36).substr(2)}while(t.length<n);return t=t.substr(0,n),null!=e&&(t=e+t),t}export function uuidV4(){let n=Date.now();return"undefined"!=typeof performance&&"function"==typeof performance.now&&(n+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){const t=(n+16*Math.random())%16|0;return n=Math.floor(n/16),("x"===e?t:3&t|8).toString(16)}))}export function compareVersions(n,e){if(!n||!e)throw new Error("Please specify both verA and verB");const t=/(\.0+)+$/,r=String(n).replace(t,"").split("."),o=String(e).replace(t,"").split("."),i=Math.min(r.length,o.length);for(let n=0;n<i;n++){const e=parseInt(r[n])-parseInt(o[n]);if(e)return e}return r.length-o.length}export function maskChars(n,e){var t,r,o;e=e||{};const i=n.length,s=null!==(t=e.start)&&void 0!==t?t:0,l=null!==(r=e.end)&&void 0!==r?r:i-1,a=null!==(o=e.maskChar)&&void 0!==o?o:"*";if(s>=0&&l>=0&&s<=l&&l<i){let e=n.substring(0,s);return e+=new Array(l-s+2).join(a),l<i-1&&(e+=n.substring(l+1)),e}if(s>=0)return s>=i?n:n.substring(0,s)+new Array(i-s+1).join(a);if(l>=0){let e=new Array(Math.min(l,i)+2).join(a);return l<i-1&&(e+=n.substring(l+1)),e}return n}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polyv/utils",
3
- "version": "2.11.0",
3
+ "version": "2.12.0-beta.1",
4
4
  "description": "Utility functions of Polyv frontend development.",
5
5
  "keywords": [
6
6
  "polyv",