klog.js
Version:
A JavaScript implementation of the Klog time tracking file format
77 lines (76 loc) • 2.17 kB
TypeScript
import { Duration } from "./duration.js";
import { Time } from "./time.js";
import { TimeRangeNode } from "./types.js";
/**
* Formatting options for spacing around a range's dash.
*/
export declare enum RangeDashFormat {
Spaces = 0,
NoSpaces = 1
}
/**
* Options for configuring the range.
*/
export interface RangeOptions {
/** The format for dashes in the time range. */
format?: RangeDashFormat;
/** The number of placeholder characters to use for an open range. */
openRangePlaceholderCharCount?: number;
}
/**
* A range of time with a start time and optional end time.
*/
export declare class Range {
#private;
/** The start time of the range. */
start: Time;
/** The format for dashes in the time range. */
format: RangeDashFormat;
/** The number of placeholder characters to use for an open range. */
openRangePlaceholderCharCount: number;
/**
* Create a new range.
* @throws {Error} The end time is before the start time.
*/
constructor(
/** The start time of the range. */
start: Time,
/** The end time of the range. `null` if the range is open. */
end?: Time | null,
/** Configuration options for the range */
{ format, openRangePlaceholderCharCount, }?: RangeOptions);
/** @internal */
static fromAST: (node: TimeRangeNode) => Range;
/** The end time of the range. */
get end(): Time | null;
/**
* @throws {Error} The end time is before the start time.
*/
set end(value: Time | null);
/**
* Whether or not the range is considered open.
*/
get open(): boolean;
/**
* Convert the range to a duration.
*/
toDuration(): Duration;
/**
* Converts the range to minutes.
* @returns 0 if an open range, otherwise the duration of the time range in minutes.
*/
toMinutes(): number;
/**
* Render the range as a Klog string.
*/
toString(): string;
/**
* Convert the range to a JSON object.
*/
toJSON(): {
start: Time;
end: Time | null;
format: RangeDashFormat;
openRangePlaceholderCharCount: number;
};
}