npm.io
1.2.1 • Published 5d ago

@shipfox/config

Licence
MIT
Version
1.2.1
Deps
0
Vulns
0
Weekly
0
Stars
10

Shipfox Config

Typed config for Shipfox packages. It checks process.env at startup and returns a typed object.

What it does

  • createConfig(schema, update?) checks environment values with envalid.
  • Common validators are re-exported: str, num, bool, email, host, port, and url.
  • Fail-fast startup means bad values throw before the app runs.

Installation

pnpm add @shipfox/config
# or
yarn add @shipfox/config
# or
npm install @shipfox/config

Usage

import {bool, createConfig, num, str} from "@shipfox/config";

const config = createConfig({
  NODE_ENV: str({choices: ["development", "test", "production"]}),
  PORT: num({default: 3000}),
  DEBUG: bool({default: false}),
});

config.PORT; // number
config.DEBUG; // boolean

Pass update in tests to override process.env:

const testConfig = createConfig({PORT: num()}, {PORT: "4000"});

Development

turbo check --filter=@shipfox/config
turbo type --filter=@shipfox/config
turbo test --filter=@shipfox/config

License

MIT