1.0.4 • Published 1 year ago

tval v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

tval

Installation

See examples for more details: Examples

npm

npm i tval -D

Include with <script>

<script defer src="tval.js"></script>
CDN
<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:

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

tablize('tvalResultContainer', tvalResult)

Result =>:

tval result

tvalLog

Return result in console

tvalLog(tvalResult)

Result =>:

tval result

Source code


© Artyom Antoshkin

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

0.1.0

2 years ago