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

sms-ts-extensions

v0.0.15

Published

extension Methods for some of the Main interfaces in typescript

Downloads

3

Readme

sms-extensions

This Project has some extension Methods for some premitive typescript interfaces (String, Array, Bool, Number) and some global function to help.

Install:

 npm install sms-ts-extensions --save

Usage:

// To get the extensions:
import 'sms-ts-extensions';
// To get the global functions:
import {arrNoneOrEmpty, isNone, isNotNone, arrNoneOrEmptyThenReturn, arrNoneOrEmptyThenDo} from 'sms-ts-extensions';

Examples:

String Extension Methods:

console.log("".isEmpty());//will print true
console.log("".isNotEmpty());//will print false
console.log("abc".isEmpty());//will print false
console.log("abc".isNotEmpty());//will print true

console.log("abc ".joinValids(",",true," def"," ","ghi", ""));//will print "abc,def,ghi"

console.log("abc".includesAny(["a","z","X"[));//will print true
console.log("abc".includesAll(["a","z","X"]));//will print false

console.log("abc".equalsLower("ABC"));//will print true

Array Extension Methods:

let arr = [5,3,6,2,1,4];
arr.remove(2);
console.log(arr);//will print [5,3,6,1,4]
arr.removeAt(2);
console.log(arr);//will print [5,3,1,4]

arr.addAll(2,6,7,8);
console.log(arr);//will print [5,3,1,4,2,6,7,8]

console.log(arr.first());//will print 5
console.log(arr.last());//will print 8
console.log(arr.firstWhere(element=>element  < 5));//will print 3
console.log(arr.lastWhere(element=>element  < 5));//will print 2

console.log(arr.isEmpty());//will print false
console.log([].isEmpty());//will print true
console.log(arr.isNotEmpty());//will print true
console.log([].isNotEmpty());//will print false

console.log([1,2,3,4,5,6].includesAny([1,2,5,8[));//will print true
console.log([1,2,3,4,5,6].includesAll([1,2,5,8]));//will print false

let b = arr.putFirstThenSort((e1,e2)=>e1 - e2, 2,6);
console.log(b);//will print [2,6,1,3,4,5,7,8]

Boolean Extension Methods:

true.trueThenDo(()=>console.log("was true"),()=>console.log("was false"));//will print was true
false.trueThenDo(()=>console.log("was true"),()=>console.log("was false"));//will print was false

true.falseThenDo(()=>console.log("was false"),()=>console.log("was true"));//will print was true
false.falseThenDo(()=>console.log("was false"),()=>console.log("was true"));//will print was false


console.log(true.trueThenReturn("was true","was false"));//will print was true
console.log(false.trueThenReturn("was true","was false"));//will print was false

console.log(true.falseThenReturn("was false","was true"));//will print was true
console.log(false.falseThenReturn("was false","was true"));//will print was false

Number Extension Methods:

let arr1 = (5).generateArray((index)=>"val" + index);
let arr2 = (5).generateArray((index)=>5 * index);
console.log(arr2);//will print ["val0","val1","val2","val3","val4"]
console.log(arr2);//will print [0,5,10,15,20]

Global Functions:

console.log(isNone(undefined));//will print true
console.log(isNone(null));//will print true
console.log(isNone(""));//will print false
console.log(isNone(0));//will print false

console.log(isNotNone(undefined));//will print false
console.log(isNotNone(null));//will print false
console.log(isNotNone(""));//will print true
console.log(isNotNone(0));//will print true

console.log(isNotNoneAnd(undefined,(value)=>true));//will print false
console.log(isNotNoneAnd("",(value)=>value.isEmpty()));//will print true
console.log(isNotNoneAnd("",(value)=>value.length > 0));//will print false

console.log(arrNoneOrEmpty([]));//will print true
console.log(arrNoneOrEmpty(undefined));//will print true

let arr = arrNoneOrEmptyThenDo([],
            ()=>{console.log("array was empty");return [1,2,3,4]},
            (array)=>{console.log("array was not empty"); return array}
            );//will print array was empty and assign [1,2,3,4] to arr

let arr2 = arrNoneOrEmptyThenDo(arr,
            ()=>{console.log("array was empty");return [1,2,3,4]},
            (array)=>{console.log("array was not empty"); return array}
            );//will print array was not empty and assign arr to arr2

console.log([].arrNoneOrEmptyThenReturn("was empty","was not empty"));//will print was empty
console.log([1,2,3].arrNoneOrEmptyThenReturn("was empty","was not empty"));//will print was not empty

console.log(strNoneOrEmpty(""));//will print true
console.log(strNoneOrEmpty(undefined));//will print true

LICENSE:

MIT LICENSE

link to license