# objecta

> Assert on an object's property value.

Latest version **0.1.7** (published 2017-03-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install objecta
pnpm add objecta
yarn add objecta
bun add objecta
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.7 |
| Published | 2017-03-14 |
| First published | 2017-03-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | evanx |

## Links

- npm: https://www.npmjs.com/package/objecta
- Repository: https://github.com/evanx/asserta
- Issues: https://github.com/evanx/asserta/issues
- npm.io page: https://npm.io/package/objecta

## Recent versions

- 0.1.7 (latest) — 2017-03-14
- 0.1.6 — 2017-03-14
- 0.1.5 — 2017-03-12
- 0.1.4 — 2017-03-12
- 0.1.3 — 2017-03-12
- 0.1.2 — 2017-03-12

## README

# objecta

Assert on an object's property.

Implementation:
```javascript
    get: (object, key) => {
        if (typeof key !== 'string') {
            throw new Error(`Expected an string for property name`);
        }
        if (typeof object !== 'object') {
            throw new Error(`Expected an object for property '${key}'`);
        }
        return object[key];
    },
    ensure: (object, key) => {
        const value = ex.get(object, key);
        if (value === undefined) {
            throw new Error(`Expected property '${key}'`);
        }
        return value;
    },
    has: (object, key) => {
        const value = ex.get(object, key);
        if (value === undefined) {
            return false;
        }
        return true;
    },
    hasType: (object, key, type) => {
        if (typeof type !== 'string') {
            throw new Error(`Expected a type specification for '${key}'`);
        }
        const value = ex.get(object, key);
        if (value === undefined) {
            return false;
        }
        if (typeof value !== type) {
            throw new Error(`Expected type '${type}' for '${key}'`);
        }
        return true;
    },
```

<hr>
https://twitter.com/@evanxsummers

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