# @nodescript/pointer

> Simple Object Get/Set

Latest version **1.8.0** (published 2024-07-12) · ISC license · 0 weekly downloads

## Install

```sh
npm install @nodescript/pointer
pnpm add @nodescript/pointer
yarn add @nodescript/pointer
bun add @nodescript/pointer
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.8.0 |
| Published | 2024-07-12 |
| First published | 2022-11-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Boris Okunskiy |
| Maintainers | mattscarthsaunders, danielolaviobr, inca |

## Links

- npm: https://www.npmjs.com/package/@nodescript/pointer
- Repository: https://github.com/nodescript/pointer
- Homepage: https://github.com/nodescript/pointer#readme
- Issues: https://github.com/nodescript/pointer/issues
- npm.io page: https://npm.io/package/@nodescript/pointer

## Recent versions

- 1.8.0 (latest) — 2024-07-12
- 1.7.0 — 2024-07-04
- 1.6.1 — 2023-12-27
- 1.6.0 — 2023-06-06
- 1.5.0 — 2023-05-30
- 1.4.0 — 2023-05-30
- 1.3.0 — 2023-05-30
- 1.2.0 — 2023-05-29
- 1.1.0 — 2023-05-15
- 1.0.3 — 2022-11-29

## README

# NodeScript Pointer

Simple library for getting and setting object values via [JSON Pointer](https://www.rfc-editor.org/rfc/rfc6901.html) or dot-delimited formats.

## Highlights

- 🔥 Zero dependencies
- 💻 Works in browser
- 🗜 Tidy and compact, only ~500 bytes minified uncompressed
- ⚡️ Blazing fast

## Usage

```ts
import * as pointer from '@nodescript/pointer';

const object = {
    foo: {
        items: [
            { bar: 'one' },
            { bar: 'two' },
            { bar: 'three' },
        ]
    }
};

// If pointer starts with /, then it's interpreted
// as RFC6901 compliant JSON Pointer
pointer.get(object, '/foo/items/1/bar'); // 'two'

// Otherwise it's a dot-delimited path
pointer.get(object, 'foo.items.0'); // { bar: 'one' }

// Set modifies the object, creating additional objects and arrays as needed
const newObj = {}
pointer.set(newObj, 'foo.items.0.bar', '123');
// newObj is now { foo: { items: [{ bar: '123' }] } }
```

## Spec

NodeScript Pointer aims to implement all the features from [RFC6901](https://www.rfc-editor.org/rfc/rfc6901.html)
whilst also extending it to provide the following features:

1. Dot-delimited paths:

    ```ts
    get({ foo: { bar: { baz: 123 }}}, 'foo.bar.baz')
    // 123
    ```

2. Wildcard syntax to access array content:

    ```ts
    // Single level
    get({
        users: [
            { name: 'Joe' },
            { name: 'Jane' },
        ]
    }, 'users.*.name');
    // ['Joe', 'Jane']

    // Multiple levels
    get({
        items: [
            {
                tags: [{ value: 1 }, { value: 2 }],
            },
            {
                tags: [{ value: 3 }],
            },
        ]
    }, 'items.*.tags.*.value');
    // [ [ 1, 2 ], [ 3 ] ]
    ```

3. Push values into array:

    ```ts
    const obj = {};
    set(obj, '/items/-', 'foo');
    // { items: ['foo' ] }
    ```

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