itee-validators 5.3.9 → 5.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.czrc +6 -0
- package/CHANGELOG.md +20 -0
- package/builds/itee-validators.cjs.js +278 -277
- package/builds/itee-validators.cjs.js.map +1 -1
- package/builds/itee-validators.cjs.min.js +144 -144
- package/builds/itee-validators.esm.js +210 -205
- package/builds/itee-validators.esm.js.map +1 -1
- package/builds/itee-validators.esm.min.js +97 -97
- package/builds/itee-validators.iife.js +211 -207
- package/builds/itee-validators.iife.js.map +1 -1
- package/builds/itee-validators.iife.min.js +120 -120
- package/package.json +6 -10
- package/sources/cores/arrays/isArray.js +4 -4
- package/sources/cores/arrays/isArrayOfArray.js +2 -2
- package/sources/cores/arrays/isArrayOfBoolean.js +2 -2
- package/sources/cores/arrays/isArrayOfFunction.js +2 -2
- package/sources/cores/arrays/isArrayOfMultiElement.js +1 -1
- package/sources/cores/arrays/isArrayOfNull.js +2 -2
- package/sources/cores/arrays/isArrayOfNumber.js +2 -2
- package/sources/cores/arrays/isArrayOfObject.js +2 -2
- package/sources/cores/arrays/isArrayOfSingleElement.js +1 -1
- package/sources/cores/arrays/isArrayOfString.js +3 -3
- package/sources/cores/arrays/isArrayOfUndefined.js +2 -2
- package/sources/cores/arrays/isEmptyArray.js +2 -2
- package/sources/cores/booleans/isBoolean.js +4 -4
- package/sources/cores/booleans/isTrue.js +2 -2
- package/sources/cores/cores.js +91 -91
- package/sources/cores/functions/isFunction.js +2 -2
- package/sources/cores/numbers/isInfinite.js +13 -19
- package/sources/cores/numbers/isMax.js +2 -2
- package/sources/cores/numbers/isMin.js +2 -2
- package/sources/cores/numbers/isNumber.js +15 -15
- package/sources/cores/numbers/isSafeInteger.js +2 -2
- package/sources/cores/numbers/isZero.js +3 -3
- package/sources/cores/objects/isEmptyObject.js +2 -2
- package/sources/cores/objects/isObject.js +2 -2
- package/sources/cores/strings/isBlankString.js +2 -2
- package/sources/cores/strings/isEmptyString.js +2 -2
- package/sources/cores/strings/isString.js +7 -7
- package/sources/cores/symbols/isSymbol.js +2 -2
- package/sources/cores/tests/isTestUnitGenerator.js +10 -10
- package/sources/cores/typed-arrays/isArrayBuffer.js +2 -2
- package/sources/cores/typed-arrays/isBigInt64Array.js +2 -2
- package/sources/cores/typed-arrays/isBigUint64Array.js +2 -2
- package/sources/cores/typed-arrays/isFloat32Array.js +2 -2
- package/sources/cores/typed-arrays/isFloat64Array.js +2 -2
- package/sources/cores/typed-arrays/isInt16Array.js +2 -2
- package/sources/cores/typed-arrays/isInt32Array.js +2 -2
- package/sources/cores/typed-arrays/isInt8Array.js +2 -2
- package/sources/cores/typed-arrays/isUint16Array.js +2 -2
- package/sources/cores/typed-arrays/isUint32Array.js +2 -2
- package/sources/cores/typed-arrays/isUint8Array.js +2 -2
- package/sources/cores/typed-arrays/isUint8ClampedArray.js +2 -2
- package/sources/cores/voids/isDefined.js +2 -2
- package/sources/cores/voids/isEmpty.js +2 -2
- package/sources/cores/voids/isNull.js +3 -3
- package/sources/cores/voids/isUndefined.js +2 -2
- package/sources/dom/isEventTarget.js +2 -2
- package/sources/file-system/block-devices/isBlockDevicePath.js +9 -9
- package/sources/file-system/block-devices/isValidBlockDevicePath.js +2 -2
- package/sources/file-system/character-devices/isCharacterDevicePath.js +9 -9
- package/sources/file-system/character-devices/isValidCharacterDevicePath.js +2 -2
- package/sources/file-system/directories/isDirectoryPath.js +9 -9
- package/sources/file-system/directories/isEmptyDirectory.js +4 -4
- package/sources/file-system/directories/isValidDirectoryPath.js +2 -2
- package/sources/file-system/fifo-pipes/isFIFOPath.js +9 -9
- package/sources/file-system/fifo-pipes/isValidFIFOPath.js +2 -2
- package/sources/file-system/files/isEmptyFile.js +9 -9
- package/sources/file-system/files/isFilePath.js +9 -9
- package/sources/file-system/files/isValidFilePath.js +2 -2
- package/sources/file-system/paths/isValidPath.js +4 -4
- package/sources/file-system/sockets/isSocketPath.js +9 -9
- package/sources/file-system/sockets/isValidSocketPath.js +2 -2
- package/sources/file-system/symbolic-links/isSymbolicLinkPath.js +9 -9
- package/sources/file-system/symbolic-links/isValidSymbolicLinkPath.js +2 -2
- package/sources/itee-validators.js +1 -14
- package/sources/physics/temperatures/isCelsius.js +2 -2
- package/sources/physics/temperatures/isFahrenheit.js +2 -2
- package/sources/physics/temperatures/isKelvin.js +2 -2
- package/sources/physics/temperatures/isTemperature.js +2 -2
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* ┳ ┓┏ ┓• ┓ ┏━ ┏━ ┏┓ ┏┓ ┓ ┓
|
|
3
|
+
* ┃╋┏┓┏┓ ┃┃┏┓┃┓┏┫┏┓╋┏┓┏┓┏ ┓┏┗┓ ┗┓ ┃┫ ━━ ┗┓╋┏┓┏┓┏┫┏┓┃┏┓┏┓┏┓
|
|
4
|
+
* ┻┗┗ ┗ •┗┛┗┻┗┗┗┻┗┻┗┗┛┛ ┛ ┗┛┗┛•┗┛•┗┛ ┗┛┗┗┻┛┗┗┻┗┻┗┗┛┛┗┗
|
|
5
|
+
*
|
|
6
|
+
* @desc A library of validation functions use in various Itee projects
|
|
7
|
+
* @author [Tristan Valcke]{@link https://github.com/Itee}
|
|
8
|
+
* @license [BSD-3-Clause]{@link https://opensource.org/licenses/BSD-3-Clause}
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
(function (exports) {
|
|
4
12
|
'use strict';
|
|
5
13
|
|
|
6
14
|
/**
|
|
@@ -27,7 +35,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
27
35
|
* @param data {*} The data to check against the array type
|
|
28
36
|
* @returns {boolean} true if data is array, false otherwise
|
|
29
37
|
*/
|
|
30
|
-
function isArray
|
|
38
|
+
function isArray( data ) {
|
|
31
39
|
return Array.isArray( data )
|
|
32
40
|
}
|
|
33
41
|
|
|
@@ -37,7 +45,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
37
45
|
* @param data {*} The data to check against the array type
|
|
38
46
|
* @returns {boolean} true if data is not array, false otherwise
|
|
39
47
|
*/
|
|
40
|
-
function isNotArray
|
|
48
|
+
function isNotArray( data ) {
|
|
41
49
|
return !Array.isArray( data )
|
|
42
50
|
}
|
|
43
51
|
|
|
@@ -65,7 +73,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
65
73
|
* @param data {*} The data to check against the empty array
|
|
66
74
|
* @returns {boolean} true if data is an empty array, false otherwise
|
|
67
75
|
*/
|
|
68
|
-
function isEmptyArray
|
|
76
|
+
function isEmptyArray( data ) {
|
|
69
77
|
|
|
70
78
|
if ( isNotArray( data ) ) { return false }
|
|
71
79
|
|
|
@@ -79,7 +87,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
79
87
|
* @param data {*} The data to check against the empty array
|
|
80
88
|
* @returns {boolean} true if data is not an empty array, false otherwise
|
|
81
89
|
*/
|
|
82
|
-
function isNotEmptyArray
|
|
90
|
+
function isNotEmptyArray( data ) {
|
|
83
91
|
|
|
84
92
|
if ( isNotArray( data ) ) { return true }
|
|
85
93
|
|
|
@@ -111,7 +119,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
111
119
|
* @param data {*} The data to check against the array of array type
|
|
112
120
|
* @returns {boolean} true if data is an array of array, false otherwise
|
|
113
121
|
*/
|
|
114
|
-
function isArrayOfArray
|
|
122
|
+
function isArrayOfArray( data ) {
|
|
115
123
|
|
|
116
124
|
if ( isNotArray( data ) ) { return false }
|
|
117
125
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -132,7 +140,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
132
140
|
* @param data {*} The data to check against the array of array type
|
|
133
141
|
* @returns {boolean} true if data is not an array of array, false otherwise
|
|
134
142
|
*/
|
|
135
|
-
function isNotArrayOfArray
|
|
143
|
+
function isNotArrayOfArray( data ) {
|
|
136
144
|
|
|
137
145
|
if ( isNotArray( data ) ) { return true }
|
|
138
146
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -171,7 +179,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
171
179
|
* @param data {*} The data to check against the booleaness
|
|
172
180
|
* @returns {boolean} true if data is a boolean, false otherwise.
|
|
173
181
|
*/
|
|
174
|
-
function isBoolean
|
|
182
|
+
function isBoolean( data ) {
|
|
175
183
|
return ( typeof data === 'boolean' )
|
|
176
184
|
}
|
|
177
185
|
|
|
@@ -181,7 +189,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
181
189
|
* @param data {*} The data to check against the booleaness
|
|
182
190
|
* @returns {boolean} true if data is not a boolean, false otherwise.
|
|
183
191
|
*/
|
|
184
|
-
function isNotBoolean
|
|
192
|
+
function isNotBoolean( data ) {
|
|
185
193
|
return ( typeof data !== 'boolean' )
|
|
186
194
|
}
|
|
187
195
|
|
|
@@ -209,7 +217,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
209
217
|
* @param data {*} The data to check against the array of booleans
|
|
210
218
|
* @returns {boolean} true if data is not an empty array where all values are boolean, false otherwise
|
|
211
219
|
*/
|
|
212
|
-
function isArrayOfBoolean
|
|
220
|
+
function isArrayOfBoolean( data ) {
|
|
213
221
|
|
|
214
222
|
if ( isNotArray( data ) ) { return false }
|
|
215
223
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -230,7 +238,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
230
238
|
* @param data {*} The data to check against the array of booleans
|
|
231
239
|
* @returns {boolean} true if data is not an empty array where all values are not boolean, false otherwise
|
|
232
240
|
*/
|
|
233
|
-
function isNotArrayOfBoolean
|
|
241
|
+
function isNotArrayOfBoolean( data ) {
|
|
234
242
|
|
|
235
243
|
if ( isNotArray( data ) ) { return true }
|
|
236
244
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -269,7 +277,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
269
277
|
* @param data {*} The data to check against the functionality
|
|
270
278
|
* @returns {boolean} true if data is a function, false otherwise.
|
|
271
279
|
*/
|
|
272
|
-
function isFunction
|
|
280
|
+
function isFunction( data ) {
|
|
273
281
|
return ( typeof data === 'function' )
|
|
274
282
|
}
|
|
275
283
|
|
|
@@ -279,7 +287,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
279
287
|
* @param data {*} The data to check against the functionality
|
|
280
288
|
* @returns {boolean} true if data is not a function, false otherwise.
|
|
281
289
|
*/
|
|
282
|
-
function isNotFunction
|
|
290
|
+
function isNotFunction( data ) {
|
|
283
291
|
return ( typeof data !== 'function' )
|
|
284
292
|
}
|
|
285
293
|
|
|
@@ -307,7 +315,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
307
315
|
* @param data {*} The data to check against the array of functions
|
|
308
316
|
* @returns {boolean} true if data is not an empty array where all values are functions, false otherwise
|
|
309
317
|
*/
|
|
310
|
-
function isArrayOfFunction
|
|
318
|
+
function isArrayOfFunction( data ) {
|
|
311
319
|
|
|
312
320
|
if ( isNotArray( data ) ) { return false }
|
|
313
321
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -328,7 +336,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
328
336
|
* @param data {*} The data to check against the array of functions
|
|
329
337
|
* @returns {boolean} true if data is not an empty array where all values are not functions, false otherwise
|
|
330
338
|
*/
|
|
331
|
-
function isNotArrayOfFunction
|
|
339
|
+
function isNotArrayOfFunction( data ) {
|
|
332
340
|
|
|
333
341
|
if ( isNotArray( data ) ) { return true }
|
|
334
342
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -367,7 +375,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
367
375
|
* @param data {*} The data to check against the single valued array
|
|
368
376
|
* @returns {boolean} true if data is an array with multiples values, false otherwise
|
|
369
377
|
*/
|
|
370
|
-
function isArrayOfMultiElement
|
|
378
|
+
function isArrayOfMultiElement( data ) {
|
|
371
379
|
|
|
372
380
|
if ( isNotArray( data ) ) { return false }
|
|
373
381
|
|
|
@@ -399,7 +407,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
399
407
|
* @param data {*} The data to check against the nullity
|
|
400
408
|
* @returns {boolean} true if data is null, false otherwise.
|
|
401
409
|
*/
|
|
402
|
-
function isNull
|
|
410
|
+
function isNull( data ) {
|
|
403
411
|
return ( data === null )
|
|
404
412
|
}
|
|
405
413
|
|
|
@@ -411,7 +419,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
411
419
|
* @param data {*} The data to check against the nullity
|
|
412
420
|
* @returns {boolean} true if data is not null, false otherwise.
|
|
413
421
|
*/
|
|
414
|
-
function isNotNull
|
|
422
|
+
function isNotNull( data ) {
|
|
415
423
|
return ( data !== null )
|
|
416
424
|
}
|
|
417
425
|
|
|
@@ -438,7 +446,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
438
446
|
* @param data {*} The data to check against the array of null type
|
|
439
447
|
* @returns {boolean} true if data is not an empty array where all values are null, false otherwise
|
|
440
448
|
*/
|
|
441
|
-
function isArrayOfNull
|
|
449
|
+
function isArrayOfNull( data ) {
|
|
442
450
|
|
|
443
451
|
if ( isNotArray( data ) ) { return false }
|
|
444
452
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -459,7 +467,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
459
467
|
* @param data {*} The data to check against the array of null type
|
|
460
468
|
* @returns {boolean} true if data is not an empty array where all values are not null, false otherwise
|
|
461
469
|
*/
|
|
462
|
-
function isNotArrayOfNull
|
|
470
|
+
function isNotArrayOfNull( data ) {
|
|
463
471
|
|
|
464
472
|
if ( isNotArray( data ) ) { return true }
|
|
465
473
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -498,7 +506,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
498
506
|
* @param data {*} The data to check against the existence
|
|
499
507
|
* @returns {boolean} true if data is not null and not undefined, false otherwise.
|
|
500
508
|
*/
|
|
501
|
-
function isDefined
|
|
509
|
+
function isDefined( data ) {
|
|
502
510
|
return ( ( data !== null ) && ( typeof data !== 'undefined' ) )
|
|
503
511
|
}
|
|
504
512
|
|
|
@@ -508,7 +516,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
508
516
|
* @param data {*} The data to check against the existence
|
|
509
517
|
* @returns {boolean} true if data is null or undefined, false otherwise.
|
|
510
518
|
*/
|
|
511
|
-
function isNotDefined
|
|
519
|
+
function isNotDefined( data ) {
|
|
512
520
|
return ( ( data === null ) || ( typeof data === 'undefined' ) )
|
|
513
521
|
}
|
|
514
522
|
|
|
@@ -530,20 +538,6 @@ this.Itee.Validators = (function (exports) {
|
|
|
530
538
|
*
|
|
531
539
|
*/
|
|
532
540
|
|
|
533
|
-
/**
|
|
534
|
-
* Check if the given data is an infinite number
|
|
535
|
-
*
|
|
536
|
-
* @param data {*} The data to check against the infinite state
|
|
537
|
-
* @returns {boolean} true if data is infinite, false otherwise
|
|
538
|
-
*/
|
|
539
|
-
function isInfinite ( data ) {
|
|
540
|
-
|
|
541
|
-
// Todo: is required to check notnumber ?
|
|
542
|
-
if ( isNotNumber( data ) ) { return false }
|
|
543
|
-
if ( Number.isNaN( data ) ) { return false }
|
|
544
|
-
|
|
545
|
-
return !Number.isFinite( data )
|
|
546
|
-
}
|
|
547
541
|
|
|
548
542
|
/**
|
|
549
543
|
* Check if the given data is an infinite negative number
|
|
@@ -551,7 +545,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
551
545
|
* @param data {*} The data to check against the negative infinite state
|
|
552
546
|
* @returns {boolean} true if data is negative infinite, false otherwise
|
|
553
547
|
*/
|
|
554
|
-
function isInfiniteNegative
|
|
548
|
+
function isInfiniteNegative( data ) {
|
|
555
549
|
return ( data === Number.NEGATIVE_INFINITY )
|
|
556
550
|
}
|
|
557
551
|
|
|
@@ -561,17 +555,27 @@ this.Itee.Validators = (function (exports) {
|
|
|
561
555
|
* @param data {*} The data to check against the positive infinite state
|
|
562
556
|
* @returns {boolean} true if data is positive infinite, false otherwise
|
|
563
557
|
*/
|
|
564
|
-
function isInfinitePositive
|
|
558
|
+
function isInfinitePositive( data ) {
|
|
565
559
|
return ( data === Number.POSITIVE_INFINITY )
|
|
566
560
|
}
|
|
567
561
|
|
|
562
|
+
/**
|
|
563
|
+
* Check if the given data is an infinite number
|
|
564
|
+
*
|
|
565
|
+
* @param data {*} The data to check against the infinite state
|
|
566
|
+
* @returns {boolean} true if data is infinite, false otherwise
|
|
567
|
+
*/
|
|
568
|
+
function isInfinite( data ) {
|
|
569
|
+
return isInfiniteNegative( data ) || isInfinitePositive( data )
|
|
570
|
+
}
|
|
571
|
+
|
|
568
572
|
/**
|
|
569
573
|
* Check if the given data is a finite number
|
|
570
574
|
*
|
|
571
575
|
* @param data {*} The data to check against the finite state
|
|
572
576
|
* @returns {boolean} true if data is finite, false otherwise
|
|
573
577
|
*/
|
|
574
|
-
function isFinite
|
|
578
|
+
function isFinite( data ) {
|
|
575
579
|
return Number.isFinite( data )
|
|
576
580
|
}
|
|
577
581
|
|
|
@@ -601,7 +605,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
601
605
|
* @param data {*} The data to check against the zero value
|
|
602
606
|
* @returns {boolean} true if data is zero, false otherwise
|
|
603
607
|
*/
|
|
604
|
-
function isZero
|
|
608
|
+
function isZero( data ) {
|
|
605
609
|
//Todo protect truthy values
|
|
606
610
|
return ( data === 0 )
|
|
607
611
|
}
|
|
@@ -612,7 +616,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
612
616
|
* @param data {*} The data to check against the positive zero value
|
|
613
617
|
* @returns {boolean} true if data is a positive zero, false otherwise
|
|
614
618
|
*/
|
|
615
|
-
function isZeroPositive
|
|
619
|
+
function isZeroPositive( data ) {
|
|
616
620
|
return ( data === 0 && ( 1 / data ) === Number.POSITIVE_INFINITY )
|
|
617
621
|
}
|
|
618
622
|
|
|
@@ -622,7 +626,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
622
626
|
* @param data {*} The data to check against the negative zero value
|
|
623
627
|
* @returns {boolean} true if data is a negative zero, false otherwise
|
|
624
628
|
*/
|
|
625
|
-
function isZeroNegative
|
|
629
|
+
function isZeroNegative( data ) {
|
|
626
630
|
return ( data === 0 && ( 1 / data ) === Number.NEGATIVE_INFINITY )
|
|
627
631
|
}
|
|
628
632
|
|
|
@@ -650,7 +654,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
650
654
|
* @param data {*} The data to check against the maximum safe integer state
|
|
651
655
|
* @returns {boolean} true if data is a number, false otherwise.
|
|
652
656
|
*/
|
|
653
|
-
function isNumber
|
|
657
|
+
function isNumber( data ) {
|
|
654
658
|
|
|
655
659
|
if ( isNotDefined( data ) ) { return false }
|
|
656
660
|
|
|
@@ -664,7 +668,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
664
668
|
* @param data {*} The data to check against the positivity
|
|
665
669
|
* @returns {boolean} true if data is a positive number, false otherwise.
|
|
666
670
|
*/
|
|
667
|
-
function isNumberPositive
|
|
671
|
+
function isNumberPositive( data ) {
|
|
668
672
|
|
|
669
673
|
if ( isNotNumber( data ) ) { return false }
|
|
670
674
|
|
|
@@ -679,7 +683,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
679
683
|
* @param data {*} The data to check against the negativity
|
|
680
684
|
* @returns {boolean} true if data is a negative number, false otherwise.
|
|
681
685
|
*/
|
|
682
|
-
function isNumberNegative
|
|
686
|
+
function isNumberNegative( data ) {
|
|
683
687
|
return ( isNumber( data ) && data < 0 )
|
|
684
688
|
}
|
|
685
689
|
|
|
@@ -689,7 +693,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
689
693
|
* @param data {*} The data to check against the number type
|
|
690
694
|
* @returns {boolean} true if data is not of type number or not a number, false otherwise.
|
|
691
695
|
*/
|
|
692
|
-
function isNotNumber
|
|
696
|
+
function isNotNumber( data ) {
|
|
693
697
|
return !( isNumber( data ) )
|
|
694
698
|
}
|
|
695
699
|
|
|
@@ -699,7 +703,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
699
703
|
* @param data {*} The data to check against the integer state
|
|
700
704
|
* @returns {boolean} true if data is an integer, false otherwise
|
|
701
705
|
*/
|
|
702
|
-
function isInteger
|
|
706
|
+
function isInteger( data ) {
|
|
703
707
|
return Number.isInteger( data )
|
|
704
708
|
}
|
|
705
709
|
|
|
@@ -709,7 +713,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
709
713
|
* @param data {*} The data to check against the floating point
|
|
710
714
|
* @returns {boolean} true if data is a float, false otherwise
|
|
711
715
|
*/
|
|
712
|
-
function isFloat
|
|
716
|
+
function isFloat( data ) {
|
|
713
717
|
|
|
714
718
|
if ( isNotNumber( data ) ) { return false }
|
|
715
719
|
if ( Number.isNaN( data ) ) { return false }
|
|
@@ -725,7 +729,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
725
729
|
* @param data {*} The data to check against the NaN state
|
|
726
730
|
* @returns {boolean} true if data is not a number, false otherwise.
|
|
727
731
|
*/
|
|
728
|
-
function isNaN
|
|
732
|
+
function isNaN( data ) {
|
|
729
733
|
return Number.isNaN( data )
|
|
730
734
|
}
|
|
731
735
|
|
|
@@ -753,7 +757,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
753
757
|
* @param data {*} The data to check against the array of numbers
|
|
754
758
|
* @returns {boolean} true if data is not an empty array where all values are numbers, false otherwise
|
|
755
759
|
*/
|
|
756
|
-
function isArrayOfNumber
|
|
760
|
+
function isArrayOfNumber( data ) {
|
|
757
761
|
|
|
758
762
|
if ( isNotArray( data ) ) { return false }
|
|
759
763
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -774,7 +778,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
774
778
|
* @param data {*} The data to check against the array of numbers
|
|
775
779
|
* @returns {boolean} true if data is not an empty array where all values are not numbers, false otherwise
|
|
776
780
|
*/
|
|
777
|
-
function isNotArrayOfNumber
|
|
781
|
+
function isNotArrayOfNumber( data ) {
|
|
778
782
|
|
|
779
783
|
if ( isNotArray( data ) ) { return true }
|
|
780
784
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -813,7 +817,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
813
817
|
* @param data {*} The data to check against the object type
|
|
814
818
|
* @returns {boolean} true if data is object, false otherwise
|
|
815
819
|
*/
|
|
816
|
-
function isObject
|
|
820
|
+
function isObject( data ) {
|
|
817
821
|
|
|
818
822
|
if ( isNotDefined( data ) ) { return false }
|
|
819
823
|
|
|
@@ -826,7 +830,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
826
830
|
* @param data {*} The data to check against the object type
|
|
827
831
|
* @returns {boolean} true if data is not an object, false otherwise
|
|
828
832
|
*/
|
|
829
|
-
function isNotObject
|
|
833
|
+
function isNotObject( data ) {
|
|
830
834
|
return !isObject( data )
|
|
831
835
|
}
|
|
832
836
|
|
|
@@ -854,7 +858,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
854
858
|
* @param data {*} The data to check against the array of object type
|
|
855
859
|
* @returns {boolean} true if data is an array where all values are of object type, false otherwise
|
|
856
860
|
*/
|
|
857
|
-
function isArrayOfObject
|
|
861
|
+
function isArrayOfObject( data ) {
|
|
858
862
|
|
|
859
863
|
if ( isNotArray( data ) ) { return false }
|
|
860
864
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -875,7 +879,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
875
879
|
* @param data {*} The data to check against the array of object type
|
|
876
880
|
* @returns {boolean} true if data is not an array where all values are of object type, false otherwise
|
|
877
881
|
*/
|
|
878
|
-
function isNotArrayOfObject
|
|
882
|
+
function isNotArrayOfObject( data ) {
|
|
879
883
|
|
|
880
884
|
if ( isNotArray( data ) ) { return true }
|
|
881
885
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -914,7 +918,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
914
918
|
* @param data {*} The data to check against the single valued array
|
|
915
919
|
* @returns {boolean} true if data is an array with a single value, false otherwise
|
|
916
920
|
*/
|
|
917
|
-
function isArrayOfSingleElement
|
|
921
|
+
function isArrayOfSingleElement( data ) {
|
|
918
922
|
|
|
919
923
|
if ( isNotArray( data ) ) { return false }
|
|
920
924
|
|
|
@@ -950,7 +954,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
950
954
|
* @param data {*} The data to check against the string type
|
|
951
955
|
* @returns {boolean} true if data is a string, false otherwise.
|
|
952
956
|
*/
|
|
953
|
-
function isString
|
|
957
|
+
function isString( data ) {
|
|
954
958
|
return ( typeof data === 'string' || data instanceof String )
|
|
955
959
|
}
|
|
956
960
|
|
|
@@ -960,7 +964,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
960
964
|
* @param data {*} The data to check against the string type
|
|
961
965
|
* @returns {boolean} true if data is not a string, false otherwise.
|
|
962
966
|
*/
|
|
963
|
-
function isNotString
|
|
967
|
+
function isNotString( data ) {
|
|
964
968
|
return !isString( data )
|
|
965
969
|
}
|
|
966
970
|
|
|
@@ -988,7 +992,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
988
992
|
* @param data {*} The data to check against the array of strings
|
|
989
993
|
* @returns {boolean} true if data is not an empty array where all values are string, false otherwise
|
|
990
994
|
*/
|
|
991
|
-
function isArrayOfString
|
|
995
|
+
function isArrayOfString( data ) {
|
|
992
996
|
|
|
993
997
|
if ( isNotArray( data ) ) { return false }
|
|
994
998
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -1009,7 +1013,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1009
1013
|
* @param data {*} The data to check against the array of strings
|
|
1010
1014
|
* @returns {boolean} true if data is not an empty array where all values are not string, false otherwise
|
|
1011
1015
|
*/
|
|
1012
|
-
function isNotArrayOfString
|
|
1016
|
+
function isNotArrayOfString( data ) {
|
|
1013
1017
|
|
|
1014
1018
|
if ( isNotArray( data ) ) { return true }
|
|
1015
1019
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -1048,7 +1052,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1048
1052
|
* @param data {*} The data to check against the undefiness
|
|
1049
1053
|
* @returns {boolean} true if data is undefined, false otherwise.
|
|
1050
1054
|
*/
|
|
1051
|
-
function isUndefined
|
|
1055
|
+
function isUndefined( data ) {
|
|
1052
1056
|
return ( typeof data === 'undefined' )
|
|
1053
1057
|
}
|
|
1054
1058
|
|
|
@@ -1058,7 +1062,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1058
1062
|
* @param data {*} The data to check against the undefiness
|
|
1059
1063
|
* @returns {boolean} true if data is defined, false otherwise.
|
|
1060
1064
|
*/
|
|
1061
|
-
function isNotUndefined
|
|
1065
|
+
function isNotUndefined( data ) {
|
|
1062
1066
|
return ( typeof data !== 'undefined' )
|
|
1063
1067
|
}
|
|
1064
1068
|
|
|
@@ -1086,7 +1090,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1086
1090
|
* @param data {*} The data to check against the array of undefined
|
|
1087
1091
|
* @returns {boolean} true if data is not an empty array where all values are undefined, false otherwise
|
|
1088
1092
|
*/
|
|
1089
|
-
function isArrayOfUndefined
|
|
1093
|
+
function isArrayOfUndefined( data ) {
|
|
1090
1094
|
|
|
1091
1095
|
if ( isNotArray( data ) ) { return false }
|
|
1092
1096
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -1107,7 +1111,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1107
1111
|
* @param data {*} The data to check against the array of undefined
|
|
1108
1112
|
* @returns {boolean} true if data is not an empty array where all values are defined, false otherwise
|
|
1109
1113
|
*/
|
|
1110
|
-
function isNotArrayOfUndefined
|
|
1114
|
+
function isNotArrayOfUndefined( data ) {
|
|
1111
1115
|
|
|
1112
1116
|
if ( isNotArray( data ) ) { return true }
|
|
1113
1117
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -1146,7 +1150,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1146
1150
|
* @param data {*} The data to check against true value
|
|
1147
1151
|
* @returns {boolean} true if data is a boolean set to true, false otherwise.
|
|
1148
1152
|
*/
|
|
1149
|
-
function isTrue
|
|
1153
|
+
function isTrue( data ) {
|
|
1150
1154
|
return ( isBoolean( data ) && ( data === true ) )
|
|
1151
1155
|
}
|
|
1152
1156
|
|
|
@@ -1156,7 +1160,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1156
1160
|
* @param data {*} The data to check against false value
|
|
1157
1161
|
* @returns {boolean} true if data is a boolean set to false, false otherwise.
|
|
1158
1162
|
*/
|
|
1159
|
-
function isFalse
|
|
1163
|
+
function isFalse( data ) {
|
|
1160
1164
|
return ( isBoolean( data ) && ( data === false ) )
|
|
1161
1165
|
}
|
|
1162
1166
|
|
|
@@ -1184,7 +1188,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1184
1188
|
* @param data {*} The data to check against the positive maximum state
|
|
1185
1189
|
* @returns {boolean} true if data is positive maximum, false otherwise
|
|
1186
1190
|
*/
|
|
1187
|
-
function isMaxPositive
|
|
1191
|
+
function isMaxPositive( data ) {
|
|
1188
1192
|
return ( data === Number.MAX_VALUE )
|
|
1189
1193
|
}
|
|
1190
1194
|
|
|
@@ -1194,7 +1198,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1194
1198
|
* @param data {*} The data to check against the maximum infinite state
|
|
1195
1199
|
* @returns {boolean} true if data is negative maximum, false otherwise
|
|
1196
1200
|
*/
|
|
1197
|
-
function isMaxNegative
|
|
1201
|
+
function isMaxNegative( data ) {
|
|
1198
1202
|
return ( data === -Number.MAX_VALUE )
|
|
1199
1203
|
}
|
|
1200
1204
|
|
|
@@ -1222,7 +1226,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1222
1226
|
* @param data {*} The data to check against the positive minimum state
|
|
1223
1227
|
* @returns {boolean} true if data is positive minimum, false otherwise
|
|
1224
1228
|
*/
|
|
1225
|
-
function isMinPositive
|
|
1229
|
+
function isMinPositive( data ) {
|
|
1226
1230
|
return ( data === Number.MIN_VALUE )
|
|
1227
1231
|
}
|
|
1228
1232
|
|
|
@@ -1232,7 +1236,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1232
1236
|
* @param data {*} The data to check against the minimum infinite state
|
|
1233
1237
|
* @returns {boolean} true if data is negative minimum, false otherwise
|
|
1234
1238
|
*/
|
|
1235
|
-
function isMinNegative
|
|
1239
|
+
function isMinNegative( data ) {
|
|
1236
1240
|
return ( data === -Number.MIN_VALUE )
|
|
1237
1241
|
}
|
|
1238
1242
|
|
|
@@ -1260,7 +1264,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1260
1264
|
* @param data {*} The data to check against the maximum safe integer state
|
|
1261
1265
|
* @returns {boolean} true if data is a maximum safe integer, false otherwise
|
|
1262
1266
|
*/
|
|
1263
|
-
function isMaxSafeInteger
|
|
1267
|
+
function isMaxSafeInteger( data ) {
|
|
1264
1268
|
return ( data === Number.MAX_SAFE_INTEGER )
|
|
1265
1269
|
}
|
|
1266
1270
|
|
|
@@ -1272,7 +1276,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1272
1276
|
* @param data {*} The data to check against the minimum safe integer state
|
|
1273
1277
|
* @returns {boolean} true if data is a minimum safe integer, false otherwise
|
|
1274
1278
|
*/
|
|
1275
|
-
function isMinSafeInteger
|
|
1279
|
+
function isMinSafeInteger( data ) {
|
|
1276
1280
|
return ( data === Number.MIN_SAFE_INTEGER )
|
|
1277
1281
|
}
|
|
1278
1282
|
|
|
@@ -1302,7 +1306,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1302
1306
|
* @param data {*} The data to check against the emptiness of the object
|
|
1303
1307
|
* @returns {boolean} true if data is an empty object, false otherwise
|
|
1304
1308
|
*/
|
|
1305
|
-
function isEmptyObject
|
|
1309
|
+
function isEmptyObject( data ) {
|
|
1306
1310
|
|
|
1307
1311
|
if ( isNotObject( data ) ) { return false }
|
|
1308
1312
|
|
|
@@ -1327,7 +1331,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1327
1331
|
* @param data {*} The data to check against the emptiness of the object
|
|
1328
1332
|
* @returns {boolean} true if data is not an empty object, false otherwise
|
|
1329
1333
|
*/
|
|
1330
|
-
function isNotEmptyObject
|
|
1334
|
+
function isNotEmptyObject( data ) {
|
|
1331
1335
|
return !( isEmptyObject( data ) )
|
|
1332
1336
|
}
|
|
1333
1337
|
|
|
@@ -1355,7 +1359,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1355
1359
|
* @param data {*} The data to check against the emptiness of the string
|
|
1356
1360
|
* @returns {boolean} true if data is an empty string, false otherwise.
|
|
1357
1361
|
*/
|
|
1358
|
-
function isEmptyString
|
|
1362
|
+
function isEmptyString( data ) {
|
|
1359
1363
|
|
|
1360
1364
|
if ( isNotString( data ) ) {
|
|
1361
1365
|
return false
|
|
@@ -1371,7 +1375,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1371
1375
|
* @param data {*} The data to check against the emptiness of the string
|
|
1372
1376
|
* @returns {boolean} true if data is not an empty string, false otherwise.
|
|
1373
1377
|
*/
|
|
1374
|
-
function isNotEmptyString
|
|
1378
|
+
function isNotEmptyString( data ) {
|
|
1375
1379
|
|
|
1376
1380
|
return !( isEmptyString( data ) )
|
|
1377
1381
|
|
|
@@ -1401,7 +1405,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1401
1405
|
* @param data {*} The data to check against the blankness of the string
|
|
1402
1406
|
* @returns {boolean} true if data is a blank string, false otherwise.
|
|
1403
1407
|
*/
|
|
1404
|
-
function isBlankString
|
|
1408
|
+
function isBlankString( data ) {
|
|
1405
1409
|
|
|
1406
1410
|
if ( isNotString( data ) ) { return false }
|
|
1407
1411
|
if ( isEmptyString( data ) ) { return false }
|
|
@@ -1415,7 +1419,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1415
1419
|
* @param data {*} The data to check against the blankness of the string
|
|
1416
1420
|
* @returns {boolean} true if data is not a blank string, false otherwise.
|
|
1417
1421
|
*/
|
|
1418
|
-
function isNotBlankString
|
|
1422
|
+
function isNotBlankString( data ) {
|
|
1419
1423
|
|
|
1420
1424
|
return !( isBlankString( data ) )
|
|
1421
1425
|
|
|
@@ -1445,7 +1449,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1445
1449
|
* @param data {*} The data to check against the symbol type
|
|
1446
1450
|
* @returns {boolean} true if data is a symbol, false otherwise.
|
|
1447
1451
|
*/
|
|
1448
|
-
function isSymbol
|
|
1452
|
+
function isSymbol( data ) {
|
|
1449
1453
|
return ( typeof data === 'symbol' )
|
|
1450
1454
|
}
|
|
1451
1455
|
|
|
@@ -1455,7 +1459,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1455
1459
|
* @param data {*} The data to check against the symbol type
|
|
1456
1460
|
* @returns {boolean} true if data is not a symbol, false otherwise.
|
|
1457
1461
|
*/
|
|
1458
|
-
function isNotSymbol
|
|
1462
|
+
function isNotSymbol( data ) {
|
|
1459
1463
|
return ( typeof data !== 'symbol' )
|
|
1460
1464
|
}
|
|
1461
1465
|
|
|
@@ -1485,7 +1489,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1485
1489
|
* @param data {*} The data to check against the emptiness
|
|
1486
1490
|
* @returns {boolean} true if data is considered as empty, false otherwise.
|
|
1487
1491
|
*/
|
|
1488
|
-
function isEmpty
|
|
1492
|
+
function isEmpty( data ) {
|
|
1489
1493
|
|
|
1490
1494
|
if ( isNotDefined( data ) ) { return false }
|
|
1491
1495
|
if ( isEmptyString( data ) ) { return true}
|
|
@@ -1502,7 +1506,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1502
1506
|
* @param data {*} The data to check against the emptiness
|
|
1503
1507
|
* @returns {boolean} true if data is considered as not empty, false otherwise.
|
|
1504
1508
|
*/
|
|
1505
|
-
function isNotEmpty
|
|
1509
|
+
function isNotEmpty( data ) {
|
|
1506
1510
|
return !isEmpty( data )
|
|
1507
1511
|
}
|
|
1508
1512
|
|
|
@@ -1520,121 +1524,121 @@ this.Itee.Validators = (function (exports) {
|
|
|
1520
1524
|
// Usefull when a simple data structure is used multiple times
|
|
1521
1525
|
validator.add( 'ColorType', color => {
|
|
1522
1526
|
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
+
const r = color.r
|
|
1528
|
+
if ( color.r === undefined || Itee.Validators.isNotNumber( r ) ) {
|
|
1529
|
+
return false
|
|
1530
|
+
}
|
|
1527
1531
|
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
+
const g = color.g
|
|
1533
|
+
if ( color.g === undefined || Itee.Validators.isNotNumber( g ) ) {
|
|
1534
|
+
return false
|
|
1535
|
+
}
|
|
1532
1536
|
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
+
const b = color.b
|
|
1538
|
+
if ( color.b === undefined || Itee.Validators.isNotNumber( b ) ) {
|
|
1539
|
+
return false
|
|
1540
|
+
}
|
|
1537
1541
|
|
|
1538
|
-
|
|
1539
|
-
|
|
1542
|
+
return true
|
|
1543
|
+
} )
|
|
1540
1544
|
|
|
1541
1545
|
// Using schema composition
|
|
1542
1546
|
// Usefull for design validation schema faster and based on previous declared validation types
|
|
1543
1547
|
validator.add( 'Range_0_255', ( value ) => {
|
|
1544
1548
|
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1549
|
+
if ( Itee.Validators.isNotNumber( value ) ) {
|
|
1550
|
+
return false
|
|
1551
|
+
}
|
|
1548
1552
|
|
|
1549
|
-
|
|
1553
|
+
return !(value <= 0 || value > 255)
|
|
1550
1554
|
|
|
1551
|
-
|
|
1555
|
+
} )
|
|
1552
1556
|
|
|
1553
1557
|
validator.add( 'ColorSchema', {
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1558
|
+
r: {
|
|
1559
|
+
required: true,
|
|
1560
|
+
type: 'Range_0_255'
|
|
1561
|
+
},
|
|
1562
|
+
g: {
|
|
1563
|
+
required: true,
|
|
1564
|
+
type: 'Range_0_255'
|
|
1565
|
+
},
|
|
1566
|
+
b: {
|
|
1567
|
+
required: true,
|
|
1568
|
+
type: 'Range_0_255'
|
|
1569
|
+
}
|
|
1570
|
+
} )
|
|
1567
1571
|
|
|
1568
1572
|
validator.add( 'ColorStructure', {
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1573
|
+
color_from_type: {
|
|
1574
|
+
type: 'ColorType'
|
|
1575
|
+
},
|
|
1576
|
+
col_from_schema: {
|
|
1577
|
+
type: 'ColorSchema'
|
|
1578
|
+
},
|
|
1579
|
+
col_from_fn: {
|
|
1580
|
+
// Inner function
|
|
1581
|
+
// Usefull for specific validation requirement that cannot match other previous validation schema or type
|
|
1582
|
+
fn: function ColorValidator ( color ) {
|
|
1583
|
+
|
|
1584
|
+
const r = color.r
|
|
1585
|
+
if ( color.r === undefined || Itee.Validators.isNotNumber( r ) ) {
|
|
1586
|
+
return false
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
const g = color.g
|
|
1590
|
+
if ( color.g === undefined || Itee.Validators.isNotNumber( g ) ) {
|
|
1591
|
+
return false
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
const b = color.b
|
|
1595
|
+
if ( color.b === undefined || Itee.Validators.isNotNumber( b ) ) {
|
|
1596
|
+
return false
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
return true
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
} )
|
|
1599
1603
|
|
|
1600
1604
|
// The data to validate
|
|
1601
1605
|
const colorStruct = {
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1606
|
+
color_from_type: {
|
|
1607
|
+
r: 0,
|
|
1608
|
+
g: 1,
|
|
1609
|
+
b: 2
|
|
1610
|
+
},
|
|
1611
|
+
col_from_schema: {
|
|
1612
|
+
r: 10,
|
|
1613
|
+
g: 20,
|
|
1614
|
+
b: 30
|
|
1615
|
+
},
|
|
1616
|
+
col_from_fn: {
|
|
1617
|
+
r: 0,
|
|
1618
|
+
g: 127,
|
|
1619
|
+
b: 255
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1618
1622
|
|
|
1619
1623
|
// Execute
|
|
1620
1624
|
|
|
1621
1625
|
try {
|
|
1622
1626
|
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1627
|
+
if ( validator.check( colorStruct, 'ColorStructure' ) ) {
|
|
1628
|
+
alert( 'ColorStructure is valid !' )
|
|
1629
|
+
} else {
|
|
1630
|
+
alert( validator.errors )
|
|
1631
|
+
}
|
|
1628
1632
|
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1633
|
+
} catch ( err ) {
|
|
1634
|
+
alert( err )
|
|
1635
|
+
}
|
|
1632
1636
|
*
|
|
1633
1637
|
*/
|
|
1634
1638
|
|
|
1635
1639
|
class Validator {
|
|
1636
1640
|
|
|
1637
|
-
constructor
|
|
1641
|
+
constructor() {
|
|
1638
1642
|
|
|
1639
1643
|
/**
|
|
1640
1644
|
* The validators store, by default it contains validators for Boolean, Number, Integer, Float, Array, String, Object, Symbol and Function
|
|
@@ -1668,7 +1672,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1668
1672
|
* @param type {string} - A string that represent the type of data to validate
|
|
1669
1673
|
* @param validator {(function|object)} - A function or validation schema that represent the type of data to validate
|
|
1670
1674
|
*/
|
|
1671
|
-
add
|
|
1675
|
+
add( type, validator ) {
|
|
1672
1676
|
|
|
1673
1677
|
if ( isNotString( type ) ) { throw new TypeError( `Validator: Expect type to be a string` ) }
|
|
1674
1678
|
if ( isNotFunction( validator ) && isNotObject( validator ) ) { throw new TypeError( `Validator: Expect validator to be an object or a function` ) }
|
|
@@ -1683,7 +1687,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1683
1687
|
*
|
|
1684
1688
|
* @param type {string} - The type to remove
|
|
1685
1689
|
*/
|
|
1686
|
-
remove
|
|
1690
|
+
remove( type ) {
|
|
1687
1691
|
|
|
1688
1692
|
delete this.validators[ type ];
|
|
1689
1693
|
|
|
@@ -1694,7 +1698,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1694
1698
|
*
|
|
1695
1699
|
* @return {Array.<string>} - The list of registered type
|
|
1696
1700
|
*/
|
|
1697
|
-
getAvalaibleTypes
|
|
1701
|
+
getAvalaibleTypes() {
|
|
1698
1702
|
|
|
1699
1703
|
const availablesTypes = [];
|
|
1700
1704
|
|
|
@@ -1714,7 +1718,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1714
1718
|
* @param breakOnError {boolean} - Return on first validation error ( true by default )
|
|
1715
1719
|
* @return {boolean} - Return true is the data is validated, false otherwise
|
|
1716
1720
|
*/
|
|
1717
|
-
check
|
|
1721
|
+
check( data, type, breakOnError = true ) {
|
|
1718
1722
|
|
|
1719
1723
|
const validator = this.validators[ type ];
|
|
1720
1724
|
if ( isNotDefined( validator ) ) {
|
|
@@ -1820,7 +1824,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1820
1824
|
* @param data {*} The data to check against the array buffer type
|
|
1821
1825
|
* @returns {boolean} true if data is a array buffer, false otherwise.
|
|
1822
1826
|
*/
|
|
1823
|
-
function isArrayBuffer
|
|
1827
|
+
function isArrayBuffer( data ) {
|
|
1824
1828
|
return ( data instanceof ArrayBuffer )
|
|
1825
1829
|
}
|
|
1826
1830
|
|
|
@@ -1830,7 +1834,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1830
1834
|
* @param data {*} The data to check against the array buffer type
|
|
1831
1835
|
* @returns {boolean} true if data is not a array buffer, false otherwise.
|
|
1832
1836
|
*/
|
|
1833
|
-
function isNotArrayBuffer
|
|
1837
|
+
function isNotArrayBuffer( data ) {
|
|
1834
1838
|
return !isArrayBuffer( data )
|
|
1835
1839
|
}
|
|
1836
1840
|
|
|
@@ -1858,7 +1862,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1858
1862
|
* @param data {*} The data to check against the big int 64 array type
|
|
1859
1863
|
* @returns {boolean} true if data is a big int 64 array, false otherwise.
|
|
1860
1864
|
*/
|
|
1861
|
-
function isBigInt64Array
|
|
1865
|
+
function isBigInt64Array( data ) {
|
|
1862
1866
|
return ( data instanceof BigInt64Array )
|
|
1863
1867
|
}
|
|
1864
1868
|
|
|
@@ -1868,7 +1872,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1868
1872
|
* @param data {*} The data to check against the big int 64 array type
|
|
1869
1873
|
* @returns {boolean} true if data is not a big int 64 array, false otherwise.
|
|
1870
1874
|
*/
|
|
1871
|
-
function isNotBigInt64Array
|
|
1875
|
+
function isNotBigInt64Array( data ) {
|
|
1872
1876
|
return !isBigInt64Array( data )
|
|
1873
1877
|
}
|
|
1874
1878
|
|
|
@@ -1896,7 +1900,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1896
1900
|
* @param data {*} The data to check against the big unsigned int 64 array type
|
|
1897
1901
|
* @returns {boolean} true if data is a big unsigned int 64 array, false otherwise.
|
|
1898
1902
|
*/
|
|
1899
|
-
function isBigUint64Array
|
|
1903
|
+
function isBigUint64Array( data ) {
|
|
1900
1904
|
return ( data instanceof BigUint64Array )
|
|
1901
1905
|
}
|
|
1902
1906
|
|
|
@@ -1906,7 +1910,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1906
1910
|
* @param data {*} The data to check against the big unsigned int 64 array type
|
|
1907
1911
|
* @returns {boolean} true if data is not a big unsigned int 64 array, false otherwise.
|
|
1908
1912
|
*/
|
|
1909
|
-
function isNotBigUint64Array
|
|
1913
|
+
function isNotBigUint64Array( data ) {
|
|
1910
1914
|
return !isBigUint64Array( data )
|
|
1911
1915
|
}
|
|
1912
1916
|
|
|
@@ -1934,7 +1938,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1934
1938
|
* @param data {*} The data to check against the float 32 array type
|
|
1935
1939
|
* @returns {boolean} true if data is a float 32 array , false otherwise.
|
|
1936
1940
|
*/
|
|
1937
|
-
function isFloat32Array
|
|
1941
|
+
function isFloat32Array( data ) {
|
|
1938
1942
|
return ( data instanceof Float32Array )
|
|
1939
1943
|
}
|
|
1940
1944
|
|
|
@@ -1944,7 +1948,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1944
1948
|
* @param data {*} The data to check against the float 32 array type
|
|
1945
1949
|
* @returns {boolean} true if data is not a float 32 array , false otherwise.
|
|
1946
1950
|
*/
|
|
1947
|
-
function isNotFloat32Array
|
|
1951
|
+
function isNotFloat32Array( data ) {
|
|
1948
1952
|
return !isFloat32Array( data )
|
|
1949
1953
|
}
|
|
1950
1954
|
|
|
@@ -1972,7 +1976,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1972
1976
|
* @param data {*} The data to check against the float 64 array type
|
|
1973
1977
|
* @returns {boolean} true if data is a float 64 array , false otherwise.
|
|
1974
1978
|
*/
|
|
1975
|
-
function isFloat64Array
|
|
1979
|
+
function isFloat64Array( data ) {
|
|
1976
1980
|
return ( data instanceof Float64Array )
|
|
1977
1981
|
}
|
|
1978
1982
|
|
|
@@ -1982,7 +1986,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
1982
1986
|
* @param data {*} The data to check against the float 64 array type
|
|
1983
1987
|
* @returns {boolean} true if data is not a float 64 array , false otherwise.
|
|
1984
1988
|
*/
|
|
1985
|
-
function isNotFloat64Array
|
|
1989
|
+
function isNotFloat64Array( data ) {
|
|
1986
1990
|
return !isFloat64Array( data )
|
|
1987
1991
|
}
|
|
1988
1992
|
|
|
@@ -2010,7 +2014,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2010
2014
|
* @param data {*} The data to check against the int 16 array type
|
|
2011
2015
|
* @returns {boolean} true if data is a int 16 array , false otherwise.
|
|
2012
2016
|
*/
|
|
2013
|
-
function isInt16Array
|
|
2017
|
+
function isInt16Array( data ) {
|
|
2014
2018
|
return ( data instanceof Int16Array )
|
|
2015
2019
|
}
|
|
2016
2020
|
|
|
@@ -2020,7 +2024,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2020
2024
|
* @param data {*} The data to check against the int 16 array type
|
|
2021
2025
|
* @returns {boolean} true if data is not a int 16 array , false otherwise.
|
|
2022
2026
|
*/
|
|
2023
|
-
function isNotInt16Array
|
|
2027
|
+
function isNotInt16Array( data ) {
|
|
2024
2028
|
return !isInt16Array( data )
|
|
2025
2029
|
}
|
|
2026
2030
|
|
|
@@ -2048,7 +2052,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2048
2052
|
* @param data {*} The data to check against the int 32 array type
|
|
2049
2053
|
* @returns {boolean} true if data is a int 32 array , false otherwise.
|
|
2050
2054
|
*/
|
|
2051
|
-
function isInt32Array
|
|
2055
|
+
function isInt32Array( data ) {
|
|
2052
2056
|
return ( data instanceof Int32Array )
|
|
2053
2057
|
}
|
|
2054
2058
|
|
|
@@ -2058,7 +2062,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2058
2062
|
* @param data {*} The data to check against the int 32 array type
|
|
2059
2063
|
* @returns {boolean} true if data is not a int 32 array , false otherwise.
|
|
2060
2064
|
*/
|
|
2061
|
-
function isNotInt32Array
|
|
2065
|
+
function isNotInt32Array( data ) {
|
|
2062
2066
|
return !isInt32Array( data )
|
|
2063
2067
|
}
|
|
2064
2068
|
|
|
@@ -2086,7 +2090,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2086
2090
|
* @param data {*} The data to check against the int 8 array type
|
|
2087
2091
|
* @returns {boolean} true if data is a int 8 array , false otherwise.
|
|
2088
2092
|
*/
|
|
2089
|
-
function isInt8Array
|
|
2093
|
+
function isInt8Array( data ) {
|
|
2090
2094
|
return ( data instanceof Int8Array )
|
|
2091
2095
|
}
|
|
2092
2096
|
|
|
@@ -2096,7 +2100,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2096
2100
|
* @param data {*} The data to check against the int 8 array type
|
|
2097
2101
|
* @returns {boolean} true if data is not a int 8 array , false otherwise.
|
|
2098
2102
|
*/
|
|
2099
|
-
function isNotInt8Array
|
|
2103
|
+
function isNotInt8Array( data ) {
|
|
2100
2104
|
return !isInt8Array( data )
|
|
2101
2105
|
}
|
|
2102
2106
|
|
|
@@ -2124,7 +2128,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2124
2128
|
* @param data {*} The data to check against the unsigned int 16 array type
|
|
2125
2129
|
* @returns {boolean} true if data is a unsigned int 16 array , false otherwise.
|
|
2126
2130
|
*/
|
|
2127
|
-
function isUint16Array
|
|
2131
|
+
function isUint16Array( data ) {
|
|
2128
2132
|
return ( data instanceof Uint16Array )
|
|
2129
2133
|
}
|
|
2130
2134
|
|
|
@@ -2134,7 +2138,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2134
2138
|
* @param data {*} The data to check against the unsigned int 16 array type
|
|
2135
2139
|
* @returns {boolean} true if data is not a unsigned int 16 array , false otherwise.
|
|
2136
2140
|
*/
|
|
2137
|
-
function isNotUint16Array
|
|
2141
|
+
function isNotUint16Array( data ) {
|
|
2138
2142
|
return !isUint16Array( data )
|
|
2139
2143
|
}
|
|
2140
2144
|
|
|
@@ -2162,7 +2166,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2162
2166
|
* @param data {*} The data to check against the unsigned int 32 array type
|
|
2163
2167
|
* @returns {boolean} true if data is a unsigned int 32 array , false otherwise.
|
|
2164
2168
|
*/
|
|
2165
|
-
function isUint32Array
|
|
2169
|
+
function isUint32Array( data ) {
|
|
2166
2170
|
return ( data instanceof Uint32Array )
|
|
2167
2171
|
}
|
|
2168
2172
|
|
|
@@ -2172,7 +2176,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2172
2176
|
* @param data {*} The data to check against the unsigned int 32 array type
|
|
2173
2177
|
* @returns {boolean} true if data is not a unsigned int 32 array , false otherwise.
|
|
2174
2178
|
*/
|
|
2175
|
-
function isNotUint32Array
|
|
2179
|
+
function isNotUint32Array( data ) {
|
|
2176
2180
|
return !isUint32Array( data )
|
|
2177
2181
|
}
|
|
2178
2182
|
|
|
@@ -2200,7 +2204,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2200
2204
|
* @param data {*} The data to check against the unsigned int 8 array type
|
|
2201
2205
|
* @returns {boolean} true if data is a unsigned int 8 array , false otherwise.
|
|
2202
2206
|
*/
|
|
2203
|
-
function isUint8Array
|
|
2207
|
+
function isUint8Array( data ) {
|
|
2204
2208
|
return ( data instanceof Uint8Array )
|
|
2205
2209
|
}
|
|
2206
2210
|
|
|
@@ -2210,7 +2214,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2210
2214
|
* @param data {*} The data to check against the unsigned int 8 array type
|
|
2211
2215
|
* @returns {boolean} true if data is not a unsigned int 8 array , false otherwise.
|
|
2212
2216
|
*/
|
|
2213
|
-
function isNotUint8Array
|
|
2217
|
+
function isNotUint8Array( data ) {
|
|
2214
2218
|
return !isUint8Array( data )
|
|
2215
2219
|
}
|
|
2216
2220
|
|
|
@@ -2238,7 +2242,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2238
2242
|
* @param data {*} The data to check against the unsigned clamped int 8 array type
|
|
2239
2243
|
* @returns {boolean} true if data is a unsigned clamped int 8 array , false otherwise.
|
|
2240
2244
|
*/
|
|
2241
|
-
function isUint8ClampedArray
|
|
2245
|
+
function isUint8ClampedArray( data ) {
|
|
2242
2246
|
return ( data instanceof Uint8ClampedArray )
|
|
2243
2247
|
}
|
|
2244
2248
|
|
|
@@ -2248,7 +2252,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2248
2252
|
* @param data {*} The data to check against the unsigned clamped int 8 array type
|
|
2249
2253
|
* @returns {boolean} true if data is not a unsigned clamped int 8 array , false otherwise.
|
|
2250
2254
|
*/
|
|
2251
|
-
function isNotUint8ClampedArray
|
|
2255
|
+
function isNotUint8ClampedArray( data ) {
|
|
2252
2256
|
return !isUint8ClampedArray( data )
|
|
2253
2257
|
}
|
|
2254
2258
|
|
|
@@ -2308,7 +2312,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2308
2312
|
* @param data {*}
|
|
2309
2313
|
* @return {boolean}
|
|
2310
2314
|
*/
|
|
2311
|
-
function isCelsius
|
|
2315
|
+
function isCelsius( data ) {
|
|
2312
2316
|
return ( isNumber( data ) && data >= ABSOLUTE_ZERO_CELSIUS )
|
|
2313
2317
|
}
|
|
2314
2318
|
|
|
@@ -2317,7 +2321,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2317
2321
|
* @param data {*}
|
|
2318
2322
|
* @return {boolean}
|
|
2319
2323
|
*/
|
|
2320
|
-
function isNotCelsius
|
|
2324
|
+
function isNotCelsius( data ) {
|
|
2321
2325
|
return !isCelsius( data )
|
|
2322
2326
|
}
|
|
2323
2327
|
|
|
@@ -2344,7 +2348,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2344
2348
|
* @param data {*}
|
|
2345
2349
|
* @return {boolean}
|
|
2346
2350
|
*/
|
|
2347
|
-
function isFahrenheit
|
|
2351
|
+
function isFahrenheit( data ) {
|
|
2348
2352
|
return ( isNumber( data ) && data >= ABSOLUTE_ZERO_FAHRENHEIT )
|
|
2349
2353
|
}
|
|
2350
2354
|
|
|
@@ -2353,7 +2357,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2353
2357
|
* @param data {*}
|
|
2354
2358
|
* @return {boolean}
|
|
2355
2359
|
*/
|
|
2356
|
-
function isNotFahrenheit
|
|
2360
|
+
function isNotFahrenheit( data ) {
|
|
2357
2361
|
return !isFahrenheit( data )
|
|
2358
2362
|
}
|
|
2359
2363
|
|
|
@@ -2380,7 +2384,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2380
2384
|
* @param data {*}
|
|
2381
2385
|
* @return {boolean}
|
|
2382
2386
|
*/
|
|
2383
|
-
function isKelvin
|
|
2387
|
+
function isKelvin( data ) {
|
|
2384
2388
|
return ( isNumber( data ) && data >= ABSOLUTE_ZERO_KELVIN )
|
|
2385
2389
|
}
|
|
2386
2390
|
|
|
@@ -2389,7 +2393,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2389
2393
|
* @param data {*}
|
|
2390
2394
|
* @return {boolean}
|
|
2391
2395
|
*/
|
|
2392
|
-
function isNotKelvin
|
|
2396
|
+
function isNotKelvin( data ) {
|
|
2393
2397
|
return !isKelvin( data )
|
|
2394
2398
|
}
|
|
2395
2399
|
|
|
@@ -2416,7 +2420,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2416
2420
|
* @param data {*}
|
|
2417
2421
|
* @return {boolean}
|
|
2418
2422
|
*/
|
|
2419
|
-
function isTemperature
|
|
2423
|
+
function isTemperature( data ) {
|
|
2420
2424
|
return ( isKelvin( data ) || isCelsius( data ) || isFahrenheit( data ) )
|
|
2421
2425
|
}
|
|
2422
2426
|
|
|
@@ -2425,7 +2429,7 @@ this.Itee.Validators = (function (exports) {
|
|
|
2425
2429
|
* @param data {*}
|
|
2426
2430
|
* @return {boolean}
|
|
2427
2431
|
*/
|
|
2428
|
-
function isNotTemperature
|
|
2432
|
+
function isNotTemperature( data ) {
|
|
2429
2433
|
return ( isNotKelvin( data ) && isNotCelsius( data ) && isNotFahrenheit( data ) )
|
|
2430
2434
|
}
|
|
2431
2435
|
|