topkat-utils
Version:
A comprehensive collection of TypeScript/JavaScript utility functions for common programming tasks. Includes validation, object manipulation, date handling, string formatting, and more. Zero dependencies, fully typed, and optimized for performance.
101 lines (100 loc) • 7.24 kB
TypeScript
export declare function getDateAsInt12(dateAllFormat?: Date | string | number, errIfNotValid?: any): string;
export declare function humanReadableTimestamp(dateAllFormat: any): number;
/** format for 6/8/2018 => 20180806
* @param dateAllFormat multiple format allowed 2012, 20120101, 201201011200, new Date(), "2019-12-08T16:19:10.341Z" and all string that new Date() can parse
*/
export declare function getDateAsInt(dateAllFormat?: Date | string | number, errIfNotValid$?: boolean, withHoursAndMinutes$?: boolean): string;
export declare function getMonthAsInt(dateAllFormat?: Date | string | number): number;
/**
* @param dateAllFormat multiple format allowed 2012, 20120101, 201201011200, new Date(), "2019-12-08T16:19:10.341Z" and all string that new Date() can parse
*/
export declare function getDateAsObject(dateAllFormat?: any, errIfNotValid$?: boolean): Date;
/** [2018,01,06] */
export declare function dateStringToArray(strOrInt: any): any[];
/**
* @param dateAllFormat default: actualDate
* @returns ['01', '01', '2019'] OR **string** if separator is provided */
export declare function dateArray(dateAllFormat?: Date | string | number): [string, string, string];
/**
* @param dateAllFormat default: actualDate
* @returns ['01', '01', '2019'] OR **string** if separator is provided */
export declare function dateArrayInt(dateAllFormat?: Date | string | number): [number, number, number];
/**
* @return 01/01/2012 (alias of dateArrayFormatted(date, '/'))
*/
export declare function dateFormatted(dateAllFormat: Date | string | number, separator?: string): string;
/** Date with custom offset (Ex: +2 for France) */
export declare function dateOffset(offsetHours: any, dateObj?: Date): Date;
/** */
export declare function getTimeAsInt(timeOrDateInt?: any): number | "dateInvalid";
/**
* @param {timeInt|dateInt12} Eg: 2222 OR 201201012222. Default, actual dateInt12
* @param {String} separator default: ":"
*/
export declare function getIntAsTime(intOrDateTimeInt?: string, separator?: string): string;
export declare function isTimeStringValid(timeStr: any, outputAnError$?: boolean): boolean;
export declare function getDuration(startDate: any, endDate: any, inMinutes?: boolean): number | number[];
/** compare two object with DATE INT, if they overlap return true
* @param {Object} event1 {startDate, endDate}
* @param {Object} event2 {startDate, endDate}
* @param {String} fieldNameForStartDate$ replace startDate with this string
* @param {String} fieldNameForEndDate$ replace endDate with this string
* @param {Boolean} allowNull$ if false, retrun false if any of the startdates or enddates are not set
* @param {Boolean} strict$ if true,
*/
export declare function doDateOverlap(event1: any, event2: any, fieldNameForStartDate$?: string, fieldNameForEndDate$?: string, allowNull$?: boolean, strict$?: boolean): boolean;
type DateAllFormat = DateObjectFormat | DateStringFormats;
type DateStringFormats = 'dateInt8' | 'dateInt12' | 'humanReadableTimestamp';
type DateObjectFormat = 'date';
export declare function nextWeekDay(fromDate: any, weekDayInt?: 0 | 1 | 2 | 3 | 4 | 5 | 6, outputFormat?: DateStringFormats, sameDayAllowed?: boolean): number;
export declare function nextWeekDay(fromDate: any, weekDayInt?: 0 | 1 | 2 | 3 | 4 | 5 | 6, outputFormat?: DateObjectFormat, sameDayAllowed?: boolean): Date;
/**
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
*/
export declare function addDays(dateAllFormat?: Date | string | number, numberOfDays?: number, outputFormat?: 'dateInt8' | 'dateInt12' | 'humanReadableTimestamp'): string;
export declare function addDays(dateAllFormat?: Date | string | number, numberOfDays?: number, outputFormat?: 'date'): Date;
/**
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
*/
export declare function addMinutes(dateAllFormat?: Date | string | number, numberOfMinutes?: number, outputFormat?: DateStringFormats): string;
export declare function addMinutes(dateAllFormat?: Date | string | number, numberOfMinutes?: number, outputFormat?: DateObjectFormat): Date;
/**
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
*/
export declare function addHours(dateAllFormat?: Date | string | number, numberOfHours?: number, outputFormat?: 'dateInt8' | 'dateInt12' | 'humanReadableTimestamp'): string;
export declare function addHours(dateAllFormat?: Date | string | number, numberOfHours?: number, outputFormat?: 'date'): Date;
/**
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
*/
export declare function addMonths(dateAllFormat?: Date | string | number, numberOfMonths?: number, outputFormat?: 'dateInt8' | 'dateInt12' | 'humanReadableTimestamp'): string;
export declare function addMonths(dateAllFormat?: Date | string | number, numberOfMonths?: number, outputFormat?: 'date'): Date;
/**
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
*/
export declare function addYears(dateAllFormat?: Date | string | number, numberOfYears?: number, outputFormat?: DateAllFormat): Date;
export declare function getDayOfMonth(dateAllFormat?: Date | string | number): any;
export declare function getYear(dateAllFormat?: Date | string | number): any;
export declare function getHours(dateAllFormat?: Date | string | number): any;
export declare function getMinutes(dateAllFormat?: Date | string | number): any;
/**
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
*/
export declare function lastDayOfMonth(dateAllFormat?: Date | string | number, outputFormat?: DateAllFormat): Date;
/**
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
*/
export declare function firstDayOfMonth(dateAllFormat?: Date | string | number, outputFormat?: DateAllFormat): Date;
export declare function differenceInMilliseconds(startDateAllFormat: any, endDateAllFormat: any): number;
export declare function differenceInSeconds(startDateAllFormat: any, endDateAllFormat: any): number;
export declare function differenceInMinutes(startDateAllFormat: any, endDateAllFormat: any): number;
export declare function differenceInHours(startDateAllFormat: any, endDateAllFormat: any): number;
export declare function differenceInDays(startDateAllFormat: any, endDateAllFormat: any): number;
export declare function differenceInWeeks(startDateAllFormat: any, endDateAllFormat: any): number;
/**
* @param {String} outputDateFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
*/
export declare function getDateAs(dateAllFormat?: Date | string | number, outputFormat?: 'dateInt8' | 'dateInt12' | 'humanReadableTimestamp'): string;
export declare function getDateAs(dateAllFormat?: Date | string | number, outputFormat?: 'date'): Date;
export declare function isDateIntOrStringValid(dateStringOrInt: any, outputAnError?: boolean, length?: any): boolean;
export declare function isDateIsoOrObjectValid(dateIsoOrObj: any, outputAnError?: boolean): boolean;
export {};