
Simple lightweight string operation library for Typescript.
No jQuery required. Unit tested.
import { String, StringBuilder } from 'typescript-string-operations';
USAGE:
String.Empty
var id = String.Empty;
String.IsNullOrWhiteSpace():
var id = image.GetId();
if(String.IsNullOrWhiteSpace(id))
return image;
String.Format():
var id = image.GetId()
String.Format("image_{0}.jpg", id)
output: "image_2db5da20-1c5d-4f1a-8fd4-b41e34c8c5b5.jpg";
Specifier available!
var value = String.Format("{0:L}", "APPLE");
value = String.Format("{0:U}", "apple");
value = String.Format("{0:d}", "2017-01-23 00:00");
value = String.Format("{0:s}", "21.03.2017 22:15:01")
value = String.Format("{0:n}", 1000000);
L | LowerCase |
U | UpperCase |
d | ShortDatePattern |
s | SortableDateTimePattern |
n | Thousand seperator |
String.Join():
var value = String.Join("; ", "Apple", "Banana");
OR
var array = ['Apple', 'Banana']
var value = String.Join("; ", array);
Methods
Empty | Property | simply returns "" . | |
IsNullOrWhiteSpace | Method | returns true value if given parameter is either null, empty or undefined. | format , args |
Format | Method | Converts the value of objects to strings based on the formats specified and inserts them into another string. | format , args |
Join | Method | Combines arguments delimited by given seperator. | delimiter ,args |
Join | Method | Combines arguments delimited by given seperator from array. | delimiter ,array |
StringBuilder
Just like you know from C#,
var favoriteFruit: string = this.fruiteService.getFavorite();
var builder = new StringBuilder("My favorite fruits are: ");
builder.Append("Apples, ");
builder.Append("Bananas ");
builder.AppendFormat("and especially {0:U}!", favoriteFruit);
builder.AppendFormat(" I eat {0} every day!", 10);
var fruits = builder.ToString();
Methods
Append | Method | appends a string. | value |
AppendFormat | Method | see description for String.Format() | format , args |
Clear | Method | clears the StringBuilder | |