Skip to content

Commit

Permalink
chore: readme changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmarqs committed Jun 1, 2024
1 parent f8f9a48 commit 04ff737
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ yarn add zod-config zod # yarn
- [Combine multiple adapters](#combine-multiple-adapters)
- [Callbacks](#callbacks)
- [Custom Logger](#custom-logger)
- [Silent mode](#silent-mode)
- [Contributing notes](#contributing-notes)
- [On the web](#on-the-web)

Expand All @@ -58,7 +59,7 @@ Zod Config provides a `loadConfig` function that takes a Zod Object schema and r
| `adapters` | `Adapter[] or Adapter` | Adapter(s) to load the configuration from. If not provided, process.env will be used. The interface `Adapter` includes an optional flag `silent` to avoid logs if adapter fails. | `false` |
| `onError` | `(error: Error) => void` | A callback to be called when an error occurs. | `false` |
| `onSuccess` | `(config: z.infer ) => void` | A callback to be called when the configuration is loaded successfully. | `false` |
| `logger` | `Logger` | A custom logger to be used to log messages. By default, it uses `console`. Currently we only log warnings internally. The `Logger` interface can be extended in the future. | `false` |
| `logger` | `Logger` | A custom logger to be used to log messages. By default, it uses `console`. Currently we only log warnings internally however the `Logger` interface can be extended in the future if needed. | `false` |

From the package we also expose the types `Adapter`, `Config` and `Logger` in case you want to use them in your own adapters.

Expand Down Expand Up @@ -119,14 +120,6 @@ const customConfig = await loadConfig({
IGNORED_KEY: 'ignored',
}})
});

// using silent flag to avoid logs if adapter fails
const customSilentConfig= await loadConfig({
schema: schemaConfig,
adapters: envAdapter({
silent: true,
})
});
```

#### JSON Adapter
Expand Down Expand Up @@ -242,7 +235,7 @@ loadConfig({

### Custom Logger

You can provide a custom logger to be used to log messages. By default, it uses `console`. Currently we only log warnings internally. This interface can be extended in the future.
You can provide a custom logger to be used to log messages. By default, it uses `console`.

```ts
import { z } from 'zod';
Expand All @@ -265,6 +258,26 @@ const config = await loadConfig({
});
```

### Silent mode

You can use the `silent` flag in the adapters to avoid any internal logs if the adapter fails. Example with the built-in `envAdapter`:

```ts
import { z } from 'zod';
import { loadConfig } from 'zod-config';
import { envAdapter } from 'zod-config/env-adapter';

const schemaConfig = z.object({
port: z.string().regex(/^\d+$/),
host: z.string(),
});

const config = await loadConfig({
schema: schemaConfig,
adapters: envAdapter({ silent: true }),
});
```



## Contributing notes
Expand Down

0 comments on commit 04ff737

Please sign in to comment.