npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

typescript-string-operations

v1.5.1

Published

Simple lightweight string operation library for Typescript, works with Angular

Downloads

450,334

Readme

CircleCI Quality Gate Status npm npm

Simple lightweight string operation library for Typescript.

Installation

npm install typescript-string-operations

No jQuery required! Unit tested, works with Angular.

 import { StringBuilder, emptyString, joinString, formatString, isNullOrWhiteSpace } from 'typescript-string-operations';

When migrating from Version 1.4.1 or lower, you can also import the class String. Using this String class would override the native String object from JavaScript. We will remove this declaration with the next major release

 import { String } from 'typescript-string-operations';

USAGE:

String.empty

var id = emptyString; // or String.empty
// output: id = '';

String.isNullOrWhiteSpace():

var id = image.GetId();
if(isNullOrWhiteSpace(id)) // String.isNullOrWhiteSpace(id)
	return image;

String.format():

var id = image.GetId()
formatString("image_{0}.jpg", id) // or String.format()
output: "image_2db5da20-1c5d-4f1a-8fd4-b41e34c8c5b5.jpg";

Specifier available!

var value = formatString("{0:L}", "APPLE"); //output "apple"

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

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

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

value = formatString("{0:n}", 1000000);
//output "1.000.000"

value = formatString("{0:00}", 1);
//output "01"

UPDATE

String.format for Objects including specifiers

var fruit = new Fruit();
fruit.type = "apple";
fruit.color = "RED";
fruit.shippingDate = new Date(2018, 1, 1);
fruit.amount = 10000;

format("the {type:U} is {color:L} shipped on {shippingDate:s} with an amount of {amount:n}", fruit);
// output: the APPLE is red shipped on 2018-01-01 with an amount of 10.000

| Specifier | Result | | :-------------: |:---------------------------:| | L | LowerCase | | U | UpperCase | | d | ShortDatePattern | | s | SortableDateTimePattern | | n | Thousand seperator | | 00 | Padding numbers |

String.join():

var value = joinString("; ", "Apple", "Banana"); // or String.join()
//output: "Apple; Banana";

OR

 let object = { Name: "Foo", Value: "Bar" };
 var value = joinString('.', object);
//output: "Foo.Bar";

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

Methods

| Method | Type | Description | Parameter | | :------------------------:|:-----------:|:--------------------------:|:----------:| | empty | Property | simply returns "". | | isNullOrWhiteSpace | Method | returns true value if given parameter is either null, empty or undefined. | format, ...args | format/formatString | Method | Converts the value of objects to strings based on the formats specified and inserts them into another string. | format, ...args | join/joinString | Method | Combines arguments delimited by given seperator.| delimiter,...args | join/joinString | Method | Combines arguments delimited by given seperator from array. | delimiter,array |

StringBuilder

Just like you know from C#,


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

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

// using String.format() internally
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

| Method | Type | Description | Parameter | | :------------------------:|:-----------:|:--------------------------:|:----------:| | Append | Method | appends a string. | value | | AppendFormat | Method | see description for format()| format, args| | AppendLine | Method | appends a string in a new line. | format, args| | AppendLineFormat | Method | like format() in a new line | format, args| | Clear | Method | clears the StringBuilder | | | ToString | Method | creates the actual string. | |