# config-file-ts-async

> Use Typescript for configuration files. Types for safety. Compiled for speed. Built for Node JS.

Latest version **1.0.7** (published 2025-02-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install config-file-ts-async
pnpm add config-file-ts-async
yarn add config-file-ts-async
bun add config-file-ts-async
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2025-02-20 |
| First published | 2024-10-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 37.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Shea Martin |
| Maintainers | shea.martin |
| Keywords | typescript, config, configuration, conf, cli, cached, command, cmd, command-line |

## Links

- npm: https://www.npmjs.com/package/config-file-ts-async
- Repository: https://github.com/sheam/config-file-ts-async
- Homepage: https://github.com/sheam/config-file-ts-async#readme
- Issues: https://github.com/sheam/config-file-ts-async/issues
- npm.io page: https://npm.io/package/config-file-ts-async

## Dependencies (3)

- [glob](https://npm.io/package/glob.md) ^10.3.12
- [tsconfig](https://npm.io/package/tsconfig.md) ^7.0.0
- [typescript](https://npm.io/package/typescript.md) ^5.4.3

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 1.0.7 (latest) — 2025-02-20
- 1.0.6 — 2025-02-20
- 1.0.5 — 2024-10-09
- 1.0.4 — 2024-10-09
- 1.0.3 — 2024-10-08
- 1.0.2 — 2024-10-08
- 1.0.2-rc.2.0 — 2024-10-08
- 1.0.1-rc.0 — 2024-10-08
- 1.0.0-rc.0 — 2024-10-08
- 0.4.0 — 2024-10-04
- 0.3.0 — 2024-10-04
- 0.3.0-rc1 — 2024-10-03

## README

## config-file-ts-async

_Just use TypeScript for configuration files._

#### Fork Info

Based on config-file-ts by _lee mighdoll_.
This version adds support for the following

- asynchronous operations
- flexible cache storage locations
- reads nearest tsconfig.json file to get _some_ settings.

If you feel like helping me justify the time I am spending on an already great package...

[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/sheamus)

### Summary

TypeScript is more syntactically **flexible** than JSON. Comments are allowed. Keys needn't be quoted.
Arrays can have trailing commas.

TypeScript allows a little **programming** in config files. Share variables, use utility functions, etc.

TypeScript **types** provide free error checking, and free IDE support for getting config files right.

### Fast

Parsing TypeScript config files is plenty quick. config-file-ts caches the TypeScript output.

Assuming TypeScript is in your environment, config-file-ts adds about 5kb to your program, or 1.5kb minified.

### How to use

```bash
$ yarn add config-file-ts-async
```

In the config file, export default. `my.config.ts`:

```ts
export default {
  entry: 'my stuff', // comments are welcome now
};
```

Feel free to add types and scripting. `my.config.ts`:

```ts
import os from 'os'; // use installed libraries in the config
import { MyConfig } from './MyProgram';

export default {
  entry: `${os.userInfo().username}'s stuff`, // use scripting in the config file
} as MyConfig; // typecheck the config file
```

Read the config file in your program. `MyProgram.ts`:

```ts
export interface MyConfig {
  entry?: string;
}

const config = await loadTsConfig<MyConfig>('my.config.ts', {
  cacheType: 'local',
});
```

### tsconfig.json

You can control how the config file is compiled with a TS Config file.
The options honoured are: strict and module. So you can put a tsconfig.json file beside your config file:

```json
{
  "compilerOptions": {
    "strict": true, // this setting is honoured
    "module": "CommonJS", // or "NodeNext" is also supported
    "target": "ESNext", // hardcoded: but set it in your tsconfig for linting purposes
    "esModuleInterop": true // this setting is honoured
  }
}
```

---
_Source: https://npm.io/package/config-file-ts-async · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
