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 } Copy
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 }
The source object type
The target object type
Static
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.
Example