typescript-string-operations
Advanced tools
Comparing version
@@ -1,1 +0,1 @@ | ||
"use strict";var __spreadArray=this&&this.__spreadArray||function(to,from,pack){if(pack||2===arguments.length)for(var ar,i=0,l=from.length;i<l;i++)!ar&&i in from||((ar=ar||Array.prototype.slice.call(from,0,i))[i]=from[i]);return to.concat(ar||Array.prototype.slice.call(from))},String=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.StringBuilder=exports.String=void 0,function(){function String(){}return String.IsNullOrWhiteSpace=function(value){try{return null==value||"undefined"==value?!0:value.toString().replace(/\s/g,"").length<1}catch(e){return console.log(e),!1}},String.Join=function(delimiter){for(var args=[],_i=1;_i<arguments.length;_i++)args[_i-1]=arguments[_i];try{var tempString_1,objectArg_1,firstArg=args[0];if(Array.isArray(firstArg)||firstArg instanceof Array){for(var tempString=String.Empty,i=0;i<firstArg.length;i++){var current=firstArg[i];i<firstArg.length-1?tempString+=current+delimiter:tempString+=current}return tempString}return"object"==typeof firstArg?(tempString_1=String.Empty,objectArg_1=firstArg,Object.keys(firstArg).forEach(function(element){tempString_1+=objectArg_1[element]+delimiter}),tempString_1=tempString_1.slice(0,tempString_1.length-delimiter.length)):String.join.apply(String,__spreadArray([delimiter],args,!1))}catch(e){return console.log(e),String.Empty}},String.Format=function(format){for(var args=[],_i=1;_i<arguments.length;_i++)args[_i-1]=arguments[_i];try{return format.match(String.regexNumber)?String.format(String.regexNumber,format,args):format.match(String.regexObject)?String.format(String.regexObject,format,args,!0):format}catch(e){return console.log(e),String.Empty}},String.format=function(regex,format,args,parseByObject){return void 0===parseByObject&&(parseByObject=!1),format.replace(regex,function(match,x){var s=match.split(":");return 1<s.length&&(x=s[0].replace("{",""),match=s[1].replace("}","")),null==(s=(parseByObject?args[0]:args)[x])||match.match(/{\d+}/)||void 0!==(s=String.parsePattern(match,s))&&null!=s?s:String.Empty})},String.parsePattern=function(match,arg){switch(match){case"L":return arg=arg.toLocaleLowerCase();case"U":return arg=arg.toLocaleUpperCase();case"d":if("string"==typeof arg)return String.getDisplayDateFromString(arg);if(arg instanceof Date)return String.Format("{0:00}.{1:00}.{2:0000}",arg.getDate(),arg.getMonth(),arg.getFullYear());break;case"s":if("string"==typeof arg)return String.getSortableDateFromString(arg);if(arg instanceof Date)return String.Format("{0:0000}-{1:00}-{2:00}",arg.getFullYear(),arg.getMonth(),arg.getDate());break;case"n":var replacedString=(arg="string"!=typeof arg?arg.toString():arg).replace(/,/g,".");if(isNaN(parseFloat(replacedString))||replacedString.length<=3)break;var replacedString=replacedString.split(/[^0-9]+/g),parts=replacedString,replacedString=(parts=1<replacedString.length?[String.join.apply(String,__spreadArray([""],replacedString.splice(0,replacedString.length-1),!1)),replacedString[replacedString.length-1]]:parts)[0],mod=replacedString.length%3,output=0<mod?replacedString.substring(0,mod):String.Empty,replacedString=replacedString.substring(mod).match(/.{3}/g);return arg=output+"."+String.Join(".",replacedString)+(1<parts.length?","+parts[1]:"");case"x":return this.decimalToHexString(arg);case"X":return this.decimalToHexString(arg,!0)}return"number"!=typeof arg&&isNaN(arg)||isNaN(+match)||String.IsNullOrWhiteSpace(arg)?arg:String.formatNumber(arg,match)},String.decimalToHexString=function(value,upperCase){void 0===upperCase&&(upperCase=!1);value=parseFloat(value).toString(16);return upperCase?value.toLocaleUpperCase():value},String.getDisplayDateFromString=function(input){var month,splitted=input.split("-");return splitted.length<=1?input:(input=splitted[splitted.length-1],month=splitted[splitted.length-2],splitted=splitted[splitted.length-3],input=(input=input.split("T")[0]).split(" ")[0],"".concat(input,".").concat(month,".").concat(splitted))},String.getSortableDateFromString=function(input){var time,month,splitted=input.replace(",","").split(".");return splitted.length<=1||(input=splitted[splitted.length-1].split(" "),time=String.Empty,1<input.length&&(time=input[input.length-1]),input=splitted[splitted.length-1].split(" ")[0],month=splitted[splitted.length-2],splitted=splitted[splitted.length-3],input="".concat(input,"-").concat(month,"-").concat(splitted),!String.IsNullOrWhiteSpace(time)&&1<time.length?input+="T".concat(time):input+="T00:00:00"),input},String.formatNumber=function(input,formatTemplate){var formatTemplate=formatTemplate.length,input=input.toString();return formatTemplate<=input.length?input:(formatTemplate=formatTemplate-input.length,++formatTemplate,new Array(formatTemplate).join("0")+input)},String.join=function(delimiter){for(var args=[],_i=1;_i<arguments.length;_i++)args[_i-1]=arguments[_i];for(var temp=String.Empty,i=0;i<args.length;i++)if(!("string"==typeof args[i]&&String.IsNullOrWhiteSpace(args[i])||"number"!=typeof args[i]&&"string"!=typeof args[i])){temp+=""+args[i];for(var i2=i+1;i2<args.length;i2++)if(!String.IsNullOrWhiteSpace(args[i2])){temp+=delimiter,i=i2-1;break}}return temp},String.regexNumber=/{(\d+(:\w*)?)}/g,String.regexObject=/{(\w+(:\w*)?)}/g,String.Empty="",String}()),StringBuilder=(exports.String=String,function(){function StringBuilder(value){this.Values=[],String.IsNullOrWhiteSpace(value)||(this.Values=new Array(value))}return StringBuilder.prototype.ToString=function(){return this.Values.join("")},StringBuilder.prototype.Append=function(value){this.Values.push(value)},StringBuilder.prototype.AppendLine=function(value){this.Values.push("\r\n"+value)},StringBuilder.prototype.AppendFormat=function(format){for(var args=[],_i=1;_i<arguments.length;_i++)args[_i-1]=arguments[_i];this.Values.push(String.Format.apply(String,__spreadArray([format],args,!1)))},StringBuilder.prototype.AppendLineFormat=function(format){for(var args=[],_i=1;_i<arguments.length;_i++)args[_i-1]=arguments[_i];this.Values.push("\r\n"+String.Format.apply(String,__spreadArray([format],args,!1)))},StringBuilder.prototype.Clear=function(){this.Values=[]},StringBuilder}());exports.StringBuilder=StringBuilder; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StringBuilder=exports.String=void 0;class String{static regexNumber=/{(\d+(:\w*)?)}/g;static regexObject=/{(\w+(:\w*)?)}/g;static Empty="";static IsNullOrWhiteSpace(value){try{return null==value||"undefined"==value?!0:value.toString().replace(/\s/g,"").length<1}catch(e){return console.log(e),!1}}static Join(delimiter,...args){try{var firstArg=args[0];if(Array.isArray(firstArg)||firstArg instanceof Array){let tempString=String.Empty;for(let i=0;i<firstArg.length;i++){var current=firstArg[i];i<firstArg.length-1?tempString+=current+delimiter:tempString+=current}return tempString}if("object"==typeof firstArg){let tempString=String.Empty,objectArg=firstArg,keys=Object.keys(firstArg);return keys.forEach(element=>{tempString+=objectArg[element]+delimiter}),tempString=tempString.slice(0,tempString.length-delimiter.length)}var stringArray=args;return String.join(delimiter,...stringArray)}catch(e){return console.log(e),String.Empty}}static Format(format,...args){try{return format.match(String.regexNumber)?String.format(String.regexNumber,format,args):format.match(String.regexObject)?String.format(String.regexObject,format,args,!0):format}catch(e){return console.log(e),String.Empty}}static format(regex,format,args,parseByObject=!1){return format.replace(regex,function(match,x){let s=match.split(":");1<s.length&&(x=s[0].replace("{",""),match=s[1].replace("}",""));let arg;return null==(arg=(parseByObject?args[0]:args)[x])||null==arg||match.match(/{\d+}/)||void 0!==(arg=String.parsePattern(match,arg))&&null!=arg?arg:String.Empty})}static parsePattern(match,arg){switch(match){case"L":return arg=arg.toLocaleLowerCase();case"U":return arg=arg.toLocaleUpperCase();case"d":if("string"==typeof arg)return String.getDisplayDateFromString(arg);if(arg instanceof Date)return String.Format("{0:00}.{1:00}.{2:0000}",arg.getDate(),arg.getMonth(),arg.getFullYear());break;case"s":if("string"==typeof arg)return String.getSortableDateFromString(arg);if(arg instanceof Date)return String.Format("{0:0000}-{1:00}-{2:00}",arg.getFullYear(),arg.getMonth(),arg.getDate());break;case"n":{let replacedString=(arg="string"!=typeof arg?arg.toString():arg).replace(/,/g,".");if(isNaN(parseFloat(replacedString))||replacedString.length<=3)break;let numberparts=replacedString.split(/[^0-9]+/g),parts=numberparts,integer=(parts=1<numberparts.length?[String.join("",...numberparts.splice(0,numberparts.length-1)),numberparts[numberparts.length-1]]:parts)[0];var mod=integer.length%3,output=0<mod?integer.substring(0,mod):String.Empty,mod=integer.substring(mod).match(/.{3}/g);return arg=output+"."+String.Join(".",mod)+(1<parts.length?","+parts[1]:"")}case"x":return this.decimalToHexString(arg);case"X":return this.decimalToHexString(arg,!0)}return"number"!=typeof arg&&isNaN(arg)||isNaN(+match)||String.IsNullOrWhiteSpace(arg)?arg:String.formatNumber(arg,match)}static decimalToHexString(value,upperCase=!1){const parsed=parseFloat(value),hexNumber=parsed.toString(16);return upperCase?hexNumber.toLocaleUpperCase():hexNumber}static getDisplayDateFromString(input){var splitted=input.split("-");if(splitted.length<=1)return input;let day=splitted[splitted.length-1];input=splitted[splitted.length-2],splitted=splitted[splitted.length-3];return(day=(day=day.split("T")[0]).split(" ")[0])+`.${input}.`+splitted}static getSortableDateFromString(input){let splitted=input.replace(",","").split(".");if(splitted.length<=1)return input;input=splitted[splitted.length-1].split(" ");let time=String.Empty,result=(1<input.length&&(time=input[input.length-1]),splitted[splitted.length-1].split(" ")[0]+`-${splitted[splitted.length-2]}-`+splitted[splitted.length-3]);return!String.IsNullOrWhiteSpace(time)&&1<time.length?result+="T"+time:result+="T00:00:00",result}static formatNumber(input,formatTemplate){var formatTemplate=formatTemplate.length,input=input.toString();return formatTemplate<=input.length?input:(formatTemplate=formatTemplate-input.length,++formatTemplate,new Array(formatTemplate).join("0")+input)}static join(delimiter,...args){let temp=String.Empty;for(let i=0;i<args.length;i++)if(!("string"==typeof args[i]&&String.IsNullOrWhiteSpace(args[i])||"number"!=typeof args[i]&&"string"!=typeof args[i])){var arg=""+args[i];temp+=arg;for(let i2=i+1;i2<args.length;i2++)if(!String.IsNullOrWhiteSpace(args[i2])){temp+=delimiter,i=i2-1;break}}return temp}}exports.String=String;class StringBuilder{Values;constructor(value){this.Values=[],String.IsNullOrWhiteSpace(value)||(this.Values=new Array(value))}ToString(){return this.Values.join("")}Append(value){this.Values.push(value)}AppendLine(value){this.Values.push("\r\n"+value)}AppendFormat(format,...args){this.Values.push(String.Format(format,...args))}AppendLineFormat(format,...args){this.Values.push("\r\n"+String.Format(format,...args))}Clear(){this.Values=[]}}exports.StringBuilder=StringBuilder; |
@@ -1,3 +0,3 @@ | ||
import { String } from "./string"; | ||
import { String, $String } from "./string"; | ||
import { StringBuilder } from "./stringbuilder"; | ||
export { String, StringBuilder }; | ||
export { String, $String, StringBuilder }; |
{ | ||
"name": "typescript-string-operations", | ||
"version": "1.5.0-beta", | ||
"version": "1.5.0-beta.0", | ||
"description": "Simple lightweight string operation library for Typescript, works with Angular", | ||
@@ -33,2 +33,3 @@ "main": "dist/index.min.js", | ||
"@types/mocha": "^9.1.1", | ||
"@types/node": "^18.7.11", | ||
"@typescript-eslint/eslint-plugin": "^5.34.0", | ||
@@ -35,0 +36,0 @@ "@typescript-eslint/parser": "^5.34.0", |
@@ -1,6 +0,27 @@ | ||
export interface String { | ||
Empty: string; | ||
IsNullOrWhiteSpace(value: string): boolean; | ||
Join(delimiter: string, ...args: (string | object | Array<any>)[]): string; | ||
Format(format: string, ...args: any[]): string; | ||
export declare class $String { | ||
static empty: string; | ||
static isNullOrWhiteSpace(value: string): boolean; | ||
static join(delimiter: string, ...args: (string | object | Array<any>)[]): string; | ||
static format(format: string, ...args: any[]): string; | ||
} | ||
export declare class String extends $String { | ||
/** | ||
* @deprecated The property should not be used, and will be removed with version 2.0.0 use `String.empty` instead. | ||
*/ | ||
static Empty: string; | ||
/** | ||
* @deprecated The method should not be used, and will be removed with version 2.0.0 use `String.isNullOrWhiteSpace()` instead. | ||
*/ | ||
static IsNullOrWhiteSpace(value: string): boolean; | ||
/** | ||
* @deprecated The method should not be used, and will be removed with version 2.0.0 use `String.join()` instead. | ||
*/ | ||
static Join(delimiter: string, ...args: (string | object | Array<any>)[]): string; | ||
/** | ||
* @deprecated The method should not be used, and will be removed with version 2.0.0 use `String.format()` instead. | ||
*/ | ||
static Format(format: string, ...args: any[]): string; | ||
} | ||
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
54
50%0
-100%14438
-2.19%16
6.67%