diff --git a/types/module-alias/index.d.ts b/types/module-alias/index.d.ts new file mode 100644 index 0000000000..09fd2f7ed8 --- /dev/null +++ b/types/module-alias/index.d.ts @@ -0,0 +1,47 @@ +// Type definitions for module-alias 2.0 +// Project: https://github.com/ilearnio/module-alias/ +// Definitions by: Kevin Ramharak +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped/ + +export = init; + +/** + * Import aliases from package.json + */ +declare function init(options?: string | init.Options): void; + +/** + * Exported functoins + */ +declare namespace init { + function isPathMatchesAlias(path: string, alias: string): boolean; + + /** + * Register a custom modules directory + */ + function addPath(path: string): void; + + /** + * Register a single alias + */ + function addAlias(alias: string, path: string): void; + + /** + * Register mutliple aliases + */ + function addAliases(aliases: { [alias: string]: string }): void; + + /** + * Reset any changes maded (resets all registered aliases + * and custom module directories) + * The function is undocumented and for testing purposes only + */ + function reset(): void; + + /** + * module intialis options type + */ + interface Options { + base: string; + } +} diff --git a/types/module-alias/module-alias-tests.ts b/types/module-alias/module-alias-tests.ts new file mode 100644 index 0000000000..6e5ddfc7ee --- /dev/null +++ b/types/module-alias/module-alias-tests.ts @@ -0,0 +1,12 @@ +import moduleAlias = require('module-alias'); + +moduleAlias('path'); // $ExpectType void +moduleAlias({ base : 'path' }); // $ExpectType void + +moduleAlias.isPathMatchesAlias('./path', '@alias'); // $ExpectType boolean + +moduleAlias.addPath('path'); // $ExpectType void +moduleAlias.addAliases({ alias : 'path', anotherAlias : 'anotherPath' }); // $ExpectType void +moduleAlias.addAlias('@alias', 'somePath'); // $ExpectType void + +moduleAlias.reset(); // $ExpectType void diff --git a/types/module-alias/tsconfig.json b/types/module-alias/tsconfig.json new file mode 100644 index 0000000000..b9063a644a --- /dev/null +++ b/types/module-alias/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "module-alias-tests.ts" + ] +} diff --git a/types/module-alias/tslint.json b/types/module-alias/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/module-alias/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }