diff --git a/types/pkg-conf/index.d.ts b/types/pkg-conf/index.d.ts new file mode 100644 index 0000000000..6a783c1891 --- /dev/null +++ b/types/pkg-conf/index.d.ts @@ -0,0 +1,34 @@ +// Type definitions for pkg-conf 2.1 +// Project: https://github.com/sindresorhus/pkg-conf#readme +// Definitions by: Jorge Gonzalez +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +declare namespace pkgConf { + type AnyJson = boolean | number | string | null | JsonArray | JsonMap; + interface JsonArray extends Array { } + interface JsonMap { + [key: string]: AnyJson; + } + + interface Options { + // Directory to start looking up for a package.json file. + // Default: process.cwd() + cwd?: string; + // Default config. + defaults?: object; + // Skip package.json files that have the namespaced config explicitly set to false. + skipOnFalse?: boolean; + } + + // Returns the config. + function sync(namespace: string, options?: Options): JsonMap; + // Pass in the config returned from any of the above methods. + // Returns the filepath to the package.json file or null when not found. + function filepath(config: JsonMap): string | null; +} + +// Returns a Promise for the config. +declare function pkgConf(namespace: string, options?: pkgConf.Options): Promise; + +export = pkgConf; diff --git a/types/pkg-conf/pkg-conf-tests.ts b/types/pkg-conf/pkg-conf-tests.ts new file mode 100644 index 0000000000..bf2dee1e2f --- /dev/null +++ b/types/pkg-conf/pkg-conf-tests.ts @@ -0,0 +1,6 @@ +import pkgConf = require('pkg-conf'); + +pkgConf('name'); // $ExpectType Promise +const config = pkgConf.sync('bugs'); // $ExpectType JsonMap +pkgConf.filepath(config); // $ExpectType string | null +config.url; // $ExpectType AnyJson diff --git a/types/pkg-conf/tsconfig.json b/types/pkg-conf/tsconfig.json new file mode 100644 index 0000000000..449922d19e --- /dev/null +++ b/types/pkg-conf/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "pkg-conf-tests.ts" + ] +} diff --git a/types/pkg-conf/tslint.json b/types/pkg-conf/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/pkg-conf/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }