A toolkit with helper functions needed for repetitive, tedious tasks.
To install the package, run:
npm i helper-toolkit-ts --save
Returns a rounded timestamp based on the specified number of minutes.
import { getRoundedTimestamp } from 'helper-toolkit-ts'
const roundedDate = getRoundedDate(15);
console.log(roundedDate); // Output: 1656318000
Name | Type | Description |
---|---|---|
numOfMinutes | number | number of minuts to round to |
Type | Description |
---|---|
number | rounded time values in milliseconds |
Abbreviates a number by converting it into a shorter format with an appropriate suffix.
const num = 1500;
const abbreviated = abbreviateNumber(num, 1);
console.log(abbreviated); // Output: '1.5K'
Name | Type | Description |
---|---|---|
num | number | input number |
fixed | number | number of decimal places to show |
Type | Description |
---|---|
string | abbreviate number like 1K |
Converts a number to a string representation with commas for better readability.
import { numberWithCommas } from 'helper-toolkit-ts'
const number = 1000000;
const formattedNumber = numberWithCommas(number);
console.log(formattedNumber); // Output: '1,000,000'
Name | Type | Description |
---|---|---|
num | number | input number |
Type | Description |
---|---|
string | number separated by comma: 3,000 |
Capitalizes the first letter of each word in a given text.
import { capitalizeFirstLetter } from 'helper-toolkit-ts'
const capitalizedSentence = capitalizeFirstLetter('hello world');
console.log(capitalizedSentence); // Output: 'Hello World'
Name | Type | Description |
---|---|---|
text | string | input text |
Type | Description |
---|---|
string | string with first letter in uppercase |
Truncates a given text to a specified length and appends ellipsis (...) at the end if needed.
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...'
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 |
Type | Description |
---|---|
string | return the string end with ellipsis(...) if length of input string is longer than the max n |
Generates a unique identifier (UUID) using the version 4 format.
import { generateUID } from 'helper-toolkit-ts'
const uid = generateUID();
console.log(uid); // Output: e.g., 'f47ac10b-58cc-4372-a567-0e02b2c3d479'
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
string | unique identifier string |
Determines whether the current device is a mobile device.
import { isMobileDevice } from 'helper-toolkit-ts'
const isMobile = isMobileDevice();
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
boolean | if is using mobile device |