1 | // Type definitions for require-directory 2.1
|
2 | // Project: https://github.com/troygoode/node-require-directory/
|
3 | // Definitions by: Ihor Chulinda <https://github.com/Igmat>
|
4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
5 | // TypeScript Version: 2.4
|
6 | /// <reference types="node" />
|
7 |
|
8 | declare namespace requireDirectory {
|
9 | /**
|
10 | * @description function that checks path for whitelisting/blacklisting
|
11 | * @param path path of required module
|
12 | * @returns true if path have to be whitelisted/blacklisted, false otherwise
|
13 | */
|
14 | type CheckPathFn = (path: string) => boolean;
|
15 |
|
16 | interface RequireDirectoryResult<T> {
|
17 | /**
|
18 | * @description module itself or hash of modules in subdirectory with name of this directory
|
19 | */
|
20 | [index: string]: RequireDirectoryResult<T> | T;
|
21 | }
|
22 | interface RequireDirectoryOptions<T, U = T> {
|
23 | /**
|
24 | * @description array of file extensions that will be included in resulting hash as modules
|
25 | * @default "['js', 'json', 'coffee']"
|
26 | */
|
27 | extensions?: string[];
|
28 | /**
|
29 | * @description option to include subdirectories
|
30 | * @default true
|
31 | */
|
32 | recurse?: boolean;
|
33 | /**
|
34 | * @description RegExp or function for whitelisting modules
|
35 | * @default undefined
|
36 | */
|
37 | include?: RegExp | CheckPathFn;
|
38 | /**
|
39 | * @description RegExp or function for blacklisting modules
|
40 | * @default undefined
|
41 | */
|
42 | exclude?: RegExp | CheckPathFn;
|
43 | /**
|
44 | * @description function for renaming modules in resulting hash
|
45 | * @param name name of required module
|
46 | * @returns transformed name of module
|
47 | * @default "change nothing"
|
48 | */
|
49 | rename?(name: string): string;
|
50 | /**
|
51 | * @description function that will be called for each required module
|
52 | * @param obj required module
|
53 | * @returns transformed module OR nothing (in second case module itself will be added to hash)
|
54 | * @default "change nothing"
|
55 | */
|
56 | visit?(obj: T): U | void;
|
57 | }
|
58 |
|
59 | /**
|
60 | * @description default options that is used for "require-directory" module
|
61 | */
|
62 | const defaults: RequireDirectoryOptions<any>;
|
63 | }
|
64 |
|
65 | /**
|
66 | * @description function for requiring directory content as hash of modules
|
67 | * @param m module for which has will be created
|
68 | * @param path path to directory, if you want to build hash for another one (default to __dirname)
|
69 | * @param options object with options for require-directory call
|
70 | * @returns hash of modules in specified directory
|
71 | */
|
72 | declare function requireDirectory<T, U>(
|
73 | m: NodeModule,
|
74 | path?: string | requireDirectory.RequireDirectoryOptions<T, U>,
|
75 | options?: requireDirectory.RequireDirectoryOptions<T, U>): requireDirectory.RequireDirectoryResult<U>;
|
76 |
|
77 | export = requireDirectory;
|