@polyv/utils 2.19.0-beta.1 → 2.19.0-beta.2

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/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 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}
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){var t;(r=r||{}).enLen=Number(r.enLen)||1,r.nonEnLen=Number(r.nonEnLen)||2,r.ellipsis=null!==(t=r.ellipsis)&&void 0!==t?t:"...";var i=strLen(n=String(n),r);if(i<=e)return n;e-=strLen(r.ellipsis,r);for(var s="",o=-1;e>0&&++o<i;)(e-=n.charCodeAt(o)>255?r.nonEnLen:r.enLen)>=0&&(s+=n.charAt(o));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("."),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}
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;","&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}
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){var r;(t=t||{}).enLen=Number(t.enLen)||1,t.nonEnLen=Number(t.nonEnLen)||2,t.ellipsis=null!==(r=t.ellipsis)&&void 0!==r?r:"...";const o=strLen(n=String(n),t);if(o<=e)return n;e-=strLen(t.ellipsis,t);let i="",l=-1;for(;e>0&&++l<o;)(e-=n.charCodeAt(l)>255?t.nonEnLen:t.enLen)>=0&&(i+=n.charAt(l));return i+=t.ellipsis,i}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,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}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polyv/utils",
3
- "version": "2.19.0-beta.1",
3
+ "version": "2.19.0-beta.2",
4
4
  "description": "Utility functions of Polyv frontend development.",
5
5
  "keywords": [
6
6
  "polyv",