Class Mapper<TSource, TTarget>

Generic mapper for transforming objects from one type to another.

Provides a fluent API for defining field-by-field mappings between source and target types. Supports both direct property mappings and custom transformation functions.

interface UserDTO { firstName: string; lastName: string; age: number; }
interface UserEntity { fullName: string; isAdult: boolean; }

const mapper = Mapper.create<UserDTO, UserEntity>()
.addField('fullName', (dto) => `${dto.firstName} ${dto.lastName}`)
.addField('isAdult', (dto) => dto.age >= 18);

const user = mapper.map({ firstName: 'John', lastName: 'Doe', age: 25 });
// Result: { fullName: 'John Doe', isAdult: true }

Type Parameters

  • TSource

    The source object type

  • TTarget

    The target object type

Constructors

Methods

Constructors

Methods