rc-config-loader
Version:
load config file from .{product}rc.{json,yml,js,ts}
24 lines (23 loc) • 1.37 kB
TypeScript
import type { PossibleUndefined, rcConfigLoaderOption, rcConfigResult, loadConfigFileOption } from "./types";
/**
* Find and load rcfile, return { config, filePath }
* If not found any rcfile, throw an Error.
* @param {string} pkgName
* @param {rcConfigLoaderOption} [opts]
* @returns {{ config: Object, filePath:string } | undefined}
*/
export declare function rcFile<R extends {}>(pkgName: string, opts?: rcConfigLoaderOption): PossibleUndefined<rcConfigResult<R>>;
/**
* Load exactly one config file, return { config, filePath }
* - `filePath` is resolved from `opts.cwd`(default: `process.cwd()`)
* - It does not search parent directories, does not append any extension, and does not read `package.json`
* - The loader is selected by the extension of `filePath`
* - `.json` → JSON, `.yaml`/`.yml` → YAML, `.js`/`.cjs`/`.mjs` → JavaScript, `.ts`/`.cts`/`.mts` → TypeScript
* - Other names like `.secretlintrc` are tried as JSON, YAML, then JavaScript (in order of `extensions`)
* - If the file does not exist, throw an Error that has `code: "ENOENT"`
* - If the file can not be parsed, throw an Error
* @param {string} filePath
* @param {loadConfigFileOption} [opts]
* @returns {{ config: Object, filePath:string }}
*/
export declare function loadConfigFile<R extends {}>(filePath: string, opts?: loadConfigFileOption): rcConfigResult<R>;