add types for find-package-json (#30628)

This commit is contained in:
Dimitri Benin 2018-11-18 19:24:22 +00:00 committed by Pranav Senthilnathan
parent 05c33e7019
commit efb26511dd
4 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,19 @@
"use strict";
import finder = require("find-package-json");
const f = finder();
const fDirname = finder(__dirname);
const fModule: finder.FinderIterator = finder(module);
const findResult = f.next();
if (findResult.done) {
const res: finder.Done = findResult;
const value: undefined = findResult.value;
const filename: undefined = findResult.filename;
} else {
const res: finder.FoundPackage = findResult;
const value: finder.Package = findResult.value;
const filename: string = findResult.filename;
}

63
types/find-package-json/index.d.ts vendored Normal file
View File

@ -0,0 +1,63 @@
// Type definitions for find-package-json 1.1
// Project: https://github.com/3rd-Eden/find-package-json#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node"/>
export = finder;
import Module = NodeJS.Module;
declare function finder(root?: string | Module): finder.FinderIterator;
declare namespace finder {
interface FinderIterator {
next(): FindResult;
}
type FindResult = FoundPackage | Done;
interface FoundPackage {
done: false;
value: Package;
filename: string;
}
interface Done {
done: true;
value: undefined;
filename: undefined;
}
interface Person {
name?: string;
email?: string;
url?: string;
}
interface Package {
[k: string]: any;
name?: string;
version?: string;
files?: string[];
bin?: { [k: string]: string };
man?: string[];
keywords?: string[];
author?: Person;
maintainers?: Person[];
contributors?: Person[];
bundleDependencies?: { [name: string]: string };
dependencies?: { [name: string]: string };
devDependencies?: { [name: string]: string };
optionalDependencies?: { [name: string]: string };
description?: string;
engines?: { [type: string]: string };
license?: string;
repository?: { type: string; url: string };
bugs?: { url: string; email?: string } | { url?: string; email: string };
homepage?: string;
scripts?: { [k: string]: string };
readme?: string;
}
}

View File

@ -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",
"find-package-json-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }