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

Simple lightweight string operation library for Typescript

1.1.3
Source
npmnpm
Version published
Weekly downloads
120K
-23.29%
Maintainers
1
Weekly downloads
 
Created
Source

NPM

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"); //output "apple"

value = String.Format("{0:U}", "apple"); // output "APPLE"

value = String.Format("{0:d}", "2017-01-23 00:00"); //output "23.01.2017"


value = String.Format("{0:s}", "21.03.2017 22:15:01") //output "2017-03-21T22:15:01"

value = String.Format("{0:n}", 1000000);
//output "1.000.000"
SpecifierResult
LLowerCase
UUpperCase
dShortDatePattern
sSortableDateTimePattern
nThousand seperator

String.Join():

var value = String.Join("; ", "Apple", "Banana");
//output: "Apple; Banana";

OR

var array = ['Apple', 'Banana']
var value = String.Join("; ", array);
//output: "Apple; Banana";

Methods

MethodTypeDescriptionParameter
EmptyPropertysimply returns "".
IsNullOrWhiteSpaceMethodreturns true value if given parameter is either null, empty or undefined.format, args
FormatMethodConverts the value of objects to strings based on the formats specified and inserts them into another string.format, args
JoinMethodCombines arguments delimited by given seperator.delimiter,args
JoinMethodCombines arguments delimited by given seperator from array.delimiter,array

StringBuilder

Just like you know from C#,


var favoriteFruit: string = this.fruiteService.getFavorite(); //Blueberries

var builder = new StringBuilder("My favorite fruits are: ");
builder.Append("Apples, ");
builder.Append("Bananas ");

// of course using String.Format()
builder.AppendFormat("and especially {0:U}!", favoriteFruit);
builder.AppendFormat(" I eat {0} every day!", 10);

var fruits = builder.ToString();

//output: "My favorite fruits are: Apples, Bananas and especially Blueberries! I eat 10 every day!";

Methods

MethodTypeDescriptionParameter
AppendMethodappends a string.value
AppendFormatMethodsee description for String.Format()format, args
ClearMethodclears the StringBuilder

Keywords

typescript

FAQs

Package last updated on 21 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts