feat(AppData): Refactor AppData class for declarative env mapping and enhanced static helpers
This commit is contained in:
38
readme.md
38
readme.md
@@ -259,6 +259,44 @@ AppData intelligently handles boolean conversions:
|
||||
}
|
||||
```
|
||||
|
||||
### Static Helper Functions
|
||||
|
||||
AppData provides convenient static methods for directly accessing and converting environment variables without creating an instance:
|
||||
|
||||
```typescript
|
||||
import { AppData } from '@push.rocks/npmextra';
|
||||
|
||||
// Get environment variable as boolean
|
||||
const isEnabled = await AppData.valueAsBoolean('FEATURE_ENABLED');
|
||||
// Returns: true if "true", false otherwise
|
||||
|
||||
// Get environment variable as parsed JSON
|
||||
interface Config {
|
||||
timeout: number;
|
||||
retries: number;
|
||||
}
|
||||
const config = await AppData.valueAsJson<Config>('SERVICE_CONFIG');
|
||||
// Returns: Parsed object or undefined
|
||||
|
||||
// Get environment variable as base64 decoded string
|
||||
const secret = await AppData.valueAsBase64('ENCODED_SECRET');
|
||||
// Returns: Decoded string or undefined
|
||||
|
||||
// Get environment variable as string
|
||||
const apiUrl = await AppData.valueAsString('API_URL');
|
||||
// Returns: String value or undefined
|
||||
|
||||
// Get environment variable as number
|
||||
const port = await AppData.valueAsNumber('PORT');
|
||||
// Returns: Number value or undefined
|
||||
```
|
||||
|
||||
These static methods are perfect for:
|
||||
- Quick environment variable access without setup
|
||||
- Simple type conversions in utility functions
|
||||
- One-off configuration checks
|
||||
- Scenarios where you don't need the full AppData instance
|
||||
|
||||
## Advanced Patterns 🎨
|
||||
|
||||
### Reactive Configuration
|
||||
|
Reference in New Issue
Block a user