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