@dvcol/common-utils
Version:
Typescript library for common utility functions and constants
49 lines (47 loc) • 1.76 kB
TypeScript
declare const computeProgress: (downloaded: number | any, size: number | any) => number;
type Time = {
years: number;
months: number;
days: number;
hours: number;
minutes: number;
seconds: number;
};
declare const formatTimeShort: ({ years, months, days, hours, minutes, seconds }: Time, separator?: string) => string;
declare const formatTimeLong: ({ years, months, days, hours, minutes, seconds }: Time) => string;
/**
* Note: Months are approximated to 365/12 days and years to 365 days, which may not be accurate.
*/
declare const InSeconds: {
readonly minute: 60;
readonly hour: number;
readonly day: number;
readonly week: number;
readonly month: number;
readonly year: number;
};
declare const formatHMS: (s: number) => Time;
declare const formatDHMS: (s: number) => Time;
/**
* Format time in seconds to human readable format.
* Note: Months are approximated to 365/12 days and years to 365 days, which may not be accurate.
*
* @param s - Time in seconds
*/
declare const formatYMD: (s: number) => Time;
/**
* Format time in seconds to human readable format.
* Note: Months are approximated to 365/12 days and years to 365 days, which may not be accurate.
*
* - short: 00:00:00
* - long: 0h 0m 0s
* - days: 0d 0h 0m 0s
* - ymd: 0y 0m 0d 0h 0m 0s
* - raw: { years, months, days, hours, minutes, seconds }
*
* @param s - Time in seconds
* @param format - Format to use
*/
declare const formatTime: (s: number, format?: 'short' | 'long' | 'ymd' | 'days' | 'raw') => Time | string;
declare const formatBytes: (byte: number | any) => string;
export { InSeconds, type Time, computeProgress, formatBytes, formatDHMS, formatHMS, formatTime, formatTimeLong, formatTimeShort, formatYMD };