# tval

> See examples for more details: Examples

Latest version **1.0.4** (published 2023-04-23) · ISC license · 0 weekly downloads

## Install

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

## 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 | 1.0.4 |
| Published | 2023-04-23 |
| First published | 2023-04-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 221.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | antoshkin |

## Links

- npm: https://www.npmjs.com/package/tval
- npm.io page: https://npm.io/package/tval

## Dependencies (1)

- [console-table-printer](https://npm.io/package/console-table-printer.md) ^2.11.1

## Recent versions

- 1.0.4 (latest) — 2023-04-23
- 1.0.3 — 2023-04-23
- 1.0.2 — 2023-04-23
- 1.0.1 — 2023-04-04

## README

# tval

## Installation
See examples for more details:
<a href="https://github.com/Artanty/tval/tree/master/dist/examples" target="_blank">Examples</a>


#### npm

```shell
npm i tval -D
```

#### Include with &lt;script&gt;
```html
<script defer src="tval.js"></script>
```

##### CDN

```html
<script src="https://cdn.jsdelivr.net/npm/queryzz/dist/queryzz.js"></script>
```

## How to use

simple type validation for api request and response

- 0 - null
- n - number
- s - string
- b - boolean
- a - any

### Conditional types:
[n, 0] - number or null

### Example usage:
```JS
const obj = {
  id: 947,
  transport: [
    { name: 'volvo', wheels: 4 },
    { name: 'monobike', wheels: 1 },
    { name: 'bicycle', wheels: 2 }
  ],
  today: "2024-10-03"
}
const check = {
  id: n,
  transport: [
    { name: s, wheels: [s,n]}
  ],
  today: [b]
}
const tvalResult = tvalidate(obj, check)
// =>
// [
//     {
//         "key": "id",
//         "value": 947,
//         "validator": 2,
//         "result": true
//     },
//     {
//         "key": "transport[0].name",
//         "value": "volvo",
//         "validator": 1,
//         "result": true
//     },
//     {
//         "key": "transport[0].wheels",
//         "value": 4,
//         "validator": [
//             1,
//             2
//         ],
//         "result": true
//     },
//     {
//         "key": "transport[1].name",
//         "value": "monobike",
//         "validator": 1,
//         "result": true
//     },
//     {
//         "key": "transport[1].wheels",
//         "value": 1,
//         "validator": [
//             1,
//             2
//         ],
//         "result": true
//     },
//     {
//         "key": "transport[2].name",
//         "value": "bicycle",
//         "validator": 1,
//         "result": true
//     },
//     {
//         "key": "transport[2].wheels",
//         "value": 2,
//         "validator": [
//             1,
//             2
//         ],
//         "result": true
//     },
//     {
//         "key": "today",
//         "value": "2024-10-03",
//         "validator": [
//             3,
//             4
//         ],
//         "result": true
//     }
// ]
```
## Methods

### tablize

Wrap result in table

```JS
tablize('tvalResultContainer', tvalResult)
```

#### Result =>: 
![tval result](https://github.com/Artanty/tval/blob/master/src/examples/result.png "")

### tvalLog

Return result in console

```JS
tvalLog(tvalResult)
```

#### Result =>: 
![tval result](https://github.com/Artanty/tval/blob/master/src/examples/result_console.png "")


<a href="https://github.com/Artanty/tval/blob/master/src/lib/tval.ts" target="_blank">Source code</a>
* * *

&copy; Artyom Antoshkin

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