diff --git a/types/node-hook/index.d.ts b/types/node-hook/index.d.ts new file mode 100644 index 0000000000..320587b4b3 --- /dev/null +++ b/types/node-hook/index.d.ts @@ -0,0 +1,22 @@ +// Type definitions for node-hook 1.0 +// Project: https://github.com/bahmutov/node-hook#readme +// Definitions by: Nathan Hardy +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface Options { + verbose?: boolean; +} + +type Transform = (source: string, filename: string) => string; + +interface NodeHook { + hook: { + (extension: string, transform: Transform, options?: Options): void; + (transform: Transform, _?: undefined, options?: Options): void; + }; + unhook(extension?: string): void; +} + +declare const hook: NodeHook; + +export = hook; diff --git a/types/node-hook/node-hook-tests.ts b/types/node-hook/node-hook-tests.ts new file mode 100644 index 0000000000..3f38febbb0 --- /dev/null +++ b/types/node-hook/node-hook-tests.ts @@ -0,0 +1,12 @@ +import hook = require("node-hook"); + +function logLoadedFilename(source: string, filename: string) { + return `console.log(${JSON.stringify(filename)});\n${source}`; +} + +hook.hook(logLoadedFilename); +hook.hook(logLoadedFilename, undefined, { verbose: true }); +hook.hook(".ts", logLoadedFilename); +hook.hook(".ts", logLoadedFilename, {}); +hook.unhook(); +hook.unhook(".ts"); diff --git a/types/node-hook/tsconfig.json b/types/node-hook/tsconfig.json new file mode 100644 index 0000000000..a994dca051 --- /dev/null +++ b/types/node-hook/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "node-hook-tests.ts" + ] +} diff --git a/types/node-hook/tslint.json b/types/node-hook/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/node-hook/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }