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

path-to-prop

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

path-to-prop

Retrieves a property from an object based on a 'path/to.that.prop'

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Path to prop 🛤

Total Downloads Latest Stable Version

npm i path-to-prop

Retrieves a property from an object based on a 'path/to.that.prop'

  • Supports paths with both / and . to separate props
  • Safely typed (with TypeScript) - returns unknown

Usage

import { getProp } from 'path-to-prop'

const target = {a: {b: {c: {d: {e: 1}}}}}
const path = 'a/b/c.d.e'

getProp(target, path)
  // returns 1

getProp(target, 'nonexistent.prop')
  // returns undefined

When you have / or . in your prop names, use an array:

const target = {'a/b': {'c.d': 1}}

getProp(target, ['a/b', 'c.d'])
  // returns 1

Keywords

FAQs

Package last updated on 25 Jan 2022

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