Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeScript typings #8

Closed
wants to merge 16 commits into from
Closed
29 changes: 29 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export interface Options {
/**
* Directory to start from.
*
* @default process.cwd()
*/
cwd?: string;

/**
* [Normalize](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data.
*
* @default true
*/
normalize?: boolean;
}

export interface PackageMetadata {
[key: string]: unknown;
}

/**
* Returns a `Promise` for the parsed JSON.
*/
export default function (options?: Options): Promise<PackageMetadata>;

/**
* Returns the parsed JSON.
*/
export function sync(options?: Options): PackageMetadata;
8 changes: 8 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {expectType} from 'tsd-check';
import readPkg, {PackageMetadata, sync} from '.';

expectType<PackageMetadata>(await readPkg());
expectType<PackageMetadata>(await readPkg({cwd: '.', normalize: false}));

expectType<PackageMetadata>(sync());
expectType<PackageMetadata>(sync({cwd: '.', normalize: false}));
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd-check"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"keywords": [
"json",
Expand All @@ -37,6 +38,7 @@
},
"devDependencies": {
"ava": "*",
"tsd-check": "^0.2.1",
"xo": "*"
}
}