typescript-string-operations
Advanced tools
Comparing version
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var String=function(){function t(){}return t.IsNullOrWhiteSpace=function(t){try{return null==t||"undefined"==t||t.toString().replace(/\s/g,"").length<1}catch(t){return console.log(t),!1}},t.Join=function(r){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];try{var a=e[0];if(Array.isArray(a)||a instanceof Array){for(var i=t.Empty,o=0;o<a.length;o++){var l=a[o];o<a.length-1?i+=l+r:i+=l}return i}if("object"==typeof a){var u=t.Empty,g=a;return Object.keys(a).forEach(function(t){u+=g[t]+r}),u=u.slice(0,u.length-r.length)}var s=e;return t.join.apply(t,[r].concat(s))}catch(r){return console.log(r),t.Empty}},t.Format=function(r){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];try{return r.replace(/{(\d+(:\w*)?)}/g,function(r,n){var a=r.split(":");a.length>1&&(n=n[0],r=a[1].replace("}",""));var i=e[n];return null==i||void 0==i||r.match(/{d+}/)?i:void 0!==(i=t.parsePattern(r,i))&&null!=i?i:t.Empty})}catch(r){return console.log(r),t.Empty}},t.parsePattern=function(r,e){switch(r){case"L":return e=e.toLowerCase();case"U":return e=e.toUpperCase();case"d":if("string"==typeof e)return t.getDisplayDateFromString(e);if(e instanceof Date)return t.Format("{0:00}.{1:00}.{2:0000}",e.getDate(),e.getMonth(),e.getFullYear());break;case"s":if("string"==typeof e)return t.getSortableDateFromString(e);if(e instanceof Date)return t.Format("{0:0000}-{1:00}-{2:00}",e.getFullYear(),e.getMonth(),e.getDate());break;case"n":var n=e.replace(/,/g,".");if(isNaN(parseFloat(n))||n.length<=3)break;var a=n.split(/[^0-9]+/g),i=a;a.length>1&&(i=[t.join.apply(t,[""].concat(a.splice(0,a.length-1))),a[a.length-1]]);var o=i[0],l=o.length%3,u=l>0?o.substring(0,l):t.Empty,g=o.substring(l).match(/.{3}/g);return e=(u=u+"."+t.Join(".",g))+(i.length>1?","+i[1]:"")}return"number"!=typeof e&&isNaN(e)?e:t.formatNumber(e,r)},t.getDisplayDateFromString=function(t){var r;if((r=t.split("-")).length<=1)return t;var e=r[r.length-1],n=r[r.length-2],a=r[r.length-3];return(e=(e=e.split("T")[0]).split(" ")[0])+"."+n+"."+a},t.getSortableDateFromString=function(t){var r=t.replace(",","").split(".");if(r.length<=1)return t;var e=r[r.length-1].split(" "),n=r[0];e.length>1&&(n=e[e.length-1]);var a=r[r.length-1].split(" ")[0]+"-"+r[r.length-2]+"-"+r[r.length-3];return n.length>1?a+="T"+n:a+="T00:00:00",a},t.formatNumber=function(t,r){var e=r.length,n=t.toString();if(e<=n.length)return n;var a=e-n.length;return new Array(a+=1).join("0")+n},t.join=function(r){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var a=t.Empty,i=0;i<e.length;i++)if(!("string"==typeof e[i]&&t.IsNullOrWhiteSpace(e[i])||"number"!=typeof e[i]&&"string"!=typeof e[i])){a+=""+e[i];for(var o=i+1;o<e.length;o++)if(!t.IsNullOrWhiteSpace(e[o])){a+=r,i=o-1;break}}return a},t.Empty="",t}();exports.String=String;var StringBuilder=function(){function t(t){void 0===t&&(t=String.Empty),this.Values=[],this.Values=new Array(t)}return t.prototype.ToString=function(){return this.Values.join("")},t.prototype.Append=function(t){this.Values.push(t)},t.prototype.AppendFormat=function(t){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];this.Values.push(String.Format.apply(String,[t].concat(r)))},t.prototype.Clear=function(){this.Values=[]},t}();exports.StringBuilder=StringBuilder; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var String=function(){function t(){}return t.IsNullOrWhiteSpace=function(t){try{return null==t||"undefined"==t||t.toString().replace(/\s/g,"").length<1}catch(t){return console.log(t),!1}},t.Join=function(r){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];try{var a=e[0];if(Array.isArray(a)||a instanceof Array){for(var i=t.Empty,o=0;o<a.length;o++){var l=a[o];o<a.length-1?i+=l+r:i+=l}return i}if("object"==typeof a){var u=t.Empty,g=a;return Object.keys(a).forEach(function(t){u+=g[t]+r}),u=u.slice(0,u.length-r.length)}var s=e;return t.join.apply(t,[r].concat(s))}catch(r){return console.log(r),t.Empty}},t.Format=function(r){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];try{return r.replace(/{(\d+(:\w*)?)}/g,function(r,n){var a=r.split(":");a.length>1&&(n=n[0],r=a[1].replace("}",""));var i=e[n];return null==i||void 0==i||r.match(/{d+}/)?i:void 0!==(i=t.parsePattern(r,i))&&null!=i?i:t.Empty})}catch(r){return console.log(r),t.Empty}},t.parsePattern=function(r,e){switch(r){case"L":return e=e.toLowerCase();case"U":return e=e.toUpperCase();case"d":if("string"==typeof e)return t.getDisplayDateFromString(e);if(e instanceof Date)return t.Format("{0:00}.{1:00}.{2:0000}",e.getDate(),e.getMonth(),e.getFullYear());break;case"s":if("string"==typeof e)return t.getSortableDateFromString(e);if(e instanceof Date)return t.Format("{0:0000}-{1:00}-{2:00}",e.getFullYear(),e.getMonth(),e.getDate());break;case"n":var n=e.replace(/,/g,".");if(isNaN(parseFloat(n))||n.length<=3)break;var a=n.split(/[^0-9]+/g),i=a;a.length>1&&(i=[t.join.apply(t,[""].concat(a.splice(0,a.length-1))),a[a.length-1]]);var o=i[0],l=o.length%3,u=l>0?o.substring(0,l):t.Empty,g=o.substring(l).match(/.{3}/g);return e=(u=u+"."+t.Join(".",g))+(i.length>1?","+i[1]:"")}return"number"!=typeof e&&isNaN(e)||isNaN(+r)?e:t.formatNumber(e,r)},t.getDisplayDateFromString=function(t){var r;if((r=t.split("-")).length<=1)return t;var e=r[r.length-1],n=r[r.length-2],a=r[r.length-3];return(e=(e=e.split("T")[0]).split(" ")[0])+"."+n+"."+a},t.getSortableDateFromString=function(t){var r=t.replace(",","").split(".");if(r.length<=1)return t;var e=r[r.length-1].split(" "),n=r[0];e.length>1&&(n=e[e.length-1]);var a=r[r.length-1].split(" ")[0]+"-"+r[r.length-2]+"-"+r[r.length-3];return n.length>1?a+="T"+n:a+="T00:00:00",a},t.formatNumber=function(t,r){var e=r.length,n=t.toString();if(e<=n.length)return n;var a=e-n.length;return new Array(a+=1).join("0")+n},t.join=function(r){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var a=t.Empty,i=0;i<e.length;i++)if(!("string"==typeof e[i]&&t.IsNullOrWhiteSpace(e[i])||"number"!=typeof e[i]&&"string"!=typeof e[i])){a+=""+e[i];for(var o=i+1;o<e.length;o++)if(!t.IsNullOrWhiteSpace(e[o])){a+=r,i=o-1;break}}return a},t.Empty="",t}();exports.String=String;var StringBuilder=function(){function t(t){void 0===t&&(t=String.Empty),this.Values=[],this.Values=new Array(t)}return t.prototype.ToString=function(){return this.Values.join("")},t.prototype.Append=function(t){this.Values.push(t)},t.prototype.AppendFormat=function(t){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];this.Values.push(String.Format.apply(String,[t].concat(r)))},t.prototype.Clear=function(){this.Values=[]},t}();exports.StringBuilder=StringBuilder; |
{ | ||
"name": "typescript-string-operations", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "Simple lightweight string operation library for Typescript, works with Angular", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.min.js", |
@@ -43,2 +43,5 @@ [](https://www.npmjs.com/package/typescript-string-operations) | ||
//output "1.000.000" | ||
value = String.Format("{0:00}", 1); | ||
//output "01" | ||
``` | ||
@@ -53,2 +56,3 @@ | ||
| `n` | Thousand seperator | | ||
| `00` | Padding numbers | | ||
@@ -55,0 +59,0 @@ |
10017
1%113
3.67%