# @mangar2/checkinput

> JSON schema check

Latest version **2.6.1** (published 2020-06-30) · LGPL-3.0-or-later license · 0 weekly downloads

## Install

```sh
npm install @mangar2/checkinput
pnpm add @mangar2/checkinput
yarn add @mangar2/checkinput
bun add @mangar2/checkinput
```

## 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 | 2.6.1 |
| Published | 2020-06-30 |
| First published | 2019-10-06 |
| Weekly downloads | 0 |
| License | LGPL-3.0-or-later |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 394.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Volker Böhm |
| Maintainers | mangar2 |
| Keywords | validate, JSON, Schema |

## Links

- npm: https://www.npmjs.com/package/@mangar2/checkinput
- Repository: https://github.com/Mangar2/yaha/tree/master/node_modules/@mangar2/checkinput
- Homepage: https://github.com/Mangar2/yaha.git
- npm.io page: https://npm.io/package/@mangar2/checkinput

## Dependencies (1)

- [@mangar2/types](https://npm.io/package/@mangar2/types.md) latest

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.6.1 (latest) — 2020-06-30
- 2.6.0 — 2020-04-29
- 2.5.2 — 2020-03-15
- 2.5.0 — 2020-02-29
- 2.3.1 — 2020-02-22
- 2.3.0 — 2020-02-22
- 2.2.1 — 2020-02-15
- 2.1.0 — 2020-01-17
- 2.0.0 — 2020-01-11
- 1.3.1 — 2019-10-19
- 1.1.0 — 2019-10-17
- 1.0.4 — 2019-10-15
- 1.0.3 — 2019-10-14
- 1.0.2 — 2019-10-13
- 1.0.1 — 2019-10-06
- … 1 more at https://npm.io/package/@mangar2/checkinput/versions

## README

<!-- This file is generated by jsmddoc version 0.1 -->

# Abstract

JSON schema validator matching standard version 0 . 7

## Contents

- [Meta](#Meta)
- [Global Functions](#Global-functions)
  - [_checkPropertyNames](#_checkPropertyNames)
- [Class CheckInput](#Class-CheckInput)
  - [Parameters](#CheckInput-Parameters)
  - [Members](#CheckInput-Members)
  - [Methods](#CheckInput-Methods)
    - [throwOnValidationError](#throwOnValidationError)
    - [validate](#validate)

## Meta

| | |
| --- | --- |
| **File** | checkinput.js |
| **Abstract** | JSON schema validator matching standard version 0 . 7 |
| **Author** | Volker Böhm |
| **Copyright** | Copyright ( c ) 2020 Volker Böhm |
| **License** | This software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3 . It is furnished "as is" , without any support , and with no warranty , express or implied , as to its usefulness for any purpose . |

## Global functions

### _checkPropertyNames

`_checkPropertyNames (definition, object, checkSubschema) => {CheckResult}`

Checks the property names

#### _checkPropertyNames Parameters

| Name | Type | Description |
| ---------- | ------------ | ----------------- |
| `definition` | `Object` | property names schema definition | |
| `object` | `Object` | object to check | |
| `checkSubschema` | `function` | ( definition , data ) | |

#### _checkPropertyNames returns

| Type | Description |
| ---- | ----------- |
| `CheckResult` | result of the check with 'check' and 'message' |

## Class CheckInput

`new CheckInput(definition, options)`

Creates a new JSON Schema validation class to validate a data object according to a JSON Schema . Many thanks to epoberezkin/JSON-Schema-Test-Suite for providing a cool test suite . I use it to check my implementation This is not ( yet ) a complete implementation . The following tests are not running yet :

- remote-refs ( neither local nor remote )
- unicode-code-points ( EmacsScript length is used to get the lengt of a string ) definitions

### Example

```javascript
check = new CheckInput({
  type: 'object',
  properties: {
      topic: { type: 'string' },
      value: { type: 'string' },
  },
  required: ['topic', 'value']
})
// returns true, as the parameter fits to the descriptions
check.validate({ topic: '/a/b', value: 'on' })

// returns false and fills the error message
// check.message is { topic: 'missing property topic', value: 'missing property value' }
check.validate ( {} )

// Throws an Error, as the validation does not fits to the description
check.throwOnValidationError({ topic: '/a/b' })

// Prints the error message
console.log(check.messages)
```

### CheckInput Parameters

| Name | Type | Description |
| ---------- | ------------ | ----------------- |
| `definition` | `Any` | JSON schema definition | |
| `options` | `Object` | schema validation options | |

#### options properties

| Name | Type | Attribute | Default | Description |
| ---------- | ------------ | ------------ | ------------ | ----------------- |
| `deepUnique` | `boolean` | optional | true | if true , the content is checked deeply . For example different objects with the same | |
| `stringToNumber` | `boolean` | optional | false | if true , strings containing numbers are automatically converted | |

### CheckInput Members

| Name | Type | description |
| ------------ | ------------ | ------------ |
| `messages` | `Object, string` | Gets the list of error messages |

### CheckInput Methods

#### throwOnValidationError

`throwOnValidationError (data, message)`

Validates the input and throws a message on error

##### throwOnValidationError Parameters

| Name | Type | Attribute | Default | Description |
| ---------- | ------------ | ------------ | ------------ | ----------------- |
| `data` | `Object` |  |  | data to check against definition | |
| `message` | `string` | optional | '' | starting string of the error message | |

#### validate

`validate (data) => {boolean}`

Checks an object against a swagger defintion

##### validate Parameters

| Name | Type | Description |
| ---------- | ------------ | ----------------- |
| `data` | `Object` | data to check against definition | |

##### validate returns

| Type | Description |
| ---- | ----------- |
| `boolean` | true , if the data matches to the definition else false |

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