yeonpm-modules
Version:
Collection of frequently used functions for projects
65 lines (61 loc) • 2.27 kB
TypeScript
/**
* A function that adds commas every three digits when a number or string is input
* @param value number or string
* @returns string with commas
*/
declare const commas: (value: number | string) => string;
/**
* Formats a date into YYYY-MM-DD format
* @param date Date object or timestamp
* @param separator separator character between date parts (default: '-')
* @returns formatted date string in YYYY-MM-DD format
*/
declare const dateForm: (date: Date | number, separator?: string) => string;
/**
* Formats time into HH:mm or HH:mm:ss format
* @param date Date object or timestamp
* @param visibleSecond if true, seconds will be included in the output
* @returns formatted time string in HH:mm or HH:mm:ss format
*/
declare const timeForm: (date: Date | number, visibleSecond?: boolean) => string;
/**
* Formats a date into YYYY-MM-DD HH:mm format
* @param date Date object or timestamp
* @returns formatted date string in YYYY-MM-DD HH:mm format
*/
declare const dateTimeForm: (date: Date | number, separator?: string | undefined) => string;
/**
* Capitalizes the first letter of a string
* @param value input string
* @returns string with first letter capitalized
*/
declare const capitalize: (value: string) => string;
/**
* Converts a date string to a Date object
* @param dateStr date string (in the format YYMMDD, YYYYMMDD, YYYYMMDDHHMM, YYYYMMDDHHMMSS)
* @returns Date object
*/
declare const stringToDate: (dateStr: string) => Date | null;
/**
* Truncates a string if it exceeds the specified length
* @param value input string
* @param length maximum length before truncation
* @returns truncated string with ellipsis if needed
*/
declare const truncate: (value: string, length: number) => string;
/**
* Converts a date to a relative time string (e.g., "2 hours ago")
* @param date Date object or timestamp
* @returns relative time string
*/
declare const timeAgo: (date: Date | number) => string;
/**
* Sum all numbers
* @param args - Numbers to sum
* @returns Sum of all numbers
*/
declare const sum: (...args: number[]) => number;
declare const log: {
info: (title: string, ...args: any[]) => void;
};
export { capitalize, commas, dateForm, dateTimeForm, log, stringToDate, sum, timeAgo, timeForm, truncate };