Skip to content
awekrx edited this page May 29, 2026 · 1 revision

trim

Import

import { trim } from '@dev-suite/decorators/trim'

Category

  • parameter

Use Case

Trim whitespace from string argument.

Replaces

  • Manual .trim() in each handler
  • Normalization utility calls everywhere

Example 1

Without decorator

class UserService {
  updateName(name: string) {
    return this.repo.updateName(name.trim());
  }
}

With decorator

import { trim } from '@dev-suite/decorators/trim';

class UserService {
  updateName(@trim() name: string) {
    return this.repo.updateName(name);
  }
}

Why better

  • Centralizes cross-cutting behavior.
  • Method/class/property code stays focused on domain logic.

Example 2

Without decorator

class SearchService {
  query(q: string) {
    return this.engine.query(q.trim());
  }
}

With decorator

import { trim } from '@dev-suite/decorators/trim';

class SearchService {
  query(@trim({ collapseWhitespace: true }) q: string) {
    return this.engine.query(q);
  }
}

Why better

  • Second scenario reuses same policy without duplication.
  • Behavior is more consistent and easier to audit.

Clone this wiki locally