File tree Expand file tree Collapse file tree 4 files changed +100
-0
lines changed Expand file tree Collapse file tree 4 files changed +100
-0
lines changed Original file line number Diff line number Diff line change
1
+ import findCacheDir = require( 'find-cache-dir' ) ;
2
+
3
+ findCacheDir ( { name : 'unicorns' } ) ; // $ExpectType string | null
4
+ findCacheDir ( { name : 'unicorns' , files : 'foo' } ) ; // $ExpectType string | null
5
+ findCacheDir ( { name : 'unicorns' , files : [ 'foo' , 'bar' ] } ) ; // $ExpectType string | null
6
+ findCacheDir ( { name : 'unicorns' , cwd : 'foo' } ) ; // $ExpectType string | null
7
+ findCacheDir ( { name : 'unicorns' , create : true } ) ; // $ExpectType string | null
8
+ findCacheDir ( { name : 'unicorns' , thunk : false } ) ; // $ExpectType string | null
9
+ findCacheDir ( { } ) ; // $ExpectError
10
+ findCacheDir ( ) ; // $ExpectError
11
+
12
+ const thunk = findCacheDir ( { name : 'unicorns' , thunk : true } ) ;
13
+ thunk ; // $ExpectType ((...pathParts: string[]) => string) | null
14
+
15
+ if ( thunk ) {
16
+ thunk ( ) ; // $ExpectType string
17
+ thunk ( 'bar.js' ) ; // $ExpectType string
18
+ thunk ( 'baz' , 'quz.js' ) ; // $ExpectType string
19
+ }
Original file line number Diff line number Diff line change
1
+ // Type definitions for find-cache-dir 2.0
2
+ // Project: https://github.com/avajs/find-cache-dir#readme
3
+ // Definitions by: BendingBender <https://github.com/BendingBender>
4
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
+
6
+ export = findCacheDir ;
7
+
8
+ /**
9
+ * Finds the cache directory using the supplied options. The algorithm tries to find a `package.json` file,
10
+ * searching every parent directory of the `cwd` specified (or implied from other options).
11
+ * @param options
12
+ * @returns A string containing the absolute path to the cache directory, or null if package.json was never found.
13
+ */
14
+ declare function findCacheDir (
15
+ options : findCacheDir . OptionsWithThunk
16
+ ) : ( ( ...pathParts : string [ ] ) => string ) | null ;
17
+ declare function findCacheDir ( options : findCacheDir . Options ) : string | null ;
18
+
19
+ declare namespace findCacheDir {
20
+ interface Options {
21
+ /**
22
+ * Should be the same as your project name in `package.json`.
23
+ */
24
+ name : string ;
25
+
26
+ /**
27
+ * An array of files that will be searched for a common parent directory.
28
+ * This common parent directory will be used in lieu of the `cwd` option below.
29
+ */
30
+ files ?: string | string [ ] ;
31
+
32
+ /**
33
+ * Directory to start searching for a `package.json` from.
34
+ */
35
+ cwd ?: string ;
36
+
37
+ /**
38
+ * If `true`, the directory will be created synchronously before returning.
39
+ * @default false
40
+ */
41
+ create ?: boolean ;
42
+
43
+ /**
44
+ * If `true`, this modifies the return type to be a function that is a thunk for `path.join(theFoundCacheDirectory)`.
45
+ * @default false
46
+ */
47
+ thunk ?: boolean ;
48
+ }
49
+
50
+ interface OptionsWithThunk extends Options {
51
+ /**
52
+ * If `true`, this modifies the return type to be a function that is a thunk for `path.join(theFoundCacheDirectory)`.
53
+ * @default false
54
+ */
55
+ thunk : true ;
56
+ }
57
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "compilerOptions" : {
3
+ "module" : " commonjs" ,
4
+ "lib" : [
5
+ " es6"
6
+ ],
7
+ "noImplicitAny" : true ,
8
+ "noImplicitThis" : true ,
9
+ "strictNullChecks" : true ,
10
+ "strictFunctionTypes" : true ,
11
+ "baseUrl" : " ../" ,
12
+ "typeRoots" : [
13
+ " ../"
14
+ ],
15
+ "types" : [],
16
+ "noEmit" : true ,
17
+ "forceConsistentCasingInFileNames" : true
18
+ },
19
+ "files" : [
20
+ " index.d.ts" ,
21
+ " find-cache-dir-tests.ts"
22
+ ]
23
+ }
Original file line number Diff line number Diff line change
1
+ { "extends" : " dtslint/dt.json" }
You can’t perform that action at this time.
0 commit comments