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