UNPKG

azure-devops-ui

Version:

React components for building web UI in Azure DevOps

1 lines 5.95 kB
import*as Culture from"../../Core/Util/Culture";function prepareForComparison(e,r){return e?r?e.toLocaleUpperCase():e:""}function comparer(e,r,t){return e===r?0:prepareForComparison(e,t).localeCompare(prepareForComparison(r,t),navigator.language)}function localeComparer(e,r){return comparer(e,r,!1)}function localeIgnoreCaseComparer(e,r){return comparer(e,r,!0)}function equals(e,r,t){return t?0===localeIgnoreCaseComparer(e,r):0===localeComparer(e,r)}function equalsNullable(e,r,t){return e===r||null!=e&&null!=r&&equals(e,r,t)}function startsWith(e,r,t){return 0===(t?localeIgnoreCaseComparer:localeComparer)(r,e.substr(0,r.length))}function endsWith(e,r,t){return 0===(t?localeIgnoreCaseComparer:localeComparer)(r,e.substr(e.length-r.length,r.length))}function caseInsensitiveContains(e,r){return-1!==e.toLocaleLowerCase().indexOf(r.toLocaleLowerCase())}function format(e,...r){return _stringFormat(!1,e,r)}function localeFormat(e,...r){return _stringFormat(!0,e,r)}function _stringFormat(t,n,a){let o="";for(let r=0;;){var i=n.indexOf("{",r),s=n.indexOf("}",r);if(i<0&&s<0){o+=n.slice(r);break}if(0<s&&(s<i||i<0)){if("}"!==n.charAt(s+1))throw new Error("The format string contains an unmatched opening or closing brace.");o+=n.slice(r,s+1),r=s+2}else if(o+=n.slice(r,i),r=i+1,"{"===n.charAt(r))o+="{",r++;else{if(s<0)throw new Error("The format string contains an unmatched opening or closing brace.");var i=n.substring(r,s),u=i.indexOf(":"),l=parseInt(u<0?i:i.substring(0,u),10);if(isNaN(l))throw new Error("The format string is invalid.");i=u<0?"":i.substring(u+1);let e=a[l];(e=void 0!==e&&null!==e?e:"").toFormattedString?o+=e.toFormattedString(i):"number"==typeof e?o+=numberToString(e,t,i):e instanceof Date?o+=dateToString(e,t):e.format?o+=e.format(i):o+=e.toString(),r=s+1}}return o}const localeFormatters="Intl"in window?{date:new Intl.DateTimeFormat,dateTime:new Intl.DateTimeFormat(void 0,{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric"})}:{};function dateToString(r,e){var t="string"==typeof e?e:"dateTime";if(e){let e=localeFormatters[t];return(e=e||localeFormatters.dateTime).format(r)}return r.toString()}const EmptyGuidString="00000000-0000-0000-0000-000000000000";function isGuid(e){return/^\{?([\dA-F]{8})-?([\dA-F]{4})-?([\dA-F]{4})-?([\dA-F]{4})-?([\dA-F]{12})\}?$/i.test(e)}function newGuid(){var e=(128+Math.floor(64*Math.random())).toString(16);return oct(8)+"-"+oct(4)+"-4"+oct(3)+"-"+e+oct(2)+"-"+oct(12)}const controlChars=/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/;function containsControlChars(e){return controlChars.test(e)}const surrogateChars=/(^[\uD800-\uDFFF]$)|[^\uD800-\uDBFF](?=[\uDC00-\uDFFF])|[\uD800-\uDBFF](?![\uDC00-\uDFFF])/;function containsMismatchedSurrogateChars(e){return surrogateChars.test(e)}function numberToString(e,r,t){if(!t||0===t.length||"i"===t)return r?e.toLocaleString():e.toString();function f(r,t,n){for(let e=r.length;e<t;e++)r=n?"0"+r:r+"0";return r}function n(e,r,t,n,a){let o=t[0],i=1;var s=Math.pow(10,r);let u=Math.round(e*s)/s,l=(e=u=isFinite(u)?u:e).toString(),c="";s=l.split(/e/i);l=s[0],e=1<s.length?parseInt(s[1]):0,s=l.split("."),l=s[0],c=1<s.length?s[1]:"",0<e?(c=f(c,e,!1),l+=c.slice(0,e),c=c.substr(e)):e<0&&(e=-e,l=f(l,1+e,!0),c=l.slice(-e,l.length)+c,l=l.slice(0,-e)),c=0<r?a+(c=c.length>r?c.slice(0,r):f(c,r,!1)):"";let m=l.length-1,g="";for(;0<=m;){if(0===o||o>m)return 0<g.length?l.slice(0,m+1)+n+g+c:l.slice(0,m+1)+c;g=0<g.length?l.slice(m-o+1,m+1)+n+g:l.slice(m-o+1,m+1),m-=o,i<t.length&&(o=t[i],i++)}return l.slice(0,m+1)+n+g+c}var a=(r?Culture.getCurrentCulture():Culture.getInvariantCulture()).numberFormat;let o,i=-1;1<(t=t||"D").length&&(i=parseInt(t.slice(1),10));let s;switch(t.charAt(0)){case"d":case"D":s="n",-1!==i?(o=f(""+Math.abs(e),i,!0),e<0&&(o="-"+o)):o=""+e;break;case"c":case"C":s=e<0?["($n)","-$n","$-n","$n-","(n$)","-n$","n-$","n$-","-n $","-$ n","n $-","$ n-","$ -n","n- $","($ n)","(n $)"][a.CurrencyNegativePattern]:["$n","n$","$ n","n $"][a.CurrencyPositivePattern],-1===i&&(i=a.CurrencyDecimalDigits),o=n(Math.abs(e),i,a.CurrencyGroupSizes,a.CurrencyGroupSeparator,a.CurrencyDecimalSeparator);break;case"n":case"N":s=e<0?["(n)","-n","- n","n-","n -"][a.NumberNegativePattern]:"n",-1===i&&(i=a.NumberDecimalDigits),o=n(Math.abs(e),i,a.NumberGroupSizes,a.NumberGroupSeparator,a.NumberDecimalSeparator);break;case"p":case"P":s=e<0?["-n %","-n%","-%n"][a.PercentNegativePattern]:["n %","n%","%n"][a.PercentPositivePattern],-1===i&&(i=a.PercentDecimalDigits),o=n(100*Math.abs(e),i,a.PercentGroupSizes,a.PercentGroupSeparator,a.PercentDecimalSeparator);break;default:throw new Error("Format specifier was invalid.")}var u=/n|\$|-|%/g;let l="";for(;;){var c=u.lastIndex,m=u.exec(s);if(l+=s.slice(c,m?m.index:s.length),!m)break;switch(m[0]){case"n":l+=o;break;case"$":l+=a.CurrencySymbol;break;case"-":/[1-9]/.test(o)&&(l+=a.NegativeSign);break;case"%":l+=a.PercentSymbol;break;default:throw new Error("Invalid number format pattern")}}return l}function oct(r){let t="";for(let e=0;e<r;e++)t+=Math.floor(16*Math.random()).toString(16);return t}function safeSubstring(e,r,t){for(r=Math.max(0,Math.min(r,e.length)),t=Math.min(e.length,Math.max(t,0));r<t&&56320==(64512&e.charCodeAt(r));)r++;for(;r<t&&55296==(64512&e.charCodeAt(t-1));)t--;return e.substring(r,t)}function stripHtmlToPlainText(e){if(!e)return"";if("undefined"==typeof DOMParser)return e.replace(/<[^>]*>/g,"").trim();let r=(new DOMParser).parseFromString(e,"text/html").body.textContent||"";return/&(?:lt|gt|amp|quot|apos|#\d+|#x[0-9a-f]+);/i.test(r)&&(e=(new DOMParser).parseFromString(r,"text/html"),r=e.body.textContent||""),r.trim()}export{localeComparer,localeIgnoreCaseComparer,equals,equalsNullable,startsWith,endsWith,caseInsensitiveContains,format,localeFormat,dateToString,EmptyGuidString,isGuid,newGuid,containsControlChars,containsMismatchedSurrogateChars,numberToString,safeSubstring,stripHtmlToPlainText};