function createDecorator
Since 0.1.0
createDecorator(
name: string,
metadata: Readonly<Record<string, unknown>>
): SetuClassOrMethodDecorator

Creates a custom class or method decorator that stores metadata readable by the DecoratorPlugin and custom decorator handlers.

At registration, for each registered DecoratorHandler whose name matches, the handler is invoked with (metadata, target, propertyKey?).

Examples

Example 1

export const Cacheable = (ttl: number) => createDecorator('cache:cacheable', { ttl });

Parameters

name: string

Unique decorator name (convention: plugin-name:decorator)

metadata: Readonly<Record<string, unknown>>

Arbitrary metadata payload

Return Type

A class or method decorator

Usage

import { createDecorator } from "decorator-plugin/src/index.ts";