diff --git a/types/filing-cabinet/filing-cabinet-tests.ts b/types/filing-cabinet/filing-cabinet-tests.ts new file mode 100644 index 0000000000..5397fbf6a7 --- /dev/null +++ b/types/filing-cabinet/filing-cabinet-tests.ts @@ -0,0 +1,19 @@ +import cabinet = require('filing-cabinet'); + +const result = cabinet({ + partial: 'somePartialPath', + directory: 'path/to/all/files', + filename: 'path/to/parent/file', + ast: {}, + config: 'path/to/requirejs/config', + webpackConfig: 'path/to/webpack/config', + nodeModulesConfig: { + entry: 'module', + }, + tsConfig: 'path/to/typescript/config', +}); +result; // $ExpectType string + +cabinet.register('.scss', (partial, filename, directory, config) => { + return `file.scss`; +}); diff --git a/types/filing-cabinet/index.d.ts b/types/filing-cabinet/index.d.ts new file mode 100644 index 0000000000..e8e9253451 --- /dev/null +++ b/types/filing-cabinet/index.d.ts @@ -0,0 +1,59 @@ +// Type definitions for filing-cabinet 2.5 +// Project: https://github.com/mrjoelkemp/node-filing-cabinet +// Definitions by: Piotr Błażejewicz (Peter Blazejewicz) +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace cabinet { + interface Options { + /** the dependency path */ + partial: string; + /** the path to all files */ + directory: string; + /** the path to the file containing the partial */ + filename: string; + /** + * the parsed AST for filename + * Useful optimization for avoiding a parse of filename + */ + ast?: any; + /** + * `requirejs` config for resolving aliased JavaScript modules + */ + config?: any; + /** + * `webpack` config for resolving aliased JavaScript modules + */ + webpackConfig?: any; + /** + * config for resolving entry file for `node_modules`. + * This value overrides the main attribute in the `package.json` file; + * used in conjunction with the `packageFilter` of the resolve package + */ + nodeModulesConfig?: any; + /** + * Path to a typescript configuration. + * Could also be an object representing a pre-parsed typescript config + */ + tsConfig?: string | object; + /** + * For typescript files, whether to prefer *.js over *.d.ts + */ + noTypeDefinitions?: boolean; + } + + type Resolver = (partial: string, filename: string, directory: string, config?: any) => void; + + /** + * Register a custom lookup resolver for a file extension + * If a given extension does not have a registered resolver, + * cabinet will use a generic file resolver which is basically `require('path').join` + * with a bit of extension defaulting logic + * @param extension the extension of the file that should use the custom resolver (ex: '.py', '.php') + * @param resolver A resolver of partial paths + */ + function register(extension: string, resolver: Resolver): void; +} + +declare function cabinet(options: cabinet.Options): string; + +export = cabinet; diff --git a/types/filing-cabinet/tsconfig.json b/types/filing-cabinet/tsconfig.json new file mode 100644 index 0000000000..095e72e3db --- /dev/null +++ b/types/filing-cabinet/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", + "filing-cabinet-tests.ts" + ] +} diff --git a/types/filing-cabinet/tslint.json b/types/filing-cabinet/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/filing-cabinet/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }