npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ilhamtahir/ts-mapper

v1.0.4

Published

[![npm version](https://img.shields.io/npm/v/@ilhamtahir/ts-mapper.svg)](https://www.npmjs.com/package/@ilhamtahir/ts-mapper) [![npm downloads](https://img.shields.io/npm/dm/@ilhamtahir/ts-mapper.svg)](https://www.npmjs.com/package/@ilhamtahir/ts-mapper)

Downloads

8

Readme

@ilhamtahir/ts-mapper

npm version npm downloads npm license PRs Welcome

Core package for TypeScript object mapping with decorator support. Part of the NestJS Mapper ecosystem.

📦 Installation

# npm
npm install @ilhamtahir/ts-mapper

# yarn
yarn add @ilhamtahir/ts-mapper

# pnpm
pnpm add @ilhamtahir/ts-mapper

🚀 Features

  • Compile-time Safety: Fully TypeScript-based with type safety guarantees
  • Minimal Intrusion: Decorator-driven approach with minimal impact on existing code
  • Automatic Field Mapping: Auto-assignment for same-named fields with type checking
  • Nested Path Support: Support for nested field mapping like profile.bio
  • Abstract Class Support: Support for abstract classes and empty method body auto-mapping
  • Proxy Auto Implementation: Empty method bodies automatically call transform

📖 Quick Start

1. Define Entity and DTO

// 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;
}

2. Create Mapper

// 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);
  }
}

3. Use Mapper

// app.ts
const userMapper = new UserMapper();

const entity = {
  id: 1,
  fullName: 'John Doe',
  age: 30,
  email: '[email protected]',
  profile: {
    bio: 'Software Developer',
    avatar: 'avatar.jpg',
  },
};

const dto = userMapper.toDto(entity);
console.log(dto);
// Output:
// {
//   id: 1,
//   name: 'John Doe',
//   age: 30,
//   email: '[email protected]',
//   bio: 'Software Developer',
//   avatar: 'avatar.jpg'
// }

🆕 Abstract Class + Proxy Support

Using Abstract Class (Recommended)

// 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);

📚 API Documentation

Decorators

  • @Mapper(): Mark class as mapper
  • @Mapping({ source, target }): Explicit field mapping definition

Utility Functions

  • transform(mapper, method, input, OutputType): Execute mapping transformation
  • createMapperProxy(MapperClass): Create proxy object supporting auto-mapping

🔧 Troubleshooting

TypeScript Compilation Errors

# 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
  }
}

📋 Resources

🤝 Related Packages

📄 License

MIT License