1.2.1 • Published 11 months ago

helper-toolkit-ts v1.2.1

Weekly downloads
26
License
ISC
Repository
github
Last release
11 months ago

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:

NameTypeDescription
numOfMinutesnumbernumber of minuts to round to

Returns:

TypeDescription
numberrounded 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:

NameTypeDescription
numnumberinput number
fixednumbernumber of decimal places to show

Returns:

TypeDescription
stringabbreviate 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:

NameTypeDescription
numnumberinput number

Returns:

TypeDescription
stringnumber 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:

NameTypeDescription
textstringinput text

Returns:

TypeDescription
stringstring 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:

NameTypeDescription
textstringinput text
nnumbermax number of characters to keep
useWordBoundarybooleanif true, keep the whole word at end

Returns:

TypeDescription
stringreturn 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:

NameTypeDescription

Returns:

TypeDescription
stringunique identifier string

isMobileDevice

Determines whether the current device is a mobile device.

Usage:

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

const isMobile = isMobileDevice();

Arguments:

NameTypeDescription

Returns:

TypeDescription
booleanif is using mobile device
1.2.0

11 months ago

1.2.1

11 months ago

1.1.14

3 years ago

1.1.13

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago