Add types for node-hook (#45394)

This commit is contained in:
Nathan Hardy 2020-06-24 01:40:40 +10:00 committed by GitHub
parent 208abc071d
commit 48dcc91662
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 0 deletions

22
types/node-hook/index.d.ts vendored Normal file
View File

@ -0,0 +1,22 @@
// Type definitions for node-hook 1.0
// Project: https://github.com/bahmutov/node-hook#readme
// Definitions by: Nathan Hardy <https://github.com/nhardy>
// 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;

View File

@ -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");

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }