-
Notifications
You must be signed in to change notification settings - Fork 0
range param
awekrx edited this page May 29, 2026
·
1 revision
import { rangeParam } from '@dev-suite/decorators/range-param'
parameter
Validate numeric argument is inside required range.
- Inline min/max checks and throws
- Repeated validation helpers
class LoanService {
quote(termMonths: number) {
if (termMonths < 6 || termMonths > 84) throw new Error('Out of range');
return this.engine.quote(termMonths);
}
}import { rangeParam } from '@dev-suite/decorators/range-param';
class LoanService {
quote(@rangeParam({ min: 6, max: 84 }) termMonths: number) {
return this.engine.quote(termMonths);
}
}- Centralizes cross-cutting behavior.
- Method/class/property code stays focused on domain logic.
class TaxService {
calc(rate: number) {
if (rate < 0 || rate > 1) throw new Error('Invalid rate');
return this.core.calc(rate);
}
}import { rangeParam } from '@dev-suite/decorators/range-param';
class TaxService {
calc(@rangeParam({ min: 0, max: 1 }) rate: number) {
return this.core.calc(rate);
}
}- Second scenario reuses same policy without duplication.
- Behavior is more consistent and easier to audit.