typed-duration
Version:
Zero-dependency typed duration library for JavaScript
63 lines (62 loc) • 1.73 kB
TypeScript
import { millisecondsOf, secondsOf, minutesOf, hoursOf, daysOf } from "./lib";
export declare const Duration: {
milliseconds: {
of: typeof millisecondsOf;
from: (time: MaybeTimeDuration) => number;
};
seconds: {
of: typeof secondsOf;
from: (time: MaybeTimeDuration) => number;
};
minutes: {
of: typeof minutesOf;
from: (time: MaybeTimeDuration) => number;
};
hours: {
of: typeof hoursOf;
from: (time: MaybeTimeDuration) => number;
};
days: {
of: typeof daysOf;
from: (time: MaybeTimeDuration) => number;
};
value: {
from: (time: MaybeTimeDuration) => number;
of: (time: MaybeTimeDuration, defaultUnit?: string) => string;
};
isTypedDuration: (maybeTypedDuration: any) => maybeTypedDuration is TimeDuration;
};
interface TypedDuration {
type: string;
valueType: "TYPED_DURATION";
value: number;
unit: string;
}
export interface Seconds extends TypedDuration {
type: "SECONDS";
valueType: "TYPED_DURATION";
unit: "s";
}
export interface Milliseconds extends TypedDuration {
type: "MILLISECONDS";
valueType: "TYPED_DURATION";
unit: "ms";
}
export interface Minutes extends TypedDuration {
type: "MINUTES";
valueType: "TYPED_DURATION";
unit: "m";
}
export interface Hours extends TypedDuration {
type: "HOURS";
valueType: "TYPED_DURATION";
unit: "h";
}
export interface Days extends TypedDuration {
type: "DAYS";
valueType: "TYPED_DURATION";
unit: "d";
}
export declare type TimeDuration = Milliseconds | Seconds | Minutes | Hours | Days;
export declare type MaybeTimeDuration = TimeDuration | number;
export {};