API
@agape/metadata

Token Decorator

Specifies a token for the decorated class, property, method, or parameter.

API

@Token(  token: undefined | string,  plural?: string)

Token

Specifies a token for the decorated class, property, method, or parameter.

@paramtoken:  undefined | string
@paramplural:  string

Description

Specifies a token for the decorated class, property, method, or parameter.

Tokens can be used when referencing the object or attribute—for example, as CSS classes or in URLs. While tokens can technically take any form, the recommended format is lowercase kebab-case, as it is concise and widely recognizable.

This decorator sets the token and tokens properties on the associated MetadataDescriptor.

Usage

Class

@Token('product', 'products')
class Product {
  name: string;
  price: number;
}

Property

class Product {
  @Token('sku-code')
  skuCode: string;
}

Method

class ProductService {
  @Token('product')
  getProduct(id: string): void {
    // ...
  }
}

Parameter

class ProductService {
  create(@Token('product') product: Product): void {
    // ...
  }
}