mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 15:57:13 +00:00
Merge pull request #24484 from ozum/master
[cosmiconfig] cosmiconfig npm module added
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import cosmiconfig = require("cosmiconfig");
|
||||
|
||||
const asyncExplorer = cosmiconfig("yourModuleName", {
|
||||
packageProp: "yourModuleName",
|
||||
rc: ".yourModuleNamerc",
|
||||
js: "yourModuleName.config.js",
|
||||
rcStrictJson: false,
|
||||
rcExtensions: false,
|
||||
stopDir: "someDir",
|
||||
cache: true,
|
||||
sync: false,
|
||||
transform: ({ config, filePath }) => ({ config, filePath }),
|
||||
format: "js"
|
||||
});
|
||||
|
||||
Promise.all([
|
||||
asyncExplorer.load(),
|
||||
asyncExplorer.load("start/search/here"),
|
||||
asyncExplorer.load(null, "load/this/file.json")
|
||||
]).then(result => result);
|
||||
|
||||
asyncExplorer.load().then(({ config, filePath }) => ({ config, filePath }));
|
||||
|
||||
asyncExplorer.clearFileCache();
|
||||
asyncExplorer.clearDirectoryCache();
|
||||
asyncExplorer.clearCaches();
|
||||
|
||||
const syncExplorer = cosmiconfig("yourModuleName", {
|
||||
packageProp: "yourModuleName",
|
||||
rc: ".yourModuleNamerc",
|
||||
js: "yourModuleName.config.js",
|
||||
rcStrictJson: false,
|
||||
rcExtensions: false,
|
||||
stopDir: "someDir",
|
||||
cache: true,
|
||||
sync: true,
|
||||
transform: ({ config, filePath }) => ({ config, filePath }),
|
||||
format: "js"
|
||||
});
|
||||
|
||||
const { config, filePath } = syncExplorer.load();
|
||||
Vendored
+63
@@ -0,0 +1,63 @@
|
||||
// Type definitions for cosmiconfig 4.0
|
||||
// Project: https://github.com/davidtheclark/cosmiconfig
|
||||
// Definitions by: ozum <https://github.com/ozum>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
interface Result {
|
||||
config: object;
|
||||
filePath: string;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
packageProp?: string | false;
|
||||
rc?: string | false;
|
||||
js?: string | false;
|
||||
rcStrictJson?: boolean;
|
||||
rcExtensions?: boolean;
|
||||
stopDir?: string;
|
||||
cache?: boolean;
|
||||
transform?: (result: Result) => Promise<Result> | Result;
|
||||
configPath?: string;
|
||||
format?: "json" | "yaml" | "js";
|
||||
}
|
||||
|
||||
// Default is false and makes load() method async
|
||||
interface AsyncOptions extends Options {
|
||||
sync?: false;
|
||||
}
|
||||
|
||||
// Makes load() method sync
|
||||
interface SyncOptions extends Options {
|
||||
sync: true;
|
||||
}
|
||||
|
||||
interface Explorer {
|
||||
clearFileCache(): void;
|
||||
clearDirectoryCache(): void;
|
||||
clearCaches(): void;
|
||||
}
|
||||
|
||||
interface AsyncExplorer extends Explorer {
|
||||
// You should provide either searchPath or configPath for load method. To disallow both, overloaded definitions added.
|
||||
load(searchPath?: string): Promise<Result>;
|
||||
load(searchPath: null | undefined, configPath?: string): Promise<Result>;
|
||||
}
|
||||
|
||||
interface SyncExplorer extends Explorer {
|
||||
// You should provide either searchPath or configPath for load method. To disallow both, overloaded definitions added.
|
||||
load(searchPath?: string): Result;
|
||||
load(searchPath: null | undefined, configPath?: string): Result;
|
||||
}
|
||||
|
||||
declare function cosmiconfig(
|
||||
moduleName: string,
|
||||
options: SyncOptions
|
||||
): SyncExplorer;
|
||||
|
||||
declare function cosmiconfig(
|
||||
moduleName: string,
|
||||
options?: AsyncOptions
|
||||
): AsyncExplorer;
|
||||
|
||||
export = cosmiconfig;
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": ["index.d.ts", "cosmiconfig-tests.ts"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user