# seniority/cosmiconfig

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

Source: https://seniority.interlace.tools/docs/api/cosmiconfig

<!-- Generated by scripts/api-reference.ts from the built dist/*.d.ts. Do not edit; run `npx tsx scripts/api-reference.ts`. -->

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

## Functions

### cosmiconfig

The asynchronous entry.

```ts
function cosmiconfig(moduleName: string, options?: Readonly<Partial<Options>>): PublicExplorer;
```

| Parameter | Type |
| :-- | :-- |
| `moduleName` | `string` |
| `options` (optional) | `Readonly<Partial<Options>>` |

**Returns** `PublicExplorer`

### cosmiconfigSync

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

```ts
function cosmiconfigSync(moduleName: string, options?: Readonly<Partial<OptionsSync>>): PublicExplorerSync;
```

| Parameter | Type |
| :-- | :-- |
| `moduleName` | `string` |
| `options` (optional) | `Readonly<Partial<OptionsSync>>` |

**Returns** `PublicExplorerSync`

## Classes

### Explorer

The asynchronous explorer.

```ts
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.

```ts
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

```ts
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

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

### PublicExplorer

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

### PublicExplorerSync

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

## Types

### Config

```ts
type Config = unknown;
```

### CosmiconfigResult

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

### Loaders

```ts
type Loaders = Record<string, Loader>;
```

### OptionsSync

```ts
type OptionsSync = Options;
```

### SearchStrategy

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

### Transform

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