From 5776fe227c6b2b13c7fc60c0e38de280c73faae5 Mon Sep 17 00:00:00 2001 From: Corentin Thomasset Date: Sun, 21 Sep 2025 00:28:34 +0200 Subject: [PATCH] docs(examples): add demo with multiple validation libs --- README.md | 1 + demo/figue-mix.ts | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 demo/figue-mix.ts diff --git a/README.md b/README.md index 4d5bc76..f237d38 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/demo/figue-mix.ts b/demo/figue-mix.ts new file mode 100644 index 0000000..2974560 --- /dev/null +++ b/demo/figue-mix.ts @@ -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 = { + ['~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: '' } +// }