UNPKG

tiny-essentials

Version:

Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.

64 lines 2.99 kB
/** * Calculates the time duration between the current time and a given time offset. * * @param {Date} timeData - The target time as a Date object. * @param {string} [durationType='asSeconds'] - The type of duration to return. Can be 'asMilliseconds', 'asSeconds', 'asMinutes', 'asHours', 'asDays'. * @param {Date|null} [now=null] - The current time as a Date object. Defaults to the current date and time if not provided. * @returns {number|null} The calculated duration in the specified unit, or `null` if `timeData` is not provided. */ export function getTimeDuration(timeData?: Date, durationType?: string, now?: Date | null): number | null; /** * Formats a custom timer string based on total seconds and a detail level. * Includes proper reallocation of lower units into higher ones, ensuring consistent hierarchy. * * @param {number} totalSeconds - The total amount of seconds to convert. * @param {'seconds'|'minutes'|'hours'|'days'|'months'|'years'} [level] - The highest level to calculate and display. * @param {string} [format='{time}'] - Output template with placeholders like {years}, {months}, {days}, {hours}, {minutes}, {seconds}, {time}, {total}. * @returns {string} The formatted timer string. */ export function formatCustomTimer(totalSeconds: number, level?: "seconds" | "minutes" | "hours" | "days" | "months" | "years", format?: string): string; /** * Formats a duration (in seconds) into a timer string showing only hours, minutes, and seconds. * * Example output: "05:32:10" * * @param {number} seconds - The total number of seconds to format. * @returns {string} The formatted timer string in "HH:MM:SS" format. */ export function formatTimer(seconds: number): string; /** * Formats a duration (in seconds) into a timer string including days, hours, minutes, and seconds. * * Example output: "2d 05:32:10" * * @param {number} seconds - The total number of seconds to format. * @returns {string} The formatted timer string in "Xd HH:MM:SS" format. */ export function formatDayTimer(seconds: number): string; /** * Breaks down a duration in milliseconds into its time components. * * @param {number} totalMs - The total duration in milliseconds. * @param {'milliseconds'|'seconds'|'minutes'|'hours'|'days'|'months'|'years'} [level='milliseconds'] - The highest level to calculate and display. * @returns {{ * years: number|NaN, * months: number|NaN, * days: number|NaN, * hours: number|NaN, * minutes: number|NaN, * seconds: number|NaN, * milliseconds: number|NaN, * total: number|NaN * }} */ export function breakdownDuration(totalMs: number, level?: "milliseconds" | "seconds" | "minutes" | "hours" | "days" | "months" | "years"): { years: number | number; months: number | number; days: number | number; hours: number | number; minutes: number | number; seconds: number | number; milliseconds: number | number; total: number | number; }; //# sourceMappingURL=clock.d.mts.map