0.1.2 â€Ē Published 8 months ago

flambo v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Flambo

A lightweight TypeScript decorator library for building modular class-based applications. Flambo provides utility decorators that reduce boilerplate code while maintaining clean architecture principles.

Installation

npm install flambo
yarn add flambo

Features

  • ðŸŠķ Lightweight with zero dependencies
  • ðŸŽŊ TypeScript-first approach
  • ðŸ§Đ Modular - use only what you need
  • 🔒 Type-safe environment variables handling
  • ðŸ“Ķ Property memoization
  • 📝 Metadata collection utilities

Decorators

@Once

Memoizes getter results after the first call. Perfect for expensive computations or one-time initializations.

class UserService {
  // Without @Once
  private _config: Config | null = null;
  get config(): Config {
    if (!this._config) {
      this._config = new Config();
    }
    return this._config;
  }

  // With @Once
  @Once()
  get config() {
    return new Config();
  }
}

@Env

Simplifies environment variable handling with type conversion and default values.

class ServerConfig {
  @Env(3000)
  port: number;

  @Env({ type: String, default: 'development' })
  nodeEnv: string;

  @Env({ type: 'json', key: 'DB_CONFIG' })
  dbConfig: DatabaseConfig;
}

@PushTo

Collects decorated property names into an array. Useful for metadata collection and reflection.

class ValidationRules {
  // Array can be explicitly defined for type safety
  public requiredFields: string[];

  @PushTo('requiredFields')
  username: string;

  @PushTo('requiredFields')
  password: string;

  // Decorator automatically creates: requiredFields = ['username', 'password']
}

Usage Examples

import { Once, Env, PushTo } from 'flambo';

class AppConfig {
  public initTasks: string[];

  @Env({ type: Number, default: 3000 })
  port: number;

  @Once()
  get databaseUrl(): string {
    return this.buildDatabaseUrl();
  }

  @PushTo('initTasks')
  async connectDatabase() {
    // ...
  }
}

Why Flambo?

Flambo provides lightweight decorators that enhance your classes without enforcing a specific architecture. This makes it perfect for:

  • Building modular services
  • Handling configuration
  • Creating pure class-based containers
  • Reducing boilerplate code
  • Getting rid of DI frameworks
  • Gradual refactoring without rewriting the whole codebase

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

0.1.2

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago