# path-to-prop

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

Latest version **3.0.2** (published 2025-02-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install path-to-prop
pnpm add path-to-prop
yarn add path-to-prop
bun add path-to-prop
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2025-02-19 |
| First published | 2019-10-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Luca Ban - Mesqueeb |
| Maintainers | mesqueeb |
| Keywords | path-to-prop, dot-prop, dotprop, propdot, dot-notation, dotnotation-prop, delve, prop-at-path, get-prop-at-path, get-property-at-path, get-dot-prop, get-dot-property |

## Links

- npm: https://www.npmjs.com/package/path-to-prop
- Repository: https://github.com/mesqueeb/path-to-prop
- Homepage: https://github.com/mesqueeb/path-to-prop#readme
- Issues: https://github.com/mesqueeb/path-to-prop/issues
- Funding: https://github.com/sponsors/mesqueeb
- npm.io page: https://npm.io/package/path-to-prop

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 3.0.2 (latest) — 2025-02-19
- 3.0.1 — 2024-06-18
- 3.0.0 — 2024-06-01
- 2.0.4 — 2023-05-23
- 2.0.3 — 2023-05-07
- 2.0.2 — 2022-01-26
- 2.0.1 — 2022-01-26
- 2.0.0 — 2022-01-25
- 1.0.2 — 2022-01-25
- 1.0.1 — 2022-01-25
- 1.0.0 — 2020-08-29
- 0.0.3 — 2020-04-18
- 0.0.2 — 2019-12-20
- 0.0.1 — 2019-10-22
- 0.0.0 — 2019-10-22

## README

# Path to prop 🛤

<a href="https://www.npmjs.com/package/path-to-prop"><img src="https://img.shields.io/npm/v/path-to-prop.svg" alt="Total Downloads"></a>
<a href="https://www.npmjs.com/package/path-to-prop"><img src="https://img.shields.io/npm/dw/path-to-prop.svg" alt="Latest Stable Version"></a>

```
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

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

getProp({ nested: { prop: 1 } }, 'nested.prop') // 1

getProp({ nested: { prop: 1 } }, 'nested') // { prop: 1 }
```

You can use `/` or `.` to access nested props:

```js
const obj = {a: {b: {c: {d: {e: 1}}}}}
const path = 'a/b/c.d.e'

getProp(obj, path)
  // returns 1

getProp(obj, 'nonexistent.prop')
  // returns undefined
```

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

```js
const obj = {'a/b': {'c.d': 1}}

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

---
_Source: https://npm.io/package/path-to-prop · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
