From c2cd90a611ffc174be0c29c17d0388d054a8bbc7 Mon Sep 17 00:00:00 2001 From: spacejack Date: Tue, 15 May 2018 23:54:12 -0400 Subject: [PATCH] Add types for tail module --- types/tail/index.d.ts | 40 ++++++++++++++++++++++++++++++++++++++++ types/tail/test.ts | 26 ++++++++++++++++++++++++++ types/tail/tsconfig.json | 19 +++++++++++++++++++ types/tail/tslint.json | 3 +++ 4 files changed, 88 insertions(+) create mode 100644 types/tail/index.d.ts create mode 100644 types/tail/test.ts create mode 100644 types/tail/tsconfig.json create mode 100644 types/tail/tslint.json diff --git a/types/tail/index.d.ts b/types/tail/index.d.ts new file mode 100644 index 0000000000..00f80ab079 --- /dev/null +++ b/types/tail/index.d.ts @@ -0,0 +1,40 @@ +// Type definitions for tail 1.2 +// Project: https://github.com/lucagrulla/node-tail +// Definitions by: Mike Linkovich +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +declare namespace Tail { + interface TailOptions { + separator?: string | RegExp; + fromBeginning?: boolean; + fsWatchOptions?: Record; + follow?: boolean; + logger?: any; + encoding?: string; + useWatchFile?: boolean; + } + + interface Tail { + /** Callback to listen for newlines appended to file */ + on(eventType: 'line', cb: (data: any) => void): void; + /** Error callback */ + on(eventType: 'error', cb: (error: any) => void): void; + /** Stop watching file */ + unwatch(): void; + /** Start watching file if previously stopped */ + watch(): void; + } + + interface TailConstructor { + /** Creates a new Tail object that starts watching the specified file immediately. */ + new(filename: string, options?: TailOptions): Tail; + } + + interface Static { + Tail: TailConstructor; + } +} + +declare const Tail: Tail.Static; +export = Tail; diff --git a/types/tail/test.ts b/types/tail/test.ts new file mode 100644 index 0000000000..aa212a5b78 --- /dev/null +++ b/types/tail/test.ts @@ -0,0 +1,26 @@ +import { Tail } from 'tail'; + +const tail = new Tail("test.txt"); + +tail.on("line", data => { + console.log(data); +}); + +tail.on("error", error => { + console.log('ERROR: ', error); +}); + +tail.unwatch(); + +tail.watch(); + +// With options object +const tail2 = new Tail("test2.txt", { + separator: /[\r]{0,1}\n/, + fromBeginning: false, + fsWatchOptions: {}, + follow: true, + logger: console, + useWatchFile: false, + encoding: 'utf-8' +}); diff --git a/types/tail/tsconfig.json b/types/tail/tsconfig.json new file mode 100644 index 0000000000..20be91772d --- /dev/null +++ b/types/tail/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es2015", "dom"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "forceConsistentCasingInFileNames": true, + "noEmit": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [] + }, + "files": [ + "index.d.ts", + "test.ts" + ] +} diff --git a/types/tail/tslint.json b/types/tail/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/tail/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}