Skip to content

Commit

Permalink
Add TypeScript definition (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 15, 2019
1 parent 4396ac2 commit d24b63a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
48 changes: 48 additions & 0 deletions index.d.ts
@@ -0,0 +1,48 @@
declare namespace pkgUp {
interface Options {
/**
Directory to start from.
@default process.cwd()
*/
readonly cwd?: string;
}
}

declare const pkgUp: {
/**
Find the closest `package.json` file.
@returns The filepath, or `null` if it couldn't be found.
@example
```
// /
// └── Users
// └── sindresorhus
// └── foo
// ├── package.json
// └── bar
// ├── baz
// └── example.js
// example.js
import pkgUp = require('pkg-up');
(async () => {
console.log(await pkgUp());
//=> '/Users/sindresorhus/foo/package.json'
})();
```
*/
(options?: pkgUp.Options): Promise<string | null>;

/**
Synchronously find the closest `package.json` file.
@returns The filepath, or `null` if it couldn't be found.
*/
sync(options?: pkgUp.Options): string | null;
};

export = pkgUp;
7 changes: 7 additions & 0 deletions index.test-d.ts
@@ -0,0 +1,7 @@
import {expectType} from 'tsd';
import pkgUp = require('.');

expectType<Promise<string | null>>(pkgUp());
expectType<Promise<string | null>>(pkgUp({cwd: '.'}));
expectType<string | null>(pkgUp.sync());
expectType<string | null>(pkgUp.sync({cwd: '.'}));
8 changes: 5 additions & 3 deletions package.json
Expand Up @@ -13,10 +13,11 @@
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"keywords": [
"pkg",
Expand Down Expand Up @@ -44,7 +45,8 @@
"find-up": "^3.0.0"
},
"devDependencies": {
"ava": "^1.3.1",
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

0 comments on commit d24b63a

Please sign in to comment.