Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Think of it as a modern version of [convict](https://github.com/mozilla/node-con
- Multiple sources of configuration
- Type-safe configuration
- Composable configuration
- No runtime dependencies

## Usage

Expand Down
65 changes: 65 additions & 0 deletions demo/figue-mix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { StandardSchemaV1 } from '@standard-schema/spec';
import { defineConfig } from 'figue';
import { z } from 'zod';
import * as v from 'valibot';

const passwordSchema: StandardSchemaV1<unknown, string> = {
['~standard']: {
version: 1,
vendor: 'custom',
validate: (value) => {
if (typeof value !== 'string') {
return { issues: [{ message: 'Password must be a string' }] };
}

return { value };
},
},
};

const { config } = defineConfig(
{
env: {
doc: 'Application current environment',
default: 'development',
schema: v.picklist(['development', 'production', 'test']),
env: 'NODE_ENV',
},
port: {
doc: 'Application port to listen',
schema: z.coerce.number(),
default: 3000,
env: 'PORT',
},
db: {
host: {
doc: 'Database server url',
schema: z.url(),
default: 'http://localhost:5432',
env: 'APP_DB_HOST',
},
username: {
doc: 'Database server username',
schema: v.string(),
default: 'pg',
env: 'APP_DB_USERNAME',
},
password: {
doc: 'Database server password',
schema: passwordSchema,
default: '',
env: 'APP_DB_PASSWORD',
},
},
},
{
envSource: process.env,
},
);

console.log(config);
// {
// env: 'development',
// port: 3000,
// db: { host: 'http://localhost:5432', username: 'pg', password: '' }
// }