
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@ilhamtahir/ts-mapper
Advanced tools
[](https://www.npmjs.com/package/@ilhamtahir/ts-mapper) [](https://www.npmjs.com/package/@ilhamtahir/ts-mapper)
Core package for TypeScript object mapping with decorator support. Part of the NestJS Mapper ecosystem.
# npm
npm install @ilhamtahir/ts-mapper
# yarn
yarn add @ilhamtahir/ts-mapper
# pnpm
pnpm add @ilhamtahir/ts-mapper
profile.bio// user.entity.ts
export class UserEntity {
id: number;
fullName: string;
age: number;
email: string;
profile: {
bio: string;
avatar: string;
};
}
// user.dto.ts
export class UserDto {
id: number;
name: string;
age: number;
email: string;
bio: string;
avatar: string;
}
// user.mapper.ts
import { Mapper, Mapping, transform } from '@ilhamtahir/ts-mapper';
@Mapper()
export class UserMapper {
@Mapping({ source: 'fullName', target: 'name' })
@Mapping({ source: 'profile.bio', target: 'bio' })
@Mapping({ source: 'profile.avatar', target: 'avatar' })
toDto(entity: UserEntity): UserDto {
return transform(this, 'toDto', entity, UserDto);
}
}
// app.ts
const userMapper = new UserMapper();
const entity = {
id: 1,
fullName: 'John Doe',
age: 30,
email: 'john@example.com',
profile: {
bio: 'Software Developer',
avatar: 'avatar.jpg',
},
};
const dto = userMapper.toDto(entity);
console.log(dto);
// Output:
// {
// id: 1,
// name: 'John Doe',
// age: 30,
// email: 'john@example.com',
// bio: 'Software Developer',
// avatar: 'avatar.jpg'
// }
// user-abstract.mapper.ts
import { Mapper, Mapping } from '@ilhamtahir/ts-mapper';
@Mapper()
export abstract class UserAbstractMapper {
/**
* Empty method body: system will automatically call transform
*/
@Mapping({ source: 'fullName', target: 'name' })
@Mapping({ source: 'profile.bio', target: 'bio' })
@Mapping({ source: 'profile.avatar', target: 'avatar' })
toDto(entity: UserEntity): UserDto {
// Empty method body, system will automatically call transform
return {} as UserDto;
}
/**
* Batch conversion
*/
toDtoList(entities: UserEntity[]): UserDto[] {
return entities.map(entity => this.toDto(entity));
}
}
// Usage
const userMapper = createMapperProxy(UserAbstractMapper);
const dto = userMapper.toDto(entity);
@Mapper(): Mark class as mapper@Mapping({ source, target }): Explicit field mapping definitiontransform(mapper, method, input, OutputType): Execute mapping transformationcreateMapperProxy(MapperClass): Create proxy object supporting auto-mapping# Make sure you have the correct TypeScript version
npm install typescript@^4.7.0 --save-dev
# Enable experimental decorators in tsconfig.json
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
MIT License
FAQs
[](https://www.npmjs.com/package/@ilhamtahir/ts-mapper) [](https://www.npmjs.com/package/@ilhamtahir/ts-mapper)
We found that @ilhamtahir/ts-mapper demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.