Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

deep-pick-omit

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deep-pick-omit

Deep-pick and deep-omit objects with typesafe paths.

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
91K
decreased by-7.73%
Maintainers
0
Weekly downloads
 
Created
Source

deep-pick-omit

npm version bundlephobia license

Deep-pick and deep-omit objects with typesafe paths.

Basic usage

Both deepPick and deepOmit take an object and an array of dot-notation paths to respectively pick and omit from the object. By default, TypeScript will infer types for paths and error if a path does not exist in the object.

deepPick

import { deepPick } from 'deep-pick-omit'

const obj = {
  a: {
    b: 'this',
    c: 'not this'
  },
  d: 'this'
}

deepPick(obj, ['a.b', 'e'])
// -> { a: { b: 'this' }, d: 'this' }

deepPick(obj, ['f'])
// -> TypeScript Error: `f` is not a key of `obj`

deepOmit

import { deepOmit } from 'deep-pick-omit'

const obj = {
  a: {
    b: 'this',
    c: 'not this'
  },
  d: 'this'
}

deepOmit(obj, ['a.c'])
// -> { a: { b: 'this' }, d: 'this' }

deepOmit(obj, ['f'])
// -> TypeScript Error: `f` is not a key of `obj`

[!NOTE] Pathing through array values is not allowed typesafe path methods. See unsafe methods.

Unsafe methods

If paths type-safety is a problem for some edge cases, the package exposes the same methods without the type-checking on paths.

deepPickUnsafe

import { deepPickUnsafe } from 'deep-pick-omit'

const obj = {
  a: {
    c: 'not this'
  },
  d: 'this'
}

deepPickUnsafe(obj, ['d', 'f'])
// -> { d: 'this' }

deepOmitUnsafe

import { deepOmitUnsafe } from 'deep-pick-omit'

const obj = {
  a: {
    b: 'this',
    c: 'not this'
  },
  d: 'this'
}

deepOmitUnsafe(obj, ['a.c', 'f'])
// -> { a: { b: 'this' }, d: 'this' }

License

MIT — Made with 💖.

FAQs

Package last updated on 04 Oct 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc