https://github.com/mopsgamer/config
Node.js config library for command-line tools with strict type check.
https://github.com/mopsgamer/config
Last synced: about 1 month ago
JSON representation
Node.js config library for command-line tools with strict type check.
- Host: GitHub
- URL: https://github.com/mopsgamer/config
- Owner: Mopsgamer
- Created: 2024-10-17T12:07:06.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-01-13T18:02:31.000Z (5 months ago)
- Last Synced: 2025-04-05T12:47:03.763Z (2 months ago)
- Language: TypeScript
- Homepage:
- Size: 538 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# @m234/config
[](https://www.npmjs.com/package/@m234/config)
[](https://www.npmjs.com/package/@m234/config)
[](https://github.com/Mopsgamer/config)
[](https://github.com/Mopsgamer/config/issues)Node.js config library for command-line tools with strict type check. Uses yaml format.
## Features
- Validates the config types when loading: any, string, record, struct, integer, number, boolean.
- Each type has options. For examlple there is the 'pattern' option for strings and numbers.
- Struct type has dynamic properties validation ability.## Install
```bash
npm i @m234/config
```## Usage
```ts
import {homedir} from "node:os"
import {exit} from "node:process"
import {join} from "node:path"
import {Config, Types} from "@m234/config"function exitFail(message: string | undefined) {
console.error(message)
process.exit(1)
}const aORb = Types.literal({choices: new Set(['a', 'b'])})
const cfg = new Config({
path: join(homedir(), 'app.yaml'), // or use `find-config` package
type: Types.struct({
properties:{
id: Types.integer({min: 0})
// min 8 chars password
password: Types.string({pattern: /.{8,}/})
records: Types.array({
elementType: aORb
})
}
})
})exitFail(cfg.failLoad())
console.log(cfg.get('id') === 0)
console.log(cfg.getPrintable())
```