# obcheck

> not-too-smart object validator

Latest version **1.0.5** (published 2018-03-19) · SEE LICENSE IN license.txt license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2018-03-19 |
| First published | 2018-03-03 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN license.txt |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.2.4 |
| Dependencies | 3 |
| Unpacked size | 144.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Gavin Atkinson |
| Maintainers | gatkinso |
| Keywords | checker, javascript, object, validation, validator |

## Links

- npm: https://www.npmjs.com/package/obcheck
- Repository: https://github.com/gavinpatkinson/obcheck
- Homepage: https://github.com/gavinpatkinson/obcheck#readme
- Issues: https://github.com/gavinpatkinson/obcheck/issues
- npm.io page: https://npm.io/package/obcheck

## Dependencies (3)

- [flat](https://npm.io/package/flat.md) ^4.0.0
- [is-equal](https://npm.io/package/is-equal.md) ^1.5.5
- [object-resolve-path](https://npm.io/package/object-resolve-path.md) ^1.1.1

## Alternatives

- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads

## Recent versions

- 1.0.5 (latest) — 2018-03-19
- 1.0.4 — 2018-03-13
- 1.0.3 — 2018-03-12
- 1.0.2 — 2018-03-12
- 1.0.0 — 2018-03-03

## README

[![Build Status](https://travis-ci.org/gavinpatkinson/obcheck.svg?branch=master)](https://travis-ci.org/gavinpatkinson/obcheck)
[![Coverage Status](https://coveralls.io/repos/github/gavinpatkinson/obcheck/badge.svg?branch=master)](https://coveralls.io/github/gavinpatkinson/obcheck?branch=master)

# obcheck
## Overview

This is a tiny utility for checking if an object contains a profile of values. It is pretty basic and not too smart so your usecase may warrant a look into [validate.js](https://github.com/ansman/validate.js) instead.

## Usage
The validator method is imported and passed a configuration object like so:
```javascript
import { Obcheck } from 'obcheck' // or require()

const config = {
  whitelists: { a: ['b'] }
}

const validator = new Obcheck(config)

const target = { a: 'c' }

validator.validate(target)
```
This will return
```
{
  whitelists: {
    a: {
      isValid: false,
      value: 'c'
    }
  }
}
```

One may also run custom validator logic or apply sanitizer functions to an object's values. In this case, the above code's config would look like this:
```javascript
import { Obcheck, mark } from 'obcheck' // or require()


const config = {
  whitelists: { a: ['b'] },
  sanitizers: {
    a: (val) => return val.toUpperCase()
  }
  validators: {
    isMoreThanOneChar: (obj) => isMoreThanOneChar(obj.a)
  }
}

const isMoreThanOneChar = (str) => {
  if (str.length > 1) {
    return mark(true, str.length)
  }
  return mark(false, str.length)
}
```

As you can see, a sanitizer's key in the config refers to it's location in the target object. One may target deep keys with strings like so:

```javascript
  const config = {
    whitelists: { 'a.b.c.d.e.f.g': ['h', 'i'] },
  }
```

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