Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@sk2you/custom-utils

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sk2you/custom-utils

A collection of utility functions for TypeScript projects

latest
Source
npmnpm
Version
1.0.7
Version published
Maintainers
1
Created
Source

JavaScript/TypeScript Utility Functions

This repository contains a collection of useful JavaScript/TypeScript utility functions for common tasks like date formatting, pagination, and number formatting.

Table of Contents

  • Installation
  • Functions
  • Usage Examples
  • License

Installation

# Using npm
npm install @yourpackage/utils

# Using yarn
yarn add @yourpackage/utils

Functions

Date Formatting

Format UNIX timestamps into readable date strings with customizable options.

getFormattedDate(
  UNIX_timestamp: number | string, 
  types: string[], 
  symbol = '-', 
  timeSeparator = ':', 
  timeFormat = '24', 
  monthName = false, 
  includeDay = true
): string

Parameters:

  • UNIX_timestamp: The UNIX timestamp to format
  • types: Array of elements to include ('day', 'date', 'month', 'year', 'hour', 'minute', 'second', 'period')
  • symbol: Symbol to use as separator between date elements (default: -)
  • timeSeparator: Symbol to use as separator between time elements (default: :)
  • timeFormat: '12' for 12-hour format with am/pm, '24' for 24-hour format (default: '24')
  • monthName: Whether to show month as name (Jan, Feb) instead of number (default: false)
  • includeDay: Whether to include the day name (SUN, MON, etc.) (default: true)

Pagination

Calculate page count based on pagination parameters.

GetPageCount(pagination: PaginationParams, index: number): number

Parameters:

  • pagination: Object containing limit and page properties
  • index: Current index

Number to Words

Convert numbers to their word representation with support for both Western and Indian number systems.

numberToWords(num: number, useIndianSystem = false): string

Parameters:

  • num: The number to convert to words
  • useIndianSystem: Whether to use Indian number naming (lakh, crore) (default: false)

Number Formatting

Format numbers with Indian numbering system separators.

formatNumberWithIndianSeparators(
  num: number | string, 
  separator = ',', 
  includeWords = false
): string

Parameters:

  • num: The number to format
  • separator: The separator character (default: ,)
  • includeWords: Whether to include the Indian names (lakh, crore) in parentheses (default: false)

Usage Examples

Date Formatting

import { getFormattedDate } from '@yourpackage/utils';

// Basic date formatting
const timestamp = 1618990800000; // April 21, 2021
const formattedDate = getFormattedDate(timestamp, ['date', 'month', 'year']);
console.log(formattedDate); // "21-04-2021"

// With month names and custom separator
const prettyDate = getFormattedDate(timestamp, ['date', 'month', 'year'], '/', undefined, undefined, true);
console.log(prettyDate); // "21/Apr/2021"

// With time
const dateTime = getFormattedDate(timestamp, ['date', 'month', 'year', 'hour', 'minute'], '-', ':', '12', true);
console.log(dateTime); // "21-Apr-2021 12:00"

Pagination

import { GetPageCount } from '@yourpackage/utils';

const pagination = { limit: 10, page: 2 };
const itemIndex = 3;

const pageCount = GetPageCount(pagination, itemIndex);
console.log(pageCount); // 14 (10 + 3 + 1)

Number to Words

import { numberToWords } from '@yourpackage/utils';

// Western system
console.log(numberToWords(123)); // "one hundred twenty-three"
console.log(numberToWords(1000000)); // "one million"

// Indian system
console.log(numberToWords(100000, true)); // "one lakh"
console.log(numberToWords(10000000, true)); // "one crore"

Number Formatting

import { formatNumberWithIndianSeparators } from '@yourpackage/utils';

// Basic formatting
console.log(formatNumberWithIndianSeparators(123456)); // "1,23,456"
console.log(formatNumberWithIndianSeparators(10000000)); // "1,00,00,000"

// With Indian number names
console.log(formatNumberWithIndianSeparators(100000, ',', true)); // "1,00,000 (1 lakh)"
console.log(formatNumberWithIndianSeparators(20000000, ',', true)); // "2,00,00,000 (2 crores)"

License

This project is licensed under the MIT License - see the LICENSE file for details.

Keywords

utilities

FAQs

Package last updated on 21 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts