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

@lcdev/api-fields

v0.1.5

Published

Trim fields from your models before returning in API

Readme

API Fields

Licensed under MPL 2.0 Build Status npm BundlePhobia

A small utility package that enables an easy way to guarantee that your API doesn't return fields that you didn't want it to.

yarn add @lcdev/[email protected]

You might want to reduce the duplication when extracting return values. Most of the time, you want to return the same fields for the same entities, records, etc.

API Fields is a decorator for classes that gives you the ability to tie in to @lcdev/mapper, specifically its extract function.

import { ApiField } from '@lcdev/api-fields';

class User extends BaseEntity {
  @ApiField()
  id: number;

  // we never want to give this back in API responses
  // maybe it's private, or maybe we don't want consumers to depend on it
  privateField: number;

  @ApiField()
  firstName: string;

  // here, we only want the API Fields of Permission in the nested field
  @ApiField(() => Permission)
  permission: Permission;

  ...
}

To reveal the 'Extraction' object that can be used by @lcdev/mapper:

import { getApiFields } from '@lcdev/api-fields';
import { extract } from '@lcdev/mapper';

// getApiFields can be called anywhere to retrieve the `Extraction` object
const extraction = getApiFields(User);

// use the mapper package to take back only the fields you're interested in
const trimmedFields = extract(fullFields, extraction);

Decorator possibilities:

  • @ApiField() property means take all of property
  • @ApiField(() => PropertyType) property means take ApiFields of property
  • @ApiField(() => [PropertyType]) property[] means take ApiFields of all propertys
  • @ApiField({ ... }) property means take { ... } from property

You might want to create middleware in your router to do this type of extraction for you. Internally at Launchcode we do just that, and would like to open-source that effort as well.

Alternatives