feature-toggle-package
Version:
A lightweight and flexible feature toggle (feature flag) implementation for JavaScript/TypeScript applications
75 lines (58 loc) • 1.6 kB
Markdown
# Feature Toggle Package
A lightweight and flexible feature toggle (feature flag) implementation for JavaScript/TypeScript applications.
## Installation
```bash
npm install feature-toggle-package
```
## Features
- Hierarchical configuration with modules, submodules, and features
- TypeScript support with full type definitions
- Zero dependencies
- Simple and intuitive API
## Usage
```typescript
import { FeatureToggle, AppConfig } from 'feature-toggle-package';
const config: AppConfig = {
modules: {
authentication: {
enabled: true,
submodules: {
social: {
enabled: true,
features: {
googleLogin: true,
facebookLogin: false
}
}
}
}
}
};
const featureToggle = new FeatureToggle(config);
// Check if a module is enabled
const isAuthEnabled = featureToggle.isFeatureEnabled('authentication');
// Check if a submodule is enabled
const isSocialEnabled = featureToggle.isFeatureEnabled('authentication', 'social');
// Check if a specific feature is enabled
const isGoogleLoginEnabled = featureToggle.isFeatureEnabled('authentication', 'social', 'googleLogin');
```
## Configuration Structure
```typescript
interface AppConfig {
modules: {
[moduleName: string]: {
enabled: boolean;
submodules?: {
[submoduleName: string]: {
enabled: boolean;
features?: {
[featureName: string]: boolean;
};
};
};
};
};
}
```
## License
ISC