You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

typescript-string-operations

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-string-operations - npm Package Compare versions

Comparing version

to
1.5.0-rc.7

dist/index.d.ts

21

dist/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StringBuilder = exports.$String = void 0;
exports.StringBuilder = exports.$String = exports.format = exports.join = exports.isNullOrWhiteSpace = exports.empty = void 0;
const EOL = '\r\n';
exports.empty = '';
function isNullOrWhiteSpace(value) {
return $String.isNullOrWhiteSpace(value);
}
exports.isNullOrWhiteSpace = isNullOrWhiteSpace;
function join(delimiter, ...args) {
return $String.join(delimiter, ...args);
}
exports.join = join;
function format(format, ...args) {
return $String.format(format, ...args);
}
exports.format = format;
class $String {

@@ -233,8 +246,2 @@ static regexNumber = /{(\d+(:\w*)?)}/g;

exports.$String = $String;
String["isNullOrWhiteSpace"] = $String.isNullOrWhiteSpace;
String["join"] = $String.join;
String["format"] = $String.format;
String["IsNullOrWhiteSpace"] = $String.isNullOrWhiteSpace;
String["Join"] = $String.join;
String["Format"] = $String.format;
class StringBuilder {

@@ -241,0 +248,0 @@ Values;

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StringBuilder=exports.$String=void 0;const EOL="\r\n";class $String{static regexNumber=/{(\d+(:\w*)?)}/g;static regexObject=/{(\w+(:\w*)?)}/g;static empty="";static Empty="";static IsNullOrWhiteSpace(value){return $String.isNullOrWhiteSpace(value)}static Join(delimiter,...args){return $String.join(delimiter,...args)}static Format(format,...args){return $String.format(format,...args)}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;const 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.joinString(delimiter,...stringArray)}catch(e){return console.log(e),$String.empty}}static format(format,...args){try{return format.match($String.regexNumber)?$String.formatString($String.regexNumber,format,args):format.match($String.regexObject)?$String.formatString($String.regexObject,format,args,!0):format}catch(e){return console.log(e),$String.empty}}static formatString(regex,format,args,parseByObject=!1){return format.replace(regex,function(match,x){const 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":{const replacedString=(arg="string"!=typeof arg?arg.toString():arg).replace(/,/g,".");if(isNaN(parseFloat(replacedString))||replacedString.length<=3)break;const numberparts=replacedString.split(/\D+/g);let parts=numberparts;const integer=(parts=1<numberparts.length?[$String.joinString("",...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){const 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 joinString(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,String.isNullOrWhiteSpace=$String.isNullOrWhiteSpace,String.join=$String.join,String.format=$String.format,String.IsNullOrWhiteSpace=$String.isNullOrWhiteSpace,String.Join=$String.join,String.Format=$String.format;class StringBuilder{Values;constructor(value=""){this.Values=[],$String.isNullOrWhiteSpace(value)||(this.Values=new Array(value))}toString(){return this.Values.join($String.empty)}ToString(){return this.toString()}append(value){this.Values.push(value)}Append(value){this.append(value)}appendLine(value){this.Values.push(EOL+value)}AppendLine(value){this.appendLine(value)}appendFormat(format,...args){this.Values.push($String.format(format,...args))}AppendFormat(format,...args){this.appendFormat(format,...args)}appendLineFormat(format,...args){this.Values.push(EOL+$String.format(format,...args))}AppendLineFormat(format,...args){return this.appendLineFormat(format,...args)}clear(){this.Values=[]}Clear(){this.clear()}}exports.StringBuilder=StringBuilder;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StringBuilder=exports.$String=exports.format=exports.join=exports.isNullOrWhiteSpace=exports.empty=void 0;const EOL="\r\n";function isNullOrWhiteSpace(value){return $String.isNullOrWhiteSpace(value)}function join(delimiter,...args){return $String.join(delimiter,...args)}function format(format,...args){return $String.format(format,...args)}exports.empty="",exports.isNullOrWhiteSpace=isNullOrWhiteSpace,exports.join=join,exports.format=format;class $String{static regexNumber=/{(\d+(:\w*)?)}/g;static regexObject=/{(\w+(:\w*)?)}/g;static empty="";static Empty="";static IsNullOrWhiteSpace(value){return $String.isNullOrWhiteSpace(value)}static Join(delimiter,...args){return $String.join(delimiter,...args)}static Format(format,...args){return $String.format(format,...args)}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;const 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.joinString(delimiter,...stringArray)}catch(e){return console.log(e),$String.empty}}static format(format,...args){try{return format.match($String.regexNumber)?$String.formatString($String.regexNumber,format,args):format.match($String.regexObject)?$String.formatString($String.regexObject,format,args,!0):format}catch(e){return console.log(e),$String.empty}}static formatString(regex,format,args,parseByObject=!1){return format.replace(regex,function(match,x){const 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":{const replacedString=(arg="string"!=typeof arg?arg.toString():arg).replace(/,/g,".");if(isNaN(parseFloat(replacedString))||replacedString.length<=3)break;const numberparts=replacedString.split(/\D+/g);let parts=numberparts;const integer=(parts=1<numberparts.length?[$String.joinString("",...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){const 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 joinString(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($String.empty)}ToString(){return this.toString()}append(value){this.Values.push(value)}Append(value){this.append(value)}appendLine(value){this.Values.push(EOL+value)}AppendLine(value){this.appendLine(value)}appendFormat(format,...args){this.Values.push($String.format(format,...args))}AppendFormat(format,...args){this.appendFormat(format,...args)}appendLineFormat(format,...args){this.Values.push(EOL+$String.format(format,...args))}AppendLineFormat(format,...args){return this.appendLineFormat(format,...args)}clear(){this.Values=[]}Clear(){this.clear()}}exports.StringBuilder=StringBuilder;
{
"name": "typescript-string-operations",
"version": "1.5.0-rc.6",
"version": "1.5.0-rc.7",
"description": "Simple lightweight string operation library for Typescript, works with Angular",
"main": "dist/index.min.js",
"types": "./tist/index.d.ts",
"files": [

@@ -42,3 +43,3 @@ "dist/**/*.js",

"uglify-js": "^3.17.0",
"typescript-string-operations": "1.5.0-rc.6"
"typescript-string-operations": "1.5.0-rc.7"
},

@@ -45,0 +46,0 @@ "directories": {

@@ -13,9 +13,9 @@

```typescript
import { String, StringBuilder } from 'typescript-string-operations';
import { StringBuilder, join, format, isNullOrWhiteSpace } from 'typescript-string-operations';
```
I recently got feedback that sometimes there are issues when using `String`, since its actually replacing the native `String` object from JavaScript. You can use `$String` instead.
When migrating from Version 1.4.1 or lower, you can also import the clas `String`, this feature will be removed in the next major release
```typescript
import { $String } from 'typescript-string-operations';
import { String } from 'typescript-string-operations';
```

@@ -22,0 +22,0 @@

@@ -10,3 +10,3 @@

// @ts-ignore
export declare class String implements StringConstructor, $String {
export declare class String extends $String implements StringConstructor {
new(value?: any): string;

@@ -13,0 +13,0 @@ constructor(value?: any);

@@ -10,3 +10,3 @@

// @ts-ignore
export declare class String implements StringConstructor {
export declare class String implements StringConstructor, $String {
new(value?: any): string;

@@ -21,16 +21,16 @@ constructor(value?: any);

*/
Empty: string;
static Empty: string;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `String.isNullOrWhiteSpace()` instead.
*/
IsNullOrWhiteSpace(value: string | null | undefined): boolean;
static IsNullOrWhiteSpace(value: string | null | undefined): boolean;
/**
* @deprecated The method should not be used, and will be removed in future versions! Use `String.join()` instead.
*/
Join(delimiter: string, ...args: (string | object | Array<any>)[]): string;
static Join(delimiter: string, ...args: (string | object | Array<any>)[]): string;
/**
* @deprecated The method should not be used, and will be removed in future version!s Use `String.format()` instead.
*/
Format(format: string, ...args: any[]): string;
static Format(format: string, ...args: any[]): string;
}

@@ -9,3 +9,6 @@

export interface String extends $String, StringConstructor {
// @ts-ignore
export declare class String implements StringConstructor {
new(value?: any): string;
constructor(value?: any);
prototype: globalThis.String;

@@ -12,0 +15,0 @@ fromCharCode(...codes: number[]): string;