tval
v1.0.4
Published
See examples for more details: <a href="https://github.com/Artanty/tval/tree/master/dist/examples" target="_blank">Examples</a>
Downloads
5
Readme
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 =>:
tvalLog
Return result in console
tvalLog(tvalResult)
Result =>:
Source code
© Artyom Antoshkin