human-duration
Version:
Formats a duration as a human-readable string
44 lines (43 loc) • 1.18 kB
TypeScript
/**
* IGradings are provided in a list to the Duration.
*/
export interface IGrading {
unit: string | ((x: number) => string);
milliseconds: number;
}
export declare const millisecond: IGrading;
export declare const second: IGrading;
export declare const minute: IGrading;
export declare const hour: IGrading;
export declare const day: IGrading;
/**
* ISegments are the count of how many units are in each grading, returned
* from the Duration's getSegments call.
*/
export interface ISegment {
unit: string;
count: number;
}
export declare class Duration {
private _duration;
private _grading;
private _separator;
constructor(_duration: number);
/**
* Sets the grading used for handling durations.
*/
grading(grading: IGrading[]): this;
/**
* Sets the separator used between durations.
*/
separator(separator: string): this;
/**
* Returns the duration formatted into the given number of segments.
*/
segments(max?: number): string;
/**
* Converts the duration to a string.
*/
toString(segments?: number): string;
}
export declare function fmt(duration: number): Duration;