From b58eb9ce0e90c61d9371ed72ad2366896c046616 Mon Sep 17 00:00:00 2001 From: Justin Grant Date: Thu, 17 Apr 2025 06:25:14 -0700 Subject: [PATCH] Add TypeScript types Adds TS types to this package. I've tested this in my project and it compiles without errors. --- index.d.ts | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..de4d55d --- /dev/null +++ b/index.d.ts @@ -0,0 +1,61 @@ +/** + * Object used to represent the time of a clock. + * */ +export interface PosixClockTime { + /** + * Seconds since the epoch (1970-01-01 00:00:00 UTC). + */ + sec: number; + + /** + * Nanoseconds since the last second. + */ + nsec: number; +} + +/** + * Retrieves the time of the specified clock. + * @param clockId - Clock identifier, specified by constant. + * @returns An object containing seconds and nanoseconds: `{ sec: number, nsec: number }`. + */ +export function gettime(clockId: number): PosixClockTime; + +/** + * Finds the resolution (precision) of the specified clock. + * @param clockId - Clock identifier, specified by constant. + * @returns An object containing seconds and nanoseconds: `{ sec: number, nsec: number }`. + */ +export function getres(clockId: number): PosixClockTime; + +/** + * High-resolution sleep with a specifiable clock. + * @warning Not supported on FreeBSD. + * @param clockId - The clock identifier. + * @param flags - Flags (e.g., `TIMER_ABSTIME`). + * @param sleepTime - The sleep time as `{ sec: number, nsec: number }`. + */ +export function nanosleep(clockId: number, flags: number, sleepTime: PosixClockTime): void; + +// Clock constants +export const REALTIME: number; +export const MONOTONIC: number; +export const REALTIME_COARSE: number; +export const MONOTONIC_COARSE: number; +export const MONOTONIC_RAW: number; +export const BOOTTIME: number; +export const PROCESS_CPUTIME_ID: number; +export const THREAD_CPUTIME_ID: number; + +// FreeBSD-specific constants +export const REALTIME_FAST: number; +export const REALTIME_PRECISE: number; +export const MONOTONIC_FAST: number; +export const MONOTONIC_PRECISE: number; +export const UPTIME: number; +export const UPTIME_FAST: number; +export const UPTIME_PRECISE: number; +export const SECOND: number; +export const PROF: number; + +// Timer flag +export const TIMER_ABSTIME: number;