{"id":13903208,"url":"https://github.com/CorentinTh/figue","last_synced_at":"2025-07-18T00:33:40.206Z","repository":{"id":57686315,"uuid":"492721657","full_name":"CorentinTh/figue","owner":"CorentinTh","description":"Configuration management library, like convict but with zod","archived":false,"fork":false,"pushed_at":"2024-09-10T12:04:56.000Z","size":297,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-19T05:59:31.469Z","etag":null,"topics":["config","configuration-management","env","environment-variables","zod"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CorentinTh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["CorentinTh"]}},"created_at":"2022-05-16T07:09:42.000Z","updated_at":"2024-09-10T12:05:00.000Z","dependencies_parsed_at":"2024-09-10T13:17:14.136Z","dependency_job_id":"75fde77c-0f9b-4285-8c49-4f86d7f6f7ca","html_url":"https://github.com/CorentinTh/figue","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"d3c7132adff88f7764aec2755d42ff169a7a3ee4"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CorentinTh%2Ffigue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CorentinTh%2Ffigue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CorentinTh%2Ffigue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CorentinTh%2Ffigue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CorentinTh","download_url":"https://codeload.github.com/CorentinTh/figue/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226320952,"owners_count":17606380,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["config","configuration-management","env","environment-variables","zod"],"created_at":"2024-08-06T22:01:52.667Z","updated_at":"2025-07-18T00:33:40.061Z","avatar_url":"https://github.com/CorentinTh.png","language":"TypeScript","funding_links":["https://github.com/sponsors/CorentinTh"],"categories":["config"],"sub_categories":[],"readme":"# Figue\n\n[![ci](https://github.com/CorentinTh/figue/actions/workflows/ci.yml/badge.svg)](https://github.com/CorentinTh/figue/actions/workflows/ci.yml)\n\n\u003e Platform agnostic configuration management library, with environmental variables and validation, like [convict](https://github.com/mozilla/node-convict/tree/master/packages/convict) but simpler, cross env and using [zod schemas](https://github.com/colinhacks/zod).\n\n## Usage\n\nInstall package:\n\n```sh\n# npm\nnpm install figue zod\n\n# yarn\nyarn install figue zod\n\n# pnpm\npnpm install figue zod\n```\n\nImport:\n\n```js\n// ESM\nimport { defineConfig } from 'figue';\n\n// CommonJS\nconst { defineConfig } = require('figue');\n```\n\n## API\n\n### Basic example\n\n```typescript\nimport { defineConfig } from 'figue';\nimport { z } from 'zod';\n\nconst { config } = defineConfig(\n  {\n    env: {\n      doc: 'Application current environment',\n      default: 'development',\n      schema: z.enum(['development', 'production', 'test']),\n      env: 'NODE_ENV',\n    },\n    port: {\n      doc: 'Application port to listen',\n      schema: z.coerce.number().int().positive(),\n      default: 3000,\n      env: 'PORT',\n    },\n    db: {\n      host: {\n        doc: 'Database server url',\n        schema: z.string().url(),\n        default: 'localhost',\n        env: 'APP_DB_HOST',\n      },\n      username: {\n        doc: 'Database server username',\n        schema: z.string(),\n        default: 'pg',\n        env: 'APP_DB_USERNAME',\n      },\n      password: {\n        doc: 'Database server password',\n        schema: z.string(),\n        default: '',\n        env: 'APP_DB_PASSWORD',\n      },\n    },\n  },\n  {\n    envSource: process.env,\n  },\n);\n\nconsole.log(config);\n// {\n//   env: \"development\",\n//   port: 3000,\n//   db: {\n//     url: \"https://localhost\",\n//     username: \"pg\",\n//     password: \"\",\n//   },\n// }\n```\n\n### Load environnement\n\nUse the `envSource` key of the second argument of `defineConfig` to specify the source of the environment variables:\n\n```typescript\nconst { config } = defineConfig(\n  {\n    /* ... */\n  },\n  {\n    envSource: process.env,\n  },\n);\n```\n\nIn some case you don't have access to a `process.env` variable, like with `vite`, just simply load what stores your env variables :\n\n```typescript\nconst { config } = defineConfig(\n  {\n    /* ... */\n  },\n  {\n    envSource: import.meta.env,\n  },\n);\n```\n\nYou can even specify you custom environment storage as long as it's a simple flat object map, for example:\n\n```typescript\nconst { config } = defineConfig(\n  {\n    env: {\n      doc: 'Application current environment',\n      default: 'development',\n      schema: z.enum(['development', 'production', 'test']),\n      env: 'NODE_ENV',\n    },\n\n    /* ... */\n  },\n  {\n    envSource: {\n      NODE_ENV: 'development',\n      PORT: '3000',\n      APP_DB_HOST: 'localhost',\n      APP_DB_USERNAME: 'pg',\n      APP_DB_PASSWORD: '',\n    },\n  },\n);\n```\n\nIf, for some reason, you have multiple sources of environment variables, you can use the `envSources` key of the second argument of `defineConfig` to specify an array of sources:\n\n```typescript\nconst { config } = defineConfig(\n  {\n    /* ... */\n  },\n  {\n    envSource: [import.meta.env, myEnvs],\n  },\n);\n```\n\n### Get defaults\n\nYou can use the `getDefaults` key of the second argument of `defineConfig` to specify a function that will be called to get some defaults:\n\n```typescript\nconst { config } = defineConfig(\n  {\n    env: {\n      doc: 'Application current environment',\n      default: 'development',\n      schema: z.enum(['development', 'production', 'test']),\n      env: 'NODE_ENV',\n    },\n    port: {\n      doc: 'Application port to listen',\n      schema: z.coerce.number().int().positive(),\n      default: 3000,\n      env: 'PORT',\n    },\n  },\n  {\n    envSource: {\n      PORT: 3001,\n    },\n    // The config argument is build from the config definition defaults and the envSources\n    // Typically you will use it to override some defaults based the config\n    getDefaults: ({ config }) =\u003e ({\n      port: config.env === 'test' ? 4444 : config.port,\n    }),\n  },\n);\n\n```\n\nYou can also use the `defaults` property of the second argument of `defineConfig` to specify some static defaults (for example taken from a json file):\n\n```typescript\nconst { config } = defineConfig(\n  {\n    /* ... */\n  },\n  {\n    // Either an array of config partial...\n    defaults: [\n      {\n        port: 4444,\n      },\n    ],\n\n    // ... or a single config partial\n    defaults: {\n      port: 4444,\n    },\n  },\n);\n```\n\n## What's wrong with convict?\n\nConvict is meant to be used in node based environnement, it needs to have access to global variables that may may not be present in some environnement (like `process`, `global`), and it also imports `fs`.\n\n## Figue?\n\n**Figue** is the french for _fig_ -\u003e con-fig.\n\n## Development\n\n- Clone this repository\n- Install dependencies using `pnpm install`\n- Run interactive tests using `pnpm dev`\n\n## Credits\n\nCoded with ❤️ by [Corentin Thomasset](//corentin-thomasset.fr).\n\n## License\n\nThis project is under the [MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCorentinTh%2Ffigue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCorentinTh%2Ffigue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCorentinTh%2Ffigue/lists"}