@polyv/utils 2.2.0-beta.1 → 2.3.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.
@@ -59,6 +59,12 @@ export declare function cutStr(str: string, length: number, options?: ICutStrOpt
59
59
  * @return 替换后的字符串。
60
60
  */
61
61
  export declare function escapeHTML(str: string): string;
62
+ /**
63
+ * 把指定字符串中的 HTML 实体替换成 HTML 预留字符。
64
+ * @param str 指定字符串。
65
+ * @return 替换后的字符串。
66
+ */
67
+ export declare function unescapeHTML(str: string): string;
62
68
  /**
63
69
  * 移除指定字符串中的 HTML 标签。
64
70
  * @param str 指定字符串。
@@ -1 +1 @@
1
- "use strict";function strLen(e,r){var n,t;"number"==typeof r?r={enLen:1,nonEnLen:r}:((r=r||{}).enLen=null!==(n=r.enLen)&&void 0!==n?n:1,r.nonEnLen=null!==(t=r.nonEnLen)&&void 0!==t?t:2);for(var o=0,s=e.length-1;s>=0;s--)o+=e.charCodeAt(s)>255?r.nonEnLen||0:r.enLen||0;return o}function cutStr(e,r,n){(n=n||{}).enLen=Number(n.enLen)||1,n.nonEnLen=Number(n.nonEnLen)||2,n.ellipsis=n.ellipsis||"...";var t=strLen(e=String(e),n);if(t<=r)return e;r-=strLen(n.ellipsis,n);for(var o="",s=-1;r>0&&++s<t;)(r-=e.charCodeAt(s)>255?n.nonEnLen:n.enLen)>=0&&(o+=e.charAt(s));return o+=n.ellipsis}function escapeHTML(e){if(null==e)return e;var r={'"':"&quot;","'":"&#39;","&":"&amp;","<":"&lt;",">":"&gt;"};return String(e).replace(/["'&<>]/g,(function(e){return r[e]}))}function removeTags(e){return null==e?"":String(e).replace(/<.+?>/g,"")}function nl2br(e){return null==e?e:String(e).replace(/\r?\n/g,"<br />")}function randomStr(e,r){if(!(e|=0)||e<0)throw new Error('"length" must be a number greater than 0');var n="";do{n+=Math.random().toString(36).substr(2)}while(n.length<e);return n=n.substr(0,e),null!=r&&(n=r+n),n}function uuidV4(){var e=Date.now();return"undefined"!=typeof performance&&"function"==typeof performance.now&&(e+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(r){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===r?n:3&n|8).toString(16)}))}function compareVersions(e,r){if(!e||!r)throw new Error("Please specify both verA and verB");for(var n=/(\.0+)+$/,t=String(e).replace(n,"").split("."),o=String(r).replace(n,"").split("."),s=Math.min(t.length,o.length),a=0;a<s;a++){var u=parseInt(t[a])-parseInt(o[a]);if(u)return u}return t.length-o.length}Object.defineProperty(exports,"__esModule",{value:!0}),exports.compareVersions=exports.uuidV4=exports.randomStr=exports.nl2br=exports.removeTags=exports.escapeHTML=exports.cutStr=exports.strLen=void 0,exports.strLen=strLen,exports.cutStr=cutStr,exports.escapeHTML=escapeHTML,exports.removeTags=removeTags,exports.nl2br=nl2br,exports.randomStr=randomStr,exports.uuidV4=uuidV4,exports.compareVersions=compareVersions;
1
+ "use strict";function strLen(e,n){var r,t;"number"==typeof n?n={enLen:1,nonEnLen:n}:((n=n||{}).enLen=null!==(r=n.enLen)&&void 0!==r?r:1,n.nonEnLen=null!==(t=n.nonEnLen)&&void 0!==t?t:2);for(var o=0,s=e.length-1;s>=0;s--)o+=e.charCodeAt(s)>255?n.nonEnLen||0:n.enLen||0;return o}function cutStr(e,n,r){(r=r||{}).enLen=Number(r.enLen)||1,r.nonEnLen=Number(r.nonEnLen)||2,r.ellipsis=r.ellipsis||"...";var t=strLen(e=String(e),r);if(t<=n)return e;n-=strLen(r.ellipsis,r);for(var o="",s=-1;n>0&&++s<t;)(n-=e.charCodeAt(s)>255?r.nonEnLen:r.enLen)>=0&&(o+=e.charAt(s));return o+=r.ellipsis}Object.defineProperty(exports,"__esModule",{value:!0}),exports.compareVersions=exports.uuidV4=exports.randomStr=exports.nl2br=exports.removeTags=exports.unescapeHTML=exports.escapeHTML=exports.cutStr=exports.strLen=void 0,exports.strLen=strLen,exports.cutStr=cutStr;var htmlChars=['"',"'","&","<",">"],htmlEntities=["&quot;","&#39;","&amp;","&lt;","&gt;"],charsToEntities=Object.create(null),entitiesToChars=Object.create(null);htmlChars.forEach((function(e,n){charsToEntities[e]=htmlEntities[n],entitiesToChars[htmlEntities[n]]=e}));var reHTMLChars=new RegExp("["+htmlChars.join("")+"]","g"),reHTMLEntities=new RegExp("("+htmlEntities.join("|")+")","g");function escapeHTML(e){return null==e?e:String(e).replace(reHTMLChars,(function(e){return charsToEntities[e]}))}function unescapeHTML(e){return null==e?e:String(e).replace(reHTMLEntities,(function(e){return entitiesToChars[e]}))}function removeTags(e){return null==e?"":String(e).replace(/<.+?>/g,"")}function nl2br(e){return null==e?e:String(e).replace(/\r?\n/g,"<br />")}function randomStr(e,n){if(!(e|=0)||e<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<e);return r=r.substr(0,e),null!=n&&(r=n+r),r}function uuidV4(){var e=Date.now();return"undefined"!=typeof performance&&"function"==typeof performance.now&&(e+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(n){var r=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===n?r:3&r|8).toString(16)}))}function compareVersions(e,n){if(!e||!n)throw new Error("Please specify both verA and verB");for(var r=/(\.0+)+$/,t=String(e).replace(r,"").split("."),o=String(n).replace(r,"").split("."),s=Math.min(t.length,o.length),i=0;i<s;i++){var a=parseInt(t[i])-parseInt(o[i]);if(a)return a}return t.length-o.length}exports.escapeHTML=escapeHTML,exports.unescapeHTML=unescapeHTML,exports.removeTags=removeTags,exports.nl2br=nl2br,exports.randomStr=randomStr,exports.uuidV4=uuidV4,exports.compareVersions=compareVersions;
@@ -59,6 +59,12 @@ export declare function cutStr(str: string, length: number, options?: ICutStrOpt
59
59
  * @return 替换后的字符串。
60
60
  */
61
61
  export declare function escapeHTML(str: string): string;
62
+ /**
63
+ * 把指定字符串中的 HTML 实体替换成 HTML 预留字符。
64
+ * @param str 指定字符串。
65
+ * @return 替换后的字符串。
66
+ */
67
+ export declare function unescapeHTML(str: string): string;
62
68
  /**
63
69
  * 移除指定字符串中的 HTML 标签。
64
70
  * @param str 指定字符串。
package/dist/es/string.js CHANGED
@@ -1 +1 @@
1
- export 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);let o=0;for(let r=n.length-1;r>=0;r--)o+=n.charCodeAt(r)>255?e.nonEnLen||0:e.enLen||0;return o}export function cutStr(n,e,r){(r=r||{}).enLen=Number(r.enLen)||1,r.nonEnLen=Number(r.nonEnLen)||2,r.ellipsis=r.ellipsis||"...";const t=strLen(n=String(n),r);if(t<=e)return n;e-=strLen(r.ellipsis,r);let o="",l=-1;for(;e>0&&++l<t;)(e-=n.charCodeAt(l)>255?r.nonEnLen:r.enLen)>=0&&(o+=n.charAt(l));return o+=r.ellipsis,o}export function escapeHTML(n){if(null==n)return n;const e={'"':"&quot;","'":"&#39;","&":"&amp;","<":"&lt;",">":"&gt;"};return String(n).replace(/["'&<>]/g,(n=>e[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 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}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 r=(n+16*Math.random())%16|0;return n=Math.floor(n/16),("x"===e?r:3&r|8).toString(16)}))}export function compareVersions(n,e){if(!n||!e)throw new Error("Please specify both verA and verB");const r=/(\.0+)+$/,t=String(n).replace(r,"").split("."),o=String(e).replace(r,"").split("."),l=Math.min(t.length,o.length);for(let n=0;n<l;n++){const e=parseInt(t[n])-parseInt(o[n]);if(e)return e}return t.length-o.length}
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}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polyv/utils",
3
- "version": "2.2.0-beta.1",
3
+ "version": "2.3.0-beta.1",
4
4
  "description": "Utility functions of Polyv frontend development.",
5
5
  "keywords": [
6
6
  "polyv",