# am-i-right

> Object Schema validator for front-end forms

Latest version **1.0.5** (published 2020-12-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install am-i-right
pnpm add am-i-right
yarn add am-i-right
bun add am-i-right
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2020-12-04 |
| First published | 2020-12-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | tejasnbontadka |
| Maintainers | tejasnbontadka |
| Keywords | am-i-right, Object schema validator, validator, front-end form validator |

## Links

- npm: https://www.npmjs.com/package/am-i-right
- npm.io page: https://npm.io/package/am-i-right

## 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) — 2020-12-04
- 1.0.4 — 2020-12-01
- 1.0.3 — 2020-12-01
- 1.0.2 — 2020-12-01
- 1.0.1 — 2020-12-01
- 1.0.0 — 2020-12-01

## README

# Am I Right

"Am I Right" is a Object Schema Validator plug and use package which is helpful for mantaining single source of validation logic for front-end.

Managing validation schema and custom error messages is straight forward using this plug-in rather maintaing seperate validation logics in each and every component.

As the name of the package tells you, that you just need to ask whether you are doing is right or wrong, package will validate and let you know what's wrong!!!!!

## Installation

Use the package manager [npm](https://www.npmjs.com/package/am-i-right) to install Am I Right.

```bash
npm install am-i-right
```

## Usage

```
import {validator} from 'am-i-right';

```

Need to feed two things for the plug-in which is necessary for performing validation.

1. Validation schema
2. Object data need to get validated against the validation schema

- Validation Schema should be defined like below, where we can give our custom error messages for the fields.

```npm
let validationSchema = {
  id: {
    minLength: 3,
    maxLength: 20,
    required: true,
    onlyNumbers: false,
    onlyAlpha: true,
    errorMessages: {
      errorMinLength: "Min length should be 3",
      errorMaxLength: "Max length should be 20",
      errorRequired: "Please fill this field",
      errorOnlyNumbers: "ID should be only numbers",
      errorOnlyAlpha: "ID should contain only alphabets"
    }
  }
};

```

As we observed in the above schema, using this plug-in we can validate against `minLength, maxLength, required, onlyAlpha, onlyNumber ` where the properties we define in schema is case sensitive.

We can define the respective error messages for each category in an `errorMessages` object, and we need to make sure that we are using the same properties as in schema.

- Object data : The data object you need to validate against the validator.

`let data = { id: "abcd" }; `

And finally you can call our validator function which will do the magic for you.

`validator(validationSchema, data)`

## License

[ISC](https://opensource.org/licenses/ISC)

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