# object-standard-path

> Safely get/set deep nested properties with standard path, strong type support

Latest version **0.3.1** (published 2024-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install object-standard-path
pnpm add object-standard-path
yarn add object-standard-path
bun add object-standard-path
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2024-09-07 |
| First published | 2023-05-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | easilyjs |
| Maintainers | easilyjs |
| Keywords | dot, path, get, set, update, change, standard, value, deep, nested, object, property, typescript, type, access, notation, array |

## Links

- npm: https://www.npmjs.com/package/object-standard-path
- Repository: https://github.com/react-earth/object-standard-path
- Homepage: https://github.com/react-earth/object-standard-path#readme
- Issues: https://github.com/react-earth/object-standard-path/issues
- npm.io page: https://npm.io/package/object-standard-path

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

- 0.3.1 (latest) — 2024-09-07
- 0.3.0 — 2023-06-12
- 0.2.4 — 2023-06-02
- 0.2.3 — 2023-06-01
- 0.2.2 — 2023-05-29
- 0.2.1 — 2023-05-24
- 0.2.0 — 2023-05-24
- 0.1.0 — 2023-05-23

## README

![title](media/repo-header.svg)

<p align="center">
<a href="https://github.com/react-earth/object-standard-path" target="\_parent"><img alt="star" src="https://img.shields.io/github/stars/react-earth/object-standard-path.svg?style=social&label=Star" /></a>
<a href="https://www.npmjs.com/package/object-standard-path" target="\_parent"><img src="https://img.shields.io/npm/v/object-standard-path" alt="version"></a>
<a href="https://www.npmjs.com/package/object-standard-path" target="\_parent"><img alt="minzip" src="https://img.badgesize.io/https:/unpkg.com/object-standard-path@latest/dist/index.esm.js?compression=gzip" /></a>
<a href="https://www.npmjs.com/package/object-standard-path" target="\_parent"><img alt="downloads" src="https://img.shields.io/npm/dm/object-standard-path.svg" /></a>
<a href="https://github.com/react-earth/object-standard-path" target="\_parent"><img alt="license" src="https://img.shields.io/npm/l/object-standard-path" /></a>
</p>

## Quick Features 🥳

- Standard path, e.g. `a.b.c[0].d`.
- Provider types & utils: Path, PathValue, pathGet, pathSet, pathSetImmutable.
- Built with typescript, provide type protection, code autocompletion, make your app robust.
- No dependencies, less than 1kB page size.

## How to use 📖

### Install package

```shell
npm install object-standard-path
```

### Use types: Path, PathValue

```typescript
import { Path, PathValue } from 'object-standard-path';

type Test = {
  value: string;
  array: {
    value: string;
  }[];
};

type TestPath = Path<Test>;
// result: "value" | "array" | `array[${number}]` | `array[${number}].value`

type TestPathValue = PathValue<Test, 'array[0]'>;
// result: { value: string }
```

### Use utils: pathGet, pathSet, pathSetImmutable

```typescript
import { pathGet, pathSet, pathSetImmutable } from 'object-standard-path';

const object = {
  array: [
    {
      value: 1,
    },
  ],
};

const result = pathGet(object, 'array[0].value');
// result: 1

pathSet(object, 'array[0].value', 2);
// object: { array: [{ value: 2 }] }

const result = pathSetImmutable(object, 'array[0].value', 2);
// result: { array: [{ value: 2 }] }
```

**Notes: please don't include the characters `.[]` in the key of the object, as they may affect parsing.**

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