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

@didiermargarido/ts-utilities

v1.2.0

Published

Collection of common utils in Typescript

Downloads

8

Readme

TS Utilities

npm GitHub Tag GitHub issues GitHub license

TS Utilities is a versatile collection of TypeScript utility functions designed to simplify your development tasks.
It provides a range of helpful functions for various common scenarios.

Installation

To incorporate TS Utilities into your TypeScript projects, you can use either npm or yarn package manager.
Choose the one you're most comfortable with:

Using NPM

npm install @didiermargarido/ts-utilities

Using Yarn

yarn add @didiermargarido/ts-utilities

Usage

TS Utilities provides a comprehensive set of utility functions that can streamline various aspects of your TypeScript projects.
Here's a detailed guide on how to use some of the key utility functions available in TS Utilities:

isDefined

Method to check if value is defined.

// Util
import { isDefined } from "@didiermargarido/ts-utilities";

// Output: true
isDefined("DM");
isDefined(10);
isDefined([]);

// Output: false
isDefined(null);
isDefined(undefined); 

isEmpty

Method to check if value is empty.

// Util
import { isEmpty } from "@didiermargarido/ts-utilities";

// Output: true
isEmpty("");
isEmpty([]);
isEmpty({});
isEmpty(null);
isEmpty(undefined);

// Output: false
isEmpty("DM");
isEmpty(["DM", 36]);
isEmpty({ key: "DM" }); 

isEqual

Method to check if two values are equal.

// Util
import { isEqual } from "@didiermargarido/ts-utilities";

// Output: true
isEqual("DM", "DM");
isEqual(true, true);
isEqual([1, 2], [1, 2]);
isEqual([{ key: "DM" }], [{ key: "DM" }]);

// Output: false
isEqual("DM", "MD");
isEqual(true, false);
isEqual({ key: "DM" }, { key: "MD" }); 

deepMerge

Method to merge multiple objects.

// Util
import { deepMerge } from "@didiermargarido/ts-utilities";

// Merge two single objects
const obj1 = { 
  car: "Ford",
};

const obj2 = { 
  car: "Peugeot", 
  color: "White"
};

// Output { car: "Peugeot", color: "White" }
deepMerge(obj1, obj2)

// Merge three objects with nested properties
const obj1 = { 
  car: "Ford", 
  specifications: { 
    km: 15000, 
    diesel: true 
  } 
};

const obj2 = { 
  car: "Peugeot", 
  color: "White"
};

const obj3 = { 
  car: "Peugeot", 
  specifications: { 
    diesel: false
  } 
};

// Output: { car: "Peugeot", color: "White", specifications: { km: 15000, diesel: false } }
deepMerge(obj1, obj2, obj3);

secureMask

Method to securely mask information by revealing specified digits from the start or end.

// Util
import { secureMask } from "@didiermargarido/ts-utilities";

// Optional options allowed
{
  digits: number // default is "4"
  char: string // default is "*"
  pad: "start" | "end" // default is "start"
}

// Output: "*****6789"
secureMask("123456789");

// Output: "*******89"
secureMask(123456789, { digits: 2 });

// Output: "123------"
secureMask("123456789", { digits: 3, char: "-", pad: "end" });

// Output: undefined
secureMask(undefined);
secureMask(null);

Author

Didier Margarido
github/didiermargarido

License

TS Utilities is open-sourced software licensed under the MIT license