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

typemold

v2.0.0

Published

A lightweight, high-performance object mapper for TypeScript and Node.js with runtime field projection

Readme

typemold

A lightweight, high-performance object mapper for TypeScript & Node.js with runtime field projection.

npm version License: MIT Downloads

Features

  • High Performance - Compiled mappers cached after first use (no runtime reflection)
  • 🎯 Runtime Field Projection - Pick/omit fields without creating multiple DTOs
  • 📦 Lightweight - ~3KB gzipped, zero runtime dependencies
  • 🏷️ Field Groups - Define reusable field sets with decorators
  • 🔧 NestJS Integration - Full module support with DI (separate import)
  • TypeScript First - Full strict mode support
  • 🔄 Hybrid Validation - Optional class-validator integration

📦 Installation

Node.js / Express / Fastify

npm install typemold reflect-metadata
// Usage
import { Mapper, AutoMap, MapFrom } from "typemold";

NestJS

npm install typemold reflect-metadata
// Core decorators & Mapper
import { Mapper, AutoMap, MapFrom } from "typemold";

// NestJS module & service (separate subpath)
import { MapperModule, MapperService } from "typemold/nestjs";

Note: NestJS integration requires @nestjs/common and @nestjs/core (usually already installed in NestJS projects).


🚀 Quick Start

1. Define Your DTO

import { AutoMap, MapFrom, FieldGroup } from "typemold";

class UserDto {
  @AutoMap()
  username: string;

  @MapFrom("profile.avatar")
  avatarUrl: string;

  @MapFrom((src) => src.age >= 18)
  isAdult: boolean;

  @AutoMap()
  email: string;
}

2. Map Objects

import { Mapper } from "typemold";

// Basic mapping
const userDto = Mapper.map(userEntity, UserDto);

// Array mapping
const userDtos = Mapper.mapArray(users, UserDto);

⭐ Runtime Field Projection

The killer feature - reuse a single DTO across multiple endpoints:

// Full user profile
Mapper.map(user, UserDto);
// Result: { username, avatarUrl, isAdult, email }

// Only username and avatar
Mapper.pick(user, UserDto, ["username", "avatarUrl"]);
// Result: { username, avatarUrl }

// Exclude sensitive fields
Mapper.omit(user, UserDto, ["email"]);
// Result: { username, avatarUrl, isAdult }

// Using options object
Mapper.map(user, UserDto, { pick: ["username", "avatarUrl"] });
Mapper.map(user, UserDto, { omit: ["email"] });

🏷️ Field Groups

Define reusable field sets:

class UserDto {
  @FieldGroup("minimal", "public")
  @AutoMap()
  username: string;

  @FieldGroup("minimal", "public")
  @MapFrom("profile.avatar")
  avatar: string;

  @FieldGroup("public", "full")
  @AutoMap()
  bio: string;

  @FieldGroup("full")
  @AutoMap()
  email: string;
}

// Use field groups
Mapper.group(user, UserDto, "minimal"); // { username, avatar }
Mapper.group(user, UserDto, "public"); // { username, avatar, bio }
Mapper.group(user, UserDto, "full"); // { bio, email }

🎨 Decorators

| Decorator | Description | Example | | ------------------------- | ---------------------------- | ------------------------------------------------ | | @AutoMap() | Maps property with same name | @AutoMap() name: string | | @MapFrom(path) | Maps from nested path | @MapFrom('profile.avatar') avatar: string | | @MapFrom(fn) | Custom transform | @MapFrom(src => src.age > 18) isAdult: boolean | | @FieldGroup(...groups) | Assigns to field groups | @FieldGroup('minimal', 'public') | | @Ignore() | Skips property | @Ignore() internalId: string | | @NestedType(() => Type) | Nested object mapping | @NestedType(() => AddressDto) |


🔧 NestJS Integration

Import from typemold/nestjs

Setup

import { Module } from "@nestjs/common";
import { MapperModule } from "typemold/nestjs";

@Module({
  imports: [MapperModule.forRoot()],
})
export class AppModule {}

Using MapperService

import { Injectable } from "@nestjs/common";
import { MapperService } from "typemold/nestjs";

@Injectable()
export class UserService {
  constructor(private readonly mapper: MapperService) {}

  async getUser(id: string): Promise<UserDto> {
    const user = await this.userRepo.findOne(id);
    return this.mapper.map(user, UserDto);
  }

  async getUserMinimal(id: string) {
    const user = await this.userRepo.findOne(id);
    return this.mapper.group(user, UserDto, "minimal");
  }
}

Async Configuration

MapperModule.forRootAsync({
  imports: [ConfigModule],
  useFactory: (config: ConfigService) => ({
    enableValidation: config.get("ENABLE_VALIDATION"),
  }),
  inject: [ConfigService],
});

⚡ Performance

| Operation | typemold | @automapper/nestjs | Manual | | ------------ | ---------- | ------------------ | -------- | | Single map | ~0.002ms | ~0.05ms | ~0.001ms | | Array (1000) | ~1.5ms | ~40ms | ~1ms | | Memory | O(1) cache | O(n) profiles | None |


📚 API Reference

Mapper (Static)

Mapper.map(source, TargetDto, options?)
Mapper.mapArray(sources, TargetDto, options?)
Mapper.pick(source, TargetDto, ['field1', 'field2'])
Mapper.omit(source, TargetDto, ['field1'])
Mapper.group(source, TargetDto, 'groupName')
Mapper.createMapper(TargetDto, options?)

MapOptions

interface MapOptions<T> {
  pick?: (keyof T)[]; // Include only these fields
  omit?: (keyof T)[]; // Exclude these fields
  group?: string; // Use predefined field group
  extras?: Record<string, unknown>; // Extra context for transforms
}

License

MIT © Chetan Joshi