From f44f31789c08ce190cf58b0d441977dabb968f24 Mon Sep 17 00:00:00 2001 From: Samuel Bodin <1637651+bodinsamuel@users.noreply.github.com> Date: Fri, 7 Feb 2020 00:29:16 +0100 Subject: [PATCH] feat(nanotimer): complete definition (#42153) * feat(nanotimer): complete definition * lint --- types/nanotimer/index.d.ts | 65 ++++++++++++++++++++++++++++++ types/nanotimer/nanotimer-tests.ts | 10 +++++ types/nanotimer/tsconfig.json | 19 +++++++++ types/nanotimer/tslint.json | 1 + 4 files changed, 95 insertions(+) create mode 100644 types/nanotimer/index.d.ts create mode 100644 types/nanotimer/nanotimer-tests.ts create mode 100644 types/nanotimer/tsconfig.json create mode 100644 types/nanotimer/tslint.json diff --git a/types/nanotimer/index.d.ts b/types/nanotimer/index.d.ts new file mode 100644 index 0000000000..34633c59c1 --- /dev/null +++ b/types/nanotimer/index.d.ts @@ -0,0 +1,65 @@ +// Type definitions for nanotimer 0.3 +// Project: https://github.com/Krb686/nanotimer +// Definitions by: Samuel Bodin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace NanoTimer { + interface TimeoutResults { + waitTime: number; + } +} + +declare class NanoTimer { + /** + * Creates an instance of NanoTimer. + * @param log - if true, will enable logging. + */ + constructor(log?: boolean); + + /** + * Call the task after the waiting the the timeout specified. + */ + setTimeout( + task: (...args: any[]) => void, + args: any[] | string, + timeout: string, + callback?: (results: NanoTimer.TimeoutResults) => void, + ): void; + + /** + * Clears current running timeOut. + */ + clearTimeout(): void; + + /** + * Call the task at the regular interval specified in interval. + */ + setInterval( + task: (...args: any[]) => void, + args: any[] | string, + interval: string, + callback?: (error: Error) => void, + ): void; + + /** + * Clears current running interval. + */ + clearInterval(): void; + + /** + * Calculate the time it tooks to execute the task. + */ + time( + task: (cb: () => void) => void, + args: string | any[], + interval: string, + callback?: (error: Error) => void, + ): number; + + /** + * Returns true if the timer currently has a scheduled timeout, or false otherwise + */ + hasTimeout(): boolean; +} + +export = NanoTimer; diff --git a/types/nanotimer/nanotimer-tests.ts b/types/nanotimer/nanotimer-tests.ts new file mode 100644 index 0000000000..5fa6cac0b9 --- /dev/null +++ b/types/nanotimer/nanotimer-tests.ts @@ -0,0 +1,10 @@ +import NanoTimer = require('nanotimer'); + +const timer = new NanoTimer(); +timer.setInterval(() => {}, '', '1s'); +timer.setTimeout(() => {}, [timer], '10s'); +const runtimeSeconds = timer.time(() => {}, '', 'u'); + +timer.clearInterval(); +timer.clearTimeout(); +timer.hasTimeout(); diff --git a/types/nanotimer/tsconfig.json b/types/nanotimer/tsconfig.json new file mode 100644 index 0000000000..15300efee4 --- /dev/null +++ b/types/nanotimer/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "nanotimer-tests.ts" + ] +} \ No newline at end of file diff --git a/types/nanotimer/tslint.json b/types/nanotimer/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/nanotimer/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }