# property-expr-csp

> tiny util for getting and setting deep object props safely

Latest version **1.4.0** (published 2018-07-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install property-expr-csp
pnpm add property-expr-csp
yarn add property-expr-csp
bun add property-expr-csp
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.0 |
| Published | 2018-07-03 |
| First published | 2018-07-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 29.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | @monasticpanic Jason Quense |
| Maintainers | enet |
| Keywords | expr, expression, setter, getter, deep, property, content-security-policy, csp, content, security, policy, accessor |

## Links

- npm: https://www.npmjs.com/package/property-expr-csp
- Repository: https://github.com/Enet/expr
- Homepage: https://github.com/Enet/expr#readme
- Issues: https://github.com/Enet/expr/issues
- npm.io page: https://npm.io/package/property-expr-csp

## Alternatives

- [ext-list](https://npm.io/package/ext-list.md) — 6.3M weekly downloads
- [@lexical/selection](https://npm.io/package/@lexical/selection.md) — 3.8M weekly downloads
- [@lexical/text](https://npm.io/package/@lexical/text.md) — 3.6M weekly downloads
- [@lexical/clipboard](https://npm.io/package/@lexical/clipboard.md) — 3.0M weekly downloads
- [@tiptap/extension-mention](https://npm.io/package/@tiptap/extension-mention.md) — 3.0M weekly downloads

## Recent versions

- 1.4.0 (latest) — 2018-07-03

## README

property-expr-csp
=================

Tiny expression helper for creating accessors; handles most stuff, including ["bracket notation"] for property access. Originally based off of Kendo UI Core expression code and the original property-expr package, but here is special version to satisfy CSP (Content-Security-Policy) requirements!

    npm install property-expr-csp

## Use

Setters and getters are not compiled to functions and executed every time to satisfy CSP

    var expr = require('property-expr')
      , obj = {
        foo: {
          bar: [ "hi", { buz: { baz: 'found me!' } }]
        }
      };

    var getBaz = expr.getter('foo.bar[1]["buz"].baz')
      , setBaz = expr.setter('foo.bar[1]["buz"].baz')

    console.log(getBaz(obj)) // => 'found me!'
    setBaz(obj, 'set me!')
    console.log(obj.foo.bar[1].buz.baz) // => 'set me!'

### `getter(expression, [ safeAccess ])`

Returns a function that accepts an obj and returns the value at the supplied expression. You can create a "safe" getter, which won't error out when accessing properties that don't exist, reducing existance checks befroe property access:

    expr.getter('foo.bar.baz', true)({ foo: {} }) // => undefined
    //instead of val = foo.bar && foo.bar.baz

### `setter(expression)`

Returns a function that accepts an obj and a value and sets the property pointed to by the expression to the supplied value.

### `expr(expression, [ safeAccess], [ paramName = 'data'])`

Method was removed, because it makes no sense in CSP version.

### `split(path) -> Array`

Returns an array of each path segment.

```js
 split("foo['bar'][0].baz") // [ "foo", "'bar'", "0", "baz"]
```

### `forEach(path, iterator[, thisArg]) `

Iterate through a path but segment, with some additional helpful metadata about the segment. The iterator function is called with: `pathSegment`, `isBracket`, `isArray`, `idx`, `segments`

```js
.forEach('foo["bar"][1]', function(pathSegment, isBracket, isArray, idx, segments) {
  // 'foo'   -> isBracket = false, isArray = false, idx = 0
  // '"bar"' -> isBracket = true,  isArray = false, idx = 1
  // '0'     -> isBracket = false, isArray = true,  idx = 2
}
```

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