Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding typescript definition file #12

Open
gama410 opened this issue May 29, 2018 · 0 comments
Open

Adding typescript definition file #12

gama410 opened this issue May 29, 2018 · 0 comments

Comments

@gama410
Copy link

gama410 commented May 29, 2018

Hello!

Thanks for your library. It exactly fits my needs here.
I'd like to propose integrating a typescript definition file for those of us working in typescript.

Just for information, here is the code I wrote for the definition file. It should only be added to the project:

`declare module 'timespan' {
export class TimeSpan {
constructor(milliseconds: number, seconds: number, minutes: number, hours: number, days: number);
add(timeSpan: TimeSpan): void;
addMilliseconds(milliseconds: number): void;
addSeconds(seconds: number): void;
addMinutes(minutes: number): void;
addHours(hours: number): void;
addDays(days: number): void;
subtract(timeSpan: TimeSpan): void;
subtractMilliseconds(milliseconds: number): void;
subtractSeconds(seconds: number): void;
subtractMinutes(minutes: number): void;
subtractHours(hours: number): void;
subtractDays(days: number): void;
totalMilliseconds(roundDown: boolean): number;
totalSeconds(roundDown: boolean): number;
totalMinutes(roundDown: boolean): number;
totalHours(roundDown: boolean): number;
totalDays(roundDown: boolean): number;

    equals(timeSpan: TimeSpan): boolean;
    toString(): string;

    readonly milliseconds: number;
    readonly seconds: number;
    readonly minutes: number;
    readonly hours: number;
    readonly days: number;
}
export function fromMilliseconds(milliseconds: number): TimeSpan;
export function fromSeconds(seconds: number): TimeSpan;
export function fromMinutes(minutes: number): TimeSpan;
export function fromHours(hours: number): TimeSpan;
export function fromDays(days: number): TimeSpan;
export function parse(str: string): TimeSpan;
export function parseDate(str: string): Date;
export function fromDates(start: string | Date, end: string | Date, abs: boolean): TimeSpan;
export function test(str: string): boolean;
export function instanceOf(timeSpan: any): boolean;
export function clone(timeSpan: TimeSpan): TimeSpan;

}
`

And reference it in your package.json. eg:

{ "name": "awesome", "author": "Vandelay Industries", "version": "1.0.0", "main": "./lib/main.js", "types": "./lib/main.d.ts" }

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant