mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
add documentation
This commit is contained in:
381
types/sharp-timer/index.d.ts
vendored
381
types/sharp-timer/index.d.ts
vendored
@@ -1,78 +1,323 @@
|
||||
// Type definitions for sharp-timer 1.0
|
||||
// Type definitions for sharp-timer library. 1.0
|
||||
// Project: https://github.com/afractal/SharpTimer
|
||||
// Definitions by: Hermes Gjini - afractal <https://github.com/afractal/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
export const millisPerSecond: number;
|
||||
export const millisPerMinute: number;
|
||||
export const millisPerHour: number;
|
||||
export const millisPerDay: number;
|
||||
|
||||
export type ElapsedEvent = () => void;
|
||||
export type ElapsingEvent = (intervalValue: number) => void;
|
||||
|
||||
export class Timer {
|
||||
private _enabled: boolean;
|
||||
private _stopped: boolean;
|
||||
private _interval: number;
|
||||
private _intervalElapsedEvents: ElapsedEvent[];
|
||||
private _intervalElapsingEvents: ElapsingEvent[];
|
||||
constructor(interval: number);
|
||||
readonly enabled: boolean;
|
||||
readonly stopped: boolean;
|
||||
interval: number;
|
||||
start(): void;
|
||||
pause(): void;
|
||||
resume(): void;
|
||||
stop(): void;
|
||||
onIntervalElapsed(intervalElapsedHandler: ElapsedEvent): void;
|
||||
onIntervalElapsing(intervalElapsingHandler: ElapsingEvent): void;
|
||||
toString(): string;
|
||||
private getDoubleDigit(number: number): string;
|
||||
private checkForValidInterval(interval: number): void;
|
||||
declare global {
|
||||
namespace SharpTimer {
|
||||
const millisPerSecond: 1000;
|
||||
const millisPerMinute: 60000;
|
||||
const millisPerHour: 3600000;
|
||||
const millisPerDay: 86400000;
|
||||
type ElapsedEvent = () => void;
|
||||
type ElapsingEvent = (intervalValue: number) => void;
|
||||
}
|
||||
}
|
||||
|
||||
export class Stopwatch {
|
||||
private _isRunning: boolean;
|
||||
private _elapsedMilliseconds: number;
|
||||
private _startedTimeInMillis: number;
|
||||
private _intervalIds: Array<number | NodeJS.Timer>;
|
||||
constructor();
|
||||
readonly elapsed: string;
|
||||
readonly elapsedMilliseconds: number;
|
||||
readonly elapsedSeconds: number;
|
||||
readonly elapsedMinutes: number;
|
||||
readonly elapsedHours: number;
|
||||
readonly isRunning: boolean;
|
||||
static startNew(): Stopwatch;
|
||||
start(): void;
|
||||
stop(): void;
|
||||
reset(): void;
|
||||
restart(): void;
|
||||
dispose(): void;
|
||||
private getDoubleDigit(num: number): string;
|
||||
declare module "sharp-timer" {
|
||||
/**
|
||||
* Simulates the actions of a generic timer,
|
||||
* generates elapsing and elapsed events for a specified interval.
|
||||
*/
|
||||
class Timer {
|
||||
private _enabled: boolean;
|
||||
private _stopped: boolean;
|
||||
private _interval: number;
|
||||
private _intervalElapsedEvents: SharpTimer.ElapsedEvent[];
|
||||
private _intervalElapsingEvents: SharpTimer.ElapsingEvent[];
|
||||
|
||||
/**
|
||||
* Initializes a new instance of the Timer class,
|
||||
* and sets all the properties to their initial values.
|
||||
* @param interval
|
||||
* The time, in milliseconds, in which the timer will be active.
|
||||
* The value must be greater than zero.
|
||||
*/
|
||||
constructor(interval: number);
|
||||
|
||||
/**
|
||||
* Gets a boolean value to indicate the enabled state
|
||||
* of the current Timer instance.
|
||||
* @readonly
|
||||
* @default true
|
||||
*/
|
||||
readonly enabled: boolean;
|
||||
|
||||
/**
|
||||
* Gets a boolean value to indicate the stopped state
|
||||
* of the current Timer instance.
|
||||
* @readonly
|
||||
* @default false
|
||||
*/
|
||||
readonly stopped: boolean;
|
||||
|
||||
/**
|
||||
* Gets or sets the remaining interval in milliseconds.
|
||||
* The value must be greater than zero.
|
||||
*/
|
||||
interval: number;
|
||||
|
||||
/**
|
||||
* Starts raising the Timer events
|
||||
* by setting the enabled property to true.
|
||||
*/
|
||||
start(): void;
|
||||
|
||||
/**
|
||||
* Pauses the Timer instance by setting the enabled property to false.
|
||||
*/
|
||||
pause(): void;
|
||||
|
||||
/**
|
||||
* Resumes the Timer instance by setting the enabled property to true.
|
||||
*/
|
||||
resume(): void;
|
||||
|
||||
/**
|
||||
* Stops raising the Timer event
|
||||
* by setting the enabled property to false.
|
||||
*/
|
||||
stop(): void;
|
||||
|
||||
/**
|
||||
* Occurs when the interval has completely elapsed.
|
||||
* @param intervalElapsedHandler
|
||||
* The callback which will be executed when
|
||||
* the interval elapsed event occurs.
|
||||
*/
|
||||
onIntervalElapsed(intervalElapsedHandler: SharpTimer.ElapsedEvent): void;
|
||||
|
||||
/**
|
||||
* Occurs when the interval elapses and completely elapsed.
|
||||
* @param intervalElapsingHandler
|
||||
* The callback which will be executed when
|
||||
* the interval elapsing event occurs.
|
||||
*/
|
||||
onIntervalElapsing(intervalElapsingHandler: SharpTimer.ElapsingEvent): void;
|
||||
|
||||
/**
|
||||
* Returns a string represenation of the remaining
|
||||
* in this format: minutes:seconds.
|
||||
* examples: 20:23, 00:04, 59:59
|
||||
*/
|
||||
toString(): string;
|
||||
|
||||
private getDoubleDigit(number: number): string;
|
||||
|
||||
private checkForValidInterval(interval: number): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulates the actions of a generic stopwatch.
|
||||
*/
|
||||
class Stopwatch {
|
||||
private _isRunning: boolean;
|
||||
private _elapsedMilliseconds: number;
|
||||
private _startedTimeInMillis: number;
|
||||
private _intervalIds: Array<number | NodeJS.Timer>;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of the Stopwatch class.
|
||||
*/
|
||||
constructor();
|
||||
|
||||
/**
|
||||
* Gets the elapsed time in this format:
|
||||
* hrs:mins:secs:ms
|
||||
* @readonly
|
||||
*/
|
||||
readonly elapsed: string;
|
||||
|
||||
/**
|
||||
* Gets the elapsed time in milliseconds.
|
||||
* @readonly
|
||||
*/
|
||||
readonly elapsedMilliseconds: number;
|
||||
|
||||
/**
|
||||
* Gets the elapsed time in seconds.
|
||||
* @readonly
|
||||
*/
|
||||
readonly elapsedSeconds: number;
|
||||
|
||||
/**
|
||||
* Gets the elapsed time in minutes.
|
||||
* @readonly
|
||||
*/
|
||||
readonly elapsedMinutes: number;
|
||||
|
||||
/**
|
||||
* Gets the elapsed hours in hours.
|
||||
* @readonly
|
||||
*/
|
||||
readonly elapsedHours: number;
|
||||
|
||||
/**
|
||||
* Gets the isRunning state of the current Stopwatch instance.
|
||||
* @readonly
|
||||
* @default false
|
||||
*/
|
||||
readonly isRunning: boolean;
|
||||
|
||||
/**
|
||||
* Initializes a new Stopwatch instance and
|
||||
* starts measuring elapsed time.
|
||||
*/
|
||||
static startNew(): Stopwatch;
|
||||
|
||||
/**
|
||||
* Starts, or resumes the Stopwatch
|
||||
* from measuring elapsed time.
|
||||
*/
|
||||
start(): void;
|
||||
|
||||
/**
|
||||
* Stops the Stopwatch from measuring elapsed time.
|
||||
*/
|
||||
stop(): void;
|
||||
|
||||
/**
|
||||
* Stops the Stopwatch and resets the elapsed time to zero.
|
||||
*/
|
||||
reset(): void;
|
||||
|
||||
/**
|
||||
* Stops the Stopwatch,
|
||||
* resets the elapsed time to zero
|
||||
* and starts the Stopwatch for measuring elapsed time.
|
||||
* It is a shortcut for writing
|
||||
* reset then start.
|
||||
*/
|
||||
restart(): void;
|
||||
|
||||
/**
|
||||
* Stops the Stopwatch and cleans up the intervals.
|
||||
*/
|
||||
dispose(): void;
|
||||
|
||||
private getDoubleDigit(num: number): string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulates an object that represents a time interval.
|
||||
*/
|
||||
class Timespan {
|
||||
private _milliseconds: number;
|
||||
private constructor(milliseconds: number);
|
||||
|
||||
/**
|
||||
* Gets the time interval in milliseconds.
|
||||
* @readonly
|
||||
*/
|
||||
readonly milliseconds: number;
|
||||
|
||||
/**
|
||||
* Gets the time interval in seconds.
|
||||
* @readonly
|
||||
*/
|
||||
readonly seconds: number;
|
||||
|
||||
/**
|
||||
* Gets the time interval in minutes.
|
||||
* @readonly
|
||||
*/
|
||||
readonly minutes: number;
|
||||
|
||||
/**
|
||||
* Gets the time interval in hours.
|
||||
* @readonly
|
||||
*/
|
||||
readonly hours: number;
|
||||
|
||||
/**
|
||||
* Gets the time interval in days.
|
||||
* @readonly
|
||||
*/
|
||||
readonly days: number;
|
||||
|
||||
/**
|
||||
* Returns a Timespan that represents a specified number of days.
|
||||
* @param days The number of days.
|
||||
*/
|
||||
static fromDays(days: number): Timespan;
|
||||
|
||||
/**
|
||||
* Returns a Timespan that represents a specified number of hours.
|
||||
* @param hours The number of hours.
|
||||
*/
|
||||
static fromHours(hours: number): Timespan;
|
||||
|
||||
/**
|
||||
* Returns a Timespan that represents a specified number of minutes.
|
||||
* @param minutes The number of minutes.
|
||||
*/
|
||||
static fromMinutes(minutes: number): Timespan;
|
||||
|
||||
/**
|
||||
* Returns a Timespan that represents a specified number of seconds.
|
||||
* @param seconds The number of seconds.
|
||||
*/
|
||||
static fromSeconds(seconds: number): Timespan;
|
||||
|
||||
/**
|
||||
* Returns a Timespan that represents a specified number of milliseconds.
|
||||
* @param milliseconds The number of milliseconds.
|
||||
*/
|
||||
static fromMilliseconds(milliseconds: number): Timespan;
|
||||
|
||||
/**
|
||||
* Compares two Timespan objects and
|
||||
* returns an integer that indicates whether
|
||||
* the first value is shorter than, equal to,
|
||||
* or longer than the second value.
|
||||
* @param t1 The first Timespan to compare.
|
||||
* @param t2 The second Timespan to compare.
|
||||
*/
|
||||
static compare(t1: Timespan, t2: Timespan): 1 | 0 | -1;
|
||||
|
||||
/**
|
||||
* Returns a boolean value that indicates
|
||||
* whether two specified instances of Timespan are equal.
|
||||
* @param t1 The first Timespan to compare.
|
||||
* @param t2 The second Timespan to compare.
|
||||
*/
|
||||
static equals(t1: Timespan, t2: Timespan): boolean;
|
||||
|
||||
/**
|
||||
* Adds the specified Timespan to this instance.
|
||||
* @param timespan The Timespan to add.
|
||||
*/
|
||||
addMutable(timespan: Timespan): void;
|
||||
|
||||
/**
|
||||
* Substracts the specified Timespan from this instance.
|
||||
* @param timespan The Timespan to substract.
|
||||
*/
|
||||
substractMutable(timespan: Timespan): void;
|
||||
|
||||
/**
|
||||
* Returns a new Timespan object whose
|
||||
* value is the sum of the specified Timespan object and this instance.
|
||||
* @param timespan The Timespan to add.
|
||||
*/
|
||||
add(timespan: Timespan): Timespan;
|
||||
|
||||
/**
|
||||
* Returns a new Timespan object whose
|
||||
* value is the difference between the
|
||||
* specified Timespan object and this instance.
|
||||
* @param timespan The Timespan to substract.
|
||||
*/
|
||||
substract(timespan: Timespan): Timespan;
|
||||
|
||||
/**
|
||||
* Returns a new Timespan object
|
||||
* whose value is the negated value of this instance.
|
||||
*/
|
||||
negate(): Timespan;
|
||||
}
|
||||
}
|
||||
|
||||
export class Timespan {
|
||||
private _milliseconds: number;
|
||||
private constructor(milliseconds: number);
|
||||
readonly milliseconds: number;
|
||||
readonly seconds: number;
|
||||
readonly minutes: number;
|
||||
readonly hours: number;
|
||||
readonly days: number;
|
||||
static fromDays(days: number): Timespan;
|
||||
static fromHours(hours: number): Timespan;
|
||||
static fromMinutes(minutes: number): Timespan;
|
||||
static fromSeconds(seconds: number): Timespan;
|
||||
static fromMilliseconds(milliseconds: number): Timespan;
|
||||
static compare(t1: Timespan, t2: Timespan): 1 | 0 | -1;
|
||||
static equals(t1: Timespan, t2: Timespan): boolean;
|
||||
addMutable(timespan: Timespan): void;
|
||||
substractMutable(timespan: Timespan): void;
|
||||
add(timespan: Timespan): Timespan;
|
||||
substract(timespan: Timespan): Timespan;
|
||||
negate(): Timespan;
|
||||
}
|
||||
export * from 'sharp-timer';
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { Timer, Stopwatch } from 'sharp-timer';
|
||||
import { Timer, Stopwatch, Timespan } from 'sharp-timer';
|
||||
import * as s from 'sharp-timer';
|
||||
import S = require('sharp-timer');
|
||||
|
||||
type Elapsed = SharpTimer.ElapsedEvent;
|
||||
|
||||
let timer = new Timer(10);
|
||||
|
||||
timer.toString();
|
||||
timer.onIntervalElapsing(i => { });
|
||||
timer.onIntervalElapsed(() => {
|
||||
timer.stop();
|
||||
|
||||
Reference in New Issue
Block a user