# @nesn/commons-schema-validator

> The `@nesn/commons-shared-objects-schema-validator` module provides a validation utility for ensuring data adherence to defined JSON schemas. This utility is particularly useful when working with data structures like the `NormalizedSubscription` interface

Latest version **1.0.1** (published 2023-10-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install @nesn/commons-schema-validator
pnpm add @nesn/commons-schema-validator
yarn add @nesn/commons-schema-validator
bun add @nesn/commons-schema-validator
```

## 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.0.1 |
| Published | 2023-10-13 |
| First published | 2023-10-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Lance Sims |
| Maintainers | nesn-admin |
| Keywords | schema, validator |

## Links

- npm: https://www.npmjs.com/package/@nesn/commons-schema-validator
- npm.io page: https://npm.io/package/@nesn/commons-schema-validator

## Alternatives

- [@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
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2023-10-13

## README

# Schema Validator Module Readme

The `@nesn/commons-shared-objects-schema-validator` module provides a validation utility for ensuring data adherence to defined JSON schemas. This utility is particularly useful when working with data structures like the `NormalizedSubscription` interface provided by the `NormalizedSubscription` module. This readme provides an overview of the module's purpose, usage, and integration.

## Table of Contents

- [Introduction](#introduction)
- [Installation](#installation)
- [Usage](#usage)
    - [Importing](#importing)
    - [Validation](#validation)
- [Customization](#customization)
- [Contributing](#contributing)
- [License](#license)

## Introduction

The `@nesn/commons-shared-objects-schema-validator` module aims to streamline the validation of data against JSON schemas. By leveraging the [Ajv](https://ajv.js.org/) library, it ensures that data structures conform to specified schemas, enabling reliable and consistent data processing. This module can be integrated with any codebase that requires schema-based validation.

## Installation

To include the `@nesn/commons-shared-objects-schema-validator` module in your project, you can install it using npm:

```bash
npm install @nesn/commons-shared-objects-schema-validator
```

## Usage

### Importing

Import the `validateObjectAgainstSchema` function from the module:

```typescript
import { validateObjectAgainstSchema } from '@nesn/commons-shared-objects-schema-validator';
```

### Validation

The `validateObjectAgainstSchema` function takes two parameters: the data object to be validated and the JSON schema against which the data will be validated. If the data adheres to the schema, the function returns `true`. If not, it throws a `SchemaValidationError`.

Here's an example of using the validator with the `NormalizedSubscription` interface and schema:

```typescript
import { validateObjectAgainstSchema } from '@nesn/commons-shared-objects-schema-validator';
import { NormalizedSubscription } from '@nesn/commons-shared-objects-normalized-subscription';

const subscriptionData = /* your subscription data */;
try {
    validateObjectAgainstSchema(subscriptionData, NormalizedSubscription);
    console.log('Data is valid!');
} catch (error) {
    if (error instanceof SchemaValidationError) {
        console.error('Validation error:', error.message);
        // Handle validation errors
    } else {
        // Handle other errors
    }
}
```

## Customization

The `@nesn/commons-shared-objects-schema-validator` module provides a default `SchemaValidationError` class for handling validation errors. You can extend or modify this class to suit your project's needs. This might include additional error information or custom error messages.

## Contributing

Contributions to the `@nesn/commons-shared-objects-schema-validator` module are welcome. If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.

## License

The `@nesn/commons-shared-objects-schema-validator` module is released under the MIT License. You can find the full license text in the module's `package.json` file.

---

*Please note that this readme is provided as an example and might need adjustments based on your specific project and documentation guidelines.*

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