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

helper-toolkit-ts

v1.2.1

Published

A toolkit with helper functions needed for minor, housekeeping, tedious things

Downloads

319

Readme

Helper Functions Toolkit

A toolkit with helper functions needed for repetitive, tedious tasks.

Installation:

To install the package, run:

npm i helper-toolkit-ts --save

Helper functions for Date

getRoundedTimestamp

Returns a rounded timestamp based on the specified number of minutes.

Usage:

import { getRoundedTimestamp } from 'helper-toolkit-ts'

const roundedDate = getRoundedDate(15);
console.log(roundedDate); // Output: 1656318000

Arguments:

|Name | Type | Description | |:-- |:-- | :-- | | numOfMinutes | number | number of minuts to round to |

Returns:

| Type | Description | |:-- | :-- | | number | rounded time values in milliseconds |

Helper functions for Number

abbreviateNumber

Abbreviates a number by converting it into a shorter format with an appropriate suffix.

Usage:

const num = 1500;
const abbreviated = abbreviateNumber(num, 1);
console.log(abbreviated); // Output: '1.5K'

Arguments:

|Name | Type | Description | |:-- |:-- | :-- | | num | number | input number | | fixed | number | number of decimal places to show |

Returns:

| Type | Description | |:-- | :-- | | string | abbreviate number like 1K |

numberWithCommas

Converts a number to a string representation with commas for better readability.

Usage:

import { numberWithCommas } from 'helper-toolkit-ts'

const number = 1000000;
const formattedNumber = numberWithCommas(number);
console.log(formattedNumber); // Output: '1,000,000'

Arguments:

|Name | Type | Description | |:-- |:-- | :-- | | num | number | input number |

Returns:

| Type | Description | |:-- | :-- | | string | number separated by comma: 3,000 |

Helper functions for Strings

capitalizeFirstLetter

Capitalizes the first letter of each word in a given text.

Usage:

import { capitalizeFirstLetter } from 'helper-toolkit-ts'

const capitalizedSentence = capitalizeFirstLetter('hello world');
console.log(capitalizedSentence); // Output: 'Hello World'

Arguments:

|Name | Type | Description | |:-- |:-- | :-- | | text | string | input text |

Returns:

| Type | Description | |:-- | :-- | | string | string with first letter in uppercase |

trunc

Truncates a given text to a specified length and appends ellipsis (...) at the end if needed.

Usage:

import { trunc } from 'helper-toolkit-ts'

const sentence = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
const truncatedSentence = trunc(sentence, 20, true);
console.log(truncatedSentence); // Output: 'Lorem ipsum dolor...'

Arguments:

|Name | Type | Description | |:-- |:-- | :-- | | text | string | input text | | n | number | max number of characters to keep | | useWordBoundary | boolean | if true, keep the whole word at end |

Returns:

| Type | Description | |:-- | :-- | | string | return the string end with ellipsis(...) if length of input string is longer than the max n |

Miscellaneous Helper Functions

generateUID

Generates a unique identifier (UUID) using the version 4 format.

Usage:

import { generateUID } from 'helper-toolkit-ts'

const uid = generateUID();
console.log(uid); // Output: e.g., 'f47ac10b-58cc-4372-a567-0e02b2c3d479'

Arguments:

|Name | Type | Description | |:-- |:-- | :-- | | | | |

Returns:

| Type | Description | |:-- | :-- | | string | unique identifier string |

isMobileDevice

Determines whether the current device is a mobile device.

Usage:

import { isMobileDevice } from 'helper-toolkit-ts'

const isMobile = isMobileDevice();

Arguments:

|Name | Type | Description | |:-- |:-- | :-- | | | | |

Returns:

| Type | Description | |:-- | :-- | | boolean | if is using mobile device |