seniority
API reference

seniority/cosmiconfig

Every export of seniority/cosmiconfig, with its signature and doc comment: cosmiconfig, cosmiconfigSync, Explorer, ExplorerSync, plus 10 types.

import { cosmiconfig, cosmiconfigSync, Explorer, … } from 'seniority/cosmiconfig';

Functions

cosmiconfig

The asynchronous entry.

function cosmiconfig(moduleName: string, options?: Readonly<Partial<Options>>): PublicExplorer;
ParameterType
moduleNamestring
options (optional)Readonly<Partial<Options>>

Returns PublicExplorer

cosmiconfigSync

The synchronous entry. Constructs ExplorerSync twice — once for the meta config, once for the search.

function cosmiconfigSync(moduleName: string, options?: Readonly<Partial<OptionsSync>>): PublicExplorerSync;
ParameterType
moduleNamestring
options (optional)Readonly<Partial<OptionsSync>>

Returns PublicExplorerSync

Classes

Explorer

The asynchronous explorer.

class Explorer extends ExplorerBase {
    load(filepath: string): Promise<CosmiconfigResult>;
    search(from?: string): Promise<CosmiconfigResult>;
    /** A `metaConfigFilePath` that loads to something non-empty short-circuits the whole search. */
    private searchMetaConfig;
    /** One directory's places, in order; `undefined` means "nothing here, keep walking". Untransformed. */
    private scan;
    private readConfiguration;
    private loadWithImports;
    private loadConfiguration;
    private directories;
}

ExplorerSync

The synchronous explorer. Same decisions, readFileSync and statSync, and no .mjs anywhere.

class ExplorerSync extends ExplorerBase {
    load(filepath: string): CosmiconfigResult;
    search(from?: string): CosmiconfigResult;
    private searchMetaConfig;
    private scan;
    private readConfiguration;
    private loadWithImports;
    private loadConfiguration;
    private directories;
}

Interfaces

CommonOptions

interface CommonOptions {
    packageProp?: string | string[];
    searchPlaces: string[];
    ignoreEmptySearchPlaces: boolean;
    stopDir?: string;
    cache: boolean;
    mergeImportArrays: boolean;
    mergeSearchPlaces: boolean;
    searchStrategy: SearchStrategy;
    /**
     * seniority's one addition: the directory a `global` search ends in. cosmiconfig derives it
     * from the environment through `env-paths`; this package takes it as an argument so nothing
     * here reads `process.*` (R11), and defaults it from `os.homedir()` and the platform.
     */
    globalConfigDir?: string;
}

Options

interface Options extends CommonOptions {
    loaders: Loaders;
    transform: Transform;
}

PublicExplorer

interface PublicExplorer {
    search: (from?: string) => Promise<CosmiconfigResult>;
    load: (filepath: string) => Promise<CosmiconfigResult>;
    clearLoadCache: () => void;
    clearSearchCache: () => void;
    clearCaches: () => void;
}

PublicExplorerSync

interface PublicExplorerSync {
    search: (from?: string) => CosmiconfigResult;
    load: (filepath: string) => CosmiconfigResult;
    clearLoadCache: () => void;
    clearSearchCache: () => void;
    clearCaches: () => void;
}

Types

Config

type Config = unknown;

CosmiconfigResult

type CosmiconfigResult = {
    config: Config;
    filepath: string;
    isEmpty?: boolean;
} | null;

Loaders

type Loaders = Record<string, Loader>;

OptionsSync

type OptionsSync = Options;

SearchStrategy

type SearchStrategy = 'none' | 'project' | 'global';

Transform

type Transform = (result: CosmiconfigResult) => CosmiconfigResult | Promise<CosmiconfigResult>;

On this page