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

object-pick-omit-ts

v1.0.0

Published

Ultra-fast, type-safe nested object projection with dot-notation path support for picking and omitting properties in TypeScript.

Readme

object-pick-omit-ts

Ultra-fast, type-safe nested object projection with dot-notation path support for picking and omitting properties in TypeScript.

npm version npm downloads license bundle size sponsor


Why object-pick-omit-ts?

Transforming objects is one of the most common tasks in JavaScript and TypeScript. However:

  1. Lodash Overhead: Importing lodash.pick or lodash.omit pulls in multiple transitive dependencies and bloated prototype chains.
  2. Missing Dot Notation: Standard solutions only handle flat top-level keys. Extracting deeply nested fields (e.g. user.profile.avatar) requires writing fragile traversal code.
  3. Security Vulnerabilities: Naive object property pickers are susceptible to prototype pollution exploits via __proto__ and constructor attacks.
  4. TypeScript Safety: You lose autocompletion and strict compile-time types when relying on un-typed helper libraries.

object-pick-omit-ts provides an elegant, robust solution:

  • Strictly Typed: pick and omit preserve native TypeScript type inference (Pick<T, K> and Omit<T, K>).
  • Dot-Notation Path Projections: Use pickDeep and omitDeep with dot paths like 'profile.settings.theme' effortlessly.
  • Prototype-Pollution Protected: Hardened against __proto__, constructor, and prototype injection vectors.
  • Conditional Projections: pickBy and omitBy filter by value or predicate.
  • Zero Dependencies: Pure TypeScript, tiny footprint (<750 bytes minified & gzipped).

Installation

Install using your preferred package manager:

# npm
npm install object-pick-omit-ts

# pnpm
pnpm add object-pick-omit-ts

# yarn
yarn add object-pick-omit-ts

# bun
bun add object-pick-omit-ts

Quick Start

import { pick, omit, pickDeep, omitDeep } from 'object-pick-omit-ts';

interface User {
  id: number;
  name: string;
  email: string;
  passwordHash: string;
  role: string;
}

const user: User = {
  id: 42,
  name: 'Alex',
  email: '[email protected]',
  passwordHash: 'argon2_secret_hash',
  role: 'member',
};

// 1. Type-safe Pick
const publicProfile = pick(user, ['id', 'name']);
// Result type: Pick<User, 'id' | 'name'>
console.log(publicProfile); // { id: 42, name: 'Alex' }

// 2. Type-safe Omit
const safeRecord = omit(user, ['passwordHash']);
// Result type: Omit<User, 'passwordHash'>
console.log(safeRecord); // { id: 42, name: 'Alex', email: '[email protected]', role: 'member' }

Real-World Examples

Example 1: Sanitizing Database Records for Public API Responses

Prevent accidental data leaks (passwords, internal salts, access tokens) before sending responses over the wire:

import { omit } from 'object-pick-omit-ts';

export async function getUserEndpoint(req, res) {
  const dbUser = await db.users.findById(req.params.id);

  // Strip sensitive internal fields safely
  const publicUser = omit(dbUser, [
    'passwordHash',
    'twoFactorSecret',
    'resetToken',
    'internalNotes',
  ]);

  return res.json(publicUser);
}

Example 2: Deep Nested Dot-Notation Extraction (pickDeep)

Extract only necessary nested fields from complex nested third-party payloads (like Stripe, GitHub, or Shopify webhooks):

import { pickDeep } from 'object-pick-omit-ts';

const stripeWebhookEvent = {
  id: 'evt_12345',
  type: 'customer.subscription.created',
  data: {
    object: {
      id: 'sub_999',
      customer: 'cus_555',
      plan: {
        id: 'plan_pro',
        amount: 2900,
        currency: 'usd',
      },
      status: 'active',
    },
  },
};

// Project only essential properties
const summary = pickDeep(stripeWebhookEvent, [
  'id',
  'type',
  'data.object.customer',
  'data.object.plan.amount',
]);

console.log(summary);
/*
{
  id: 'evt_12345',
  type: 'customer.subscription.created',
  data: {
    object: {
      customer: 'cus_555',
      plan: {
        amount: 2900
      }
    }
  }
}
*/

Example 3: Deep Nested Omit (omitDeep)

Remove confidential sub-properties from complex nested configurations without mutating the source:

import { omitDeep } from 'object-pick-omit-ts';

const serverConfig = {
  app: { name: 'Storefront', port: 3000 },
  database: {
    host: 'localhost',
    port: 5432,
    credentials: {
      username: 'db_admin',
      password: 'super_secret_password',
    },
  },
};

const safeConfig = omitDeep(serverConfig, [
  'database.credentials.password',
]);

console.log(safeConfig.database.credentials);
// { username: 'db_admin' }

Example 4: Conditional Filtering with pickBy and omitBy

Strip empty, null, or undefined values before saving to database:

import { omitBy } from 'object-pick-omit-ts';

const formData = {
  title: 'New Post',
  description: '',
  published: true,
  coAuthor: null,
  tags: undefined,
};

// Remove null and undefined values
const cleaned = omitBy(formData, (val) => val === null || val === undefined);
console.log(cleaned);
// { title: 'New Post', description: '', published: true }

API Reference

pick<T, K>(obj, keys)

Creates an object composed of the selected keys.

  • obj: Source object.
  • keys: Array of keys ((keyof T)[]).
  • Returns: Pick<T, K>.

omit<T, K>(obj, keys)

Creates an object omitting the selected keys.

  • obj: Source object.
  • keys: Array of keys ((keyof T)[]).
  • Returns: Omit<T, K>.

pickBy<T>(obj, predicate)

Filters object entries where predicate(value, key) returns true.

  • predicate: (value: T[keyof T], key: keyof T) => boolean.
  • Returns: Partial<T>.

omitBy<T>(obj, predicate)

Filters object entries where predicate(value, key) returns false.

  • predicate: (value: T[keyof T], key: keyof T) => boolean.
  • Returns: Partial<T>.

pickDeep<T>(obj, paths)

Projects nested dot-notation paths (e.g. ['user.profile.avatar']) into a newly constructed nested object.


omitDeep<T>(obj, paths)

Deeply clones an object and deletes the specified dot-notation paths without mutating the original input.


Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.


License

MIT © Pirapaakaran Pirathapan

Support & Sponsor

If you find this utility useful in your projects, please consider supporting my open-source work:

💖 Sponsor Piratha97 on GitHub