itee-validators 5.3.8 → 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 +22 -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 +4 -2
- 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
|
/**
|
|
3
12
|
* @author [Tristan Valcke]{@link https://github.com/Itee}
|
|
4
13
|
* @license [BSD-3-Clause]{@link https://opensource.org/licenses/BSD-3-Clause}
|
|
@@ -23,7 +32,7 @@ console.log('Itee.Validators v5.3.8 - EsModule')
|
|
|
23
32
|
* @param data {*} The data to check against the array type
|
|
24
33
|
* @returns {boolean} true if data is array, false otherwise
|
|
25
34
|
*/
|
|
26
|
-
function isArray
|
|
35
|
+
function isArray( data ) {
|
|
27
36
|
return Array.isArray( data )
|
|
28
37
|
}
|
|
29
38
|
|
|
@@ -33,7 +42,7 @@ function isArray ( data ) {
|
|
|
33
42
|
* @param data {*} The data to check against the array type
|
|
34
43
|
* @returns {boolean} true if data is not array, false otherwise
|
|
35
44
|
*/
|
|
36
|
-
function isNotArray
|
|
45
|
+
function isNotArray( data ) {
|
|
37
46
|
return !Array.isArray( data )
|
|
38
47
|
}
|
|
39
48
|
|
|
@@ -61,7 +70,7 @@ function isNotArray ( data ) {
|
|
|
61
70
|
* @param data {*} The data to check against the empty array
|
|
62
71
|
* @returns {boolean} true if data is an empty array, false otherwise
|
|
63
72
|
*/
|
|
64
|
-
function isEmptyArray
|
|
73
|
+
function isEmptyArray( data ) {
|
|
65
74
|
|
|
66
75
|
if ( isNotArray( data ) ) { return false }
|
|
67
76
|
|
|
@@ -75,7 +84,7 @@ function isEmptyArray ( data ) {
|
|
|
75
84
|
* @param data {*} The data to check against the empty array
|
|
76
85
|
* @returns {boolean} true if data is not an empty array, false otherwise
|
|
77
86
|
*/
|
|
78
|
-
function isNotEmptyArray
|
|
87
|
+
function isNotEmptyArray( data ) {
|
|
79
88
|
|
|
80
89
|
if ( isNotArray( data ) ) { return true }
|
|
81
90
|
|
|
@@ -107,7 +116,7 @@ function isNotEmptyArray ( data ) {
|
|
|
107
116
|
* @param data {*} The data to check against the array of array type
|
|
108
117
|
* @returns {boolean} true if data is an array of array, false otherwise
|
|
109
118
|
*/
|
|
110
|
-
function isArrayOfArray
|
|
119
|
+
function isArrayOfArray( data ) {
|
|
111
120
|
|
|
112
121
|
if ( isNotArray( data ) ) { return false }
|
|
113
122
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -128,7 +137,7 @@ function isArrayOfArray ( data ) {
|
|
|
128
137
|
* @param data {*} The data to check against the array of array type
|
|
129
138
|
* @returns {boolean} true if data is not an array of array, false otherwise
|
|
130
139
|
*/
|
|
131
|
-
function isNotArrayOfArray
|
|
140
|
+
function isNotArrayOfArray( data ) {
|
|
132
141
|
|
|
133
142
|
if ( isNotArray( data ) ) { return true }
|
|
134
143
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -167,7 +176,7 @@ function isNotArrayOfArray ( data ) {
|
|
|
167
176
|
* @param data {*} The data to check against the booleaness
|
|
168
177
|
* @returns {boolean} true if data is a boolean, false otherwise.
|
|
169
178
|
*/
|
|
170
|
-
function isBoolean
|
|
179
|
+
function isBoolean( data ) {
|
|
171
180
|
return ( typeof data === 'boolean' )
|
|
172
181
|
}
|
|
173
182
|
|
|
@@ -177,7 +186,7 @@ function isBoolean ( data ) {
|
|
|
177
186
|
* @param data {*} The data to check against the booleaness
|
|
178
187
|
* @returns {boolean} true if data is not a boolean, false otherwise.
|
|
179
188
|
*/
|
|
180
|
-
function isNotBoolean
|
|
189
|
+
function isNotBoolean( data ) {
|
|
181
190
|
return ( typeof data !== 'boolean' )
|
|
182
191
|
}
|
|
183
192
|
|
|
@@ -205,7 +214,7 @@ function isNotBoolean ( data ) {
|
|
|
205
214
|
* @param data {*} The data to check against the array of booleans
|
|
206
215
|
* @returns {boolean} true if data is not an empty array where all values are boolean, false otherwise
|
|
207
216
|
*/
|
|
208
|
-
function isArrayOfBoolean
|
|
217
|
+
function isArrayOfBoolean( data ) {
|
|
209
218
|
|
|
210
219
|
if ( isNotArray( data ) ) { return false }
|
|
211
220
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -226,7 +235,7 @@ function isArrayOfBoolean ( data ) {
|
|
|
226
235
|
* @param data {*} The data to check against the array of booleans
|
|
227
236
|
* @returns {boolean} true if data is not an empty array where all values are not boolean, false otherwise
|
|
228
237
|
*/
|
|
229
|
-
function isNotArrayOfBoolean
|
|
238
|
+
function isNotArrayOfBoolean( data ) {
|
|
230
239
|
|
|
231
240
|
if ( isNotArray( data ) ) { return true }
|
|
232
241
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -265,7 +274,7 @@ function isNotArrayOfBoolean ( data ) {
|
|
|
265
274
|
* @param data {*} The data to check against the functionality
|
|
266
275
|
* @returns {boolean} true if data is a function, false otherwise.
|
|
267
276
|
*/
|
|
268
|
-
function isFunction
|
|
277
|
+
function isFunction( data ) {
|
|
269
278
|
return ( typeof data === 'function' )
|
|
270
279
|
}
|
|
271
280
|
|
|
@@ -275,7 +284,7 @@ function isFunction ( data ) {
|
|
|
275
284
|
* @param data {*} The data to check against the functionality
|
|
276
285
|
* @returns {boolean} true if data is not a function, false otherwise.
|
|
277
286
|
*/
|
|
278
|
-
function isNotFunction
|
|
287
|
+
function isNotFunction( data ) {
|
|
279
288
|
return ( typeof data !== 'function' )
|
|
280
289
|
}
|
|
281
290
|
|
|
@@ -303,7 +312,7 @@ function isNotFunction ( data ) {
|
|
|
303
312
|
* @param data {*} The data to check against the array of functions
|
|
304
313
|
* @returns {boolean} true if data is not an empty array where all values are functions, false otherwise
|
|
305
314
|
*/
|
|
306
|
-
function isArrayOfFunction
|
|
315
|
+
function isArrayOfFunction( data ) {
|
|
307
316
|
|
|
308
317
|
if ( isNotArray( data ) ) { return false }
|
|
309
318
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -324,7 +333,7 @@ function isArrayOfFunction ( data ) {
|
|
|
324
333
|
* @param data {*} The data to check against the array of functions
|
|
325
334
|
* @returns {boolean} true if data is not an empty array where all values are not functions, false otherwise
|
|
326
335
|
*/
|
|
327
|
-
function isNotArrayOfFunction
|
|
336
|
+
function isNotArrayOfFunction( data ) {
|
|
328
337
|
|
|
329
338
|
if ( isNotArray( data ) ) { return true }
|
|
330
339
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -363,7 +372,7 @@ function isNotArrayOfFunction ( data ) {
|
|
|
363
372
|
* @param data {*} The data to check against the single valued array
|
|
364
373
|
* @returns {boolean} true if data is an array with multiples values, false otherwise
|
|
365
374
|
*/
|
|
366
|
-
function isArrayOfMultiElement
|
|
375
|
+
function isArrayOfMultiElement( data ) {
|
|
367
376
|
|
|
368
377
|
if ( isNotArray( data ) ) { return false }
|
|
369
378
|
|
|
@@ -395,7 +404,7 @@ function isArrayOfMultiElement ( data ) {
|
|
|
395
404
|
* @param data {*} The data to check against the nullity
|
|
396
405
|
* @returns {boolean} true if data is null, false otherwise.
|
|
397
406
|
*/
|
|
398
|
-
function isNull
|
|
407
|
+
function isNull( data ) {
|
|
399
408
|
return ( data === null )
|
|
400
409
|
}
|
|
401
410
|
|
|
@@ -407,7 +416,7 @@ function isNull ( data ) {
|
|
|
407
416
|
* @param data {*} The data to check against the nullity
|
|
408
417
|
* @returns {boolean} true if data is not null, false otherwise.
|
|
409
418
|
*/
|
|
410
|
-
function isNotNull
|
|
419
|
+
function isNotNull( data ) {
|
|
411
420
|
return ( data !== null )
|
|
412
421
|
}
|
|
413
422
|
|
|
@@ -434,7 +443,7 @@ function isNotNull ( data ) {
|
|
|
434
443
|
* @param data {*} The data to check against the array of null type
|
|
435
444
|
* @returns {boolean} true if data is not an empty array where all values are null, false otherwise
|
|
436
445
|
*/
|
|
437
|
-
function isArrayOfNull
|
|
446
|
+
function isArrayOfNull( data ) {
|
|
438
447
|
|
|
439
448
|
if ( isNotArray( data ) ) { return false }
|
|
440
449
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -455,7 +464,7 @@ function isArrayOfNull ( data ) {
|
|
|
455
464
|
* @param data {*} The data to check against the array of null type
|
|
456
465
|
* @returns {boolean} true if data is not an empty array where all values are not null, false otherwise
|
|
457
466
|
*/
|
|
458
|
-
function isNotArrayOfNull
|
|
467
|
+
function isNotArrayOfNull( data ) {
|
|
459
468
|
|
|
460
469
|
if ( isNotArray( data ) ) { return true }
|
|
461
470
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -494,7 +503,7 @@ function isNotArrayOfNull ( data ) {
|
|
|
494
503
|
* @param data {*} The data to check against the existence
|
|
495
504
|
* @returns {boolean} true if data is not null and not undefined, false otherwise.
|
|
496
505
|
*/
|
|
497
|
-
function isDefined
|
|
506
|
+
function isDefined( data ) {
|
|
498
507
|
return ( ( data !== null ) && ( typeof data !== 'undefined' ) )
|
|
499
508
|
}
|
|
500
509
|
|
|
@@ -504,7 +513,7 @@ function isDefined ( data ) {
|
|
|
504
513
|
* @param data {*} The data to check against the existence
|
|
505
514
|
* @returns {boolean} true if data is null or undefined, false otherwise.
|
|
506
515
|
*/
|
|
507
|
-
function isNotDefined
|
|
516
|
+
function isNotDefined( data ) {
|
|
508
517
|
return ( ( data === null ) || ( typeof data === 'undefined' ) )
|
|
509
518
|
}
|
|
510
519
|
|
|
@@ -526,20 +535,6 @@ function isNotDefined ( data ) {
|
|
|
526
535
|
*
|
|
527
536
|
*/
|
|
528
537
|
|
|
529
|
-
/**
|
|
530
|
-
* Check if the given data is an infinite number
|
|
531
|
-
*
|
|
532
|
-
* @param data {*} The data to check against the infinite state
|
|
533
|
-
* @returns {boolean} true if data is infinite, false otherwise
|
|
534
|
-
*/
|
|
535
|
-
function isInfinite ( data ) {
|
|
536
|
-
|
|
537
|
-
// Todo: is required to check notnumber ?
|
|
538
|
-
if ( isNotNumber( data ) ) { return false }
|
|
539
|
-
if ( Number.isNaN( data ) ) { return false }
|
|
540
|
-
|
|
541
|
-
return !Number.isFinite( data )
|
|
542
|
-
}
|
|
543
538
|
|
|
544
539
|
/**
|
|
545
540
|
* Check if the given data is an infinite negative number
|
|
@@ -547,7 +542,7 @@ function isInfinite ( data ) {
|
|
|
547
542
|
* @param data {*} The data to check against the negative infinite state
|
|
548
543
|
* @returns {boolean} true if data is negative infinite, false otherwise
|
|
549
544
|
*/
|
|
550
|
-
function isInfiniteNegative
|
|
545
|
+
function isInfiniteNegative( data ) {
|
|
551
546
|
return ( data === Number.NEGATIVE_INFINITY )
|
|
552
547
|
}
|
|
553
548
|
|
|
@@ -557,17 +552,27 @@ function isInfiniteNegative ( data ) {
|
|
|
557
552
|
* @param data {*} The data to check against the positive infinite state
|
|
558
553
|
* @returns {boolean} true if data is positive infinite, false otherwise
|
|
559
554
|
*/
|
|
560
|
-
function isInfinitePositive
|
|
555
|
+
function isInfinitePositive( data ) {
|
|
561
556
|
return ( data === Number.POSITIVE_INFINITY )
|
|
562
557
|
}
|
|
563
558
|
|
|
559
|
+
/**
|
|
560
|
+
* Check if the given data is an infinite number
|
|
561
|
+
*
|
|
562
|
+
* @param data {*} The data to check against the infinite state
|
|
563
|
+
* @returns {boolean} true if data is infinite, false otherwise
|
|
564
|
+
*/
|
|
565
|
+
function isInfinite( data ) {
|
|
566
|
+
return isInfiniteNegative( data ) || isInfinitePositive( data )
|
|
567
|
+
}
|
|
568
|
+
|
|
564
569
|
/**
|
|
565
570
|
* Check if the given data is a finite number
|
|
566
571
|
*
|
|
567
572
|
* @param data {*} The data to check against the finite state
|
|
568
573
|
* @returns {boolean} true if data is finite, false otherwise
|
|
569
574
|
*/
|
|
570
|
-
function isFinite
|
|
575
|
+
function isFinite( data ) {
|
|
571
576
|
return Number.isFinite( data )
|
|
572
577
|
}
|
|
573
578
|
|
|
@@ -597,7 +602,7 @@ function isFinite ( data ) {
|
|
|
597
602
|
* @param data {*} The data to check against the zero value
|
|
598
603
|
* @returns {boolean} true if data is zero, false otherwise
|
|
599
604
|
*/
|
|
600
|
-
function isZero
|
|
605
|
+
function isZero( data ) {
|
|
601
606
|
//Todo protect truthy values
|
|
602
607
|
return ( data === 0 )
|
|
603
608
|
}
|
|
@@ -608,7 +613,7 @@ function isZero ( data ) {
|
|
|
608
613
|
* @param data {*} The data to check against the positive zero value
|
|
609
614
|
* @returns {boolean} true if data is a positive zero, false otherwise
|
|
610
615
|
*/
|
|
611
|
-
function isZeroPositive
|
|
616
|
+
function isZeroPositive( data ) {
|
|
612
617
|
return ( data === 0 && ( 1 / data ) === Number.POSITIVE_INFINITY )
|
|
613
618
|
}
|
|
614
619
|
|
|
@@ -618,7 +623,7 @@ function isZeroPositive ( data ) {
|
|
|
618
623
|
* @param data {*} The data to check against the negative zero value
|
|
619
624
|
* @returns {boolean} true if data is a negative zero, false otherwise
|
|
620
625
|
*/
|
|
621
|
-
function isZeroNegative
|
|
626
|
+
function isZeroNegative( data ) {
|
|
622
627
|
return ( data === 0 && ( 1 / data ) === Number.NEGATIVE_INFINITY )
|
|
623
628
|
}
|
|
624
629
|
|
|
@@ -646,7 +651,7 @@ function isZeroNegative ( data ) {
|
|
|
646
651
|
* @param data {*} The data to check against the maximum safe integer state
|
|
647
652
|
* @returns {boolean} true if data is a number, false otherwise.
|
|
648
653
|
*/
|
|
649
|
-
function isNumber
|
|
654
|
+
function isNumber( data ) {
|
|
650
655
|
|
|
651
656
|
if ( isNotDefined( data ) ) { return false }
|
|
652
657
|
|
|
@@ -660,7 +665,7 @@ function isNumber ( data ) {
|
|
|
660
665
|
* @param data {*} The data to check against the positivity
|
|
661
666
|
* @returns {boolean} true if data is a positive number, false otherwise.
|
|
662
667
|
*/
|
|
663
|
-
function isNumberPositive
|
|
668
|
+
function isNumberPositive( data ) {
|
|
664
669
|
|
|
665
670
|
if ( isNotNumber( data ) ) { return false }
|
|
666
671
|
|
|
@@ -675,7 +680,7 @@ function isNumberPositive ( data ) {
|
|
|
675
680
|
* @param data {*} The data to check against the negativity
|
|
676
681
|
* @returns {boolean} true if data is a negative number, false otherwise.
|
|
677
682
|
*/
|
|
678
|
-
function isNumberNegative
|
|
683
|
+
function isNumberNegative( data ) {
|
|
679
684
|
return ( isNumber( data ) && data < 0 )
|
|
680
685
|
}
|
|
681
686
|
|
|
@@ -685,7 +690,7 @@ function isNumberNegative ( data ) {
|
|
|
685
690
|
* @param data {*} The data to check against the number type
|
|
686
691
|
* @returns {boolean} true if data is not of type number or not a number, false otherwise.
|
|
687
692
|
*/
|
|
688
|
-
function isNotNumber
|
|
693
|
+
function isNotNumber( data ) {
|
|
689
694
|
return !( isNumber( data ) )
|
|
690
695
|
}
|
|
691
696
|
|
|
@@ -695,7 +700,7 @@ function isNotNumber ( data ) {
|
|
|
695
700
|
* @param data {*} The data to check against the integer state
|
|
696
701
|
* @returns {boolean} true if data is an integer, false otherwise
|
|
697
702
|
*/
|
|
698
|
-
function isInteger
|
|
703
|
+
function isInteger( data ) {
|
|
699
704
|
return Number.isInteger( data )
|
|
700
705
|
}
|
|
701
706
|
|
|
@@ -705,7 +710,7 @@ function isInteger ( data ) {
|
|
|
705
710
|
* @param data {*} The data to check against the floating point
|
|
706
711
|
* @returns {boolean} true if data is a float, false otherwise
|
|
707
712
|
*/
|
|
708
|
-
function isFloat
|
|
713
|
+
function isFloat( data ) {
|
|
709
714
|
|
|
710
715
|
if ( isNotNumber( data ) ) { return false }
|
|
711
716
|
if ( Number.isNaN( data ) ) { return false }
|
|
@@ -721,7 +726,7 @@ function isFloat ( data ) {
|
|
|
721
726
|
* @param data {*} The data to check against the NaN state
|
|
722
727
|
* @returns {boolean} true if data is not a number, false otherwise.
|
|
723
728
|
*/
|
|
724
|
-
function isNaN
|
|
729
|
+
function isNaN( data ) {
|
|
725
730
|
return Number.isNaN( data )
|
|
726
731
|
}
|
|
727
732
|
|
|
@@ -749,7 +754,7 @@ function isNaN ( data ) {
|
|
|
749
754
|
* @param data {*} The data to check against the array of numbers
|
|
750
755
|
* @returns {boolean} true if data is not an empty array where all values are numbers, false otherwise
|
|
751
756
|
*/
|
|
752
|
-
function isArrayOfNumber
|
|
757
|
+
function isArrayOfNumber( data ) {
|
|
753
758
|
|
|
754
759
|
if ( isNotArray( data ) ) { return false }
|
|
755
760
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -770,7 +775,7 @@ function isArrayOfNumber ( data ) {
|
|
|
770
775
|
* @param data {*} The data to check against the array of numbers
|
|
771
776
|
* @returns {boolean} true if data is not an empty array where all values are not numbers, false otherwise
|
|
772
777
|
*/
|
|
773
|
-
function isNotArrayOfNumber
|
|
778
|
+
function isNotArrayOfNumber( data ) {
|
|
774
779
|
|
|
775
780
|
if ( isNotArray( data ) ) { return true }
|
|
776
781
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -809,7 +814,7 @@ function isNotArrayOfNumber ( data ) {
|
|
|
809
814
|
* @param data {*} The data to check against the object type
|
|
810
815
|
* @returns {boolean} true if data is object, false otherwise
|
|
811
816
|
*/
|
|
812
|
-
function isObject
|
|
817
|
+
function isObject( data ) {
|
|
813
818
|
|
|
814
819
|
if ( isNotDefined( data ) ) { return false }
|
|
815
820
|
|
|
@@ -822,7 +827,7 @@ function isObject ( data ) {
|
|
|
822
827
|
* @param data {*} The data to check against the object type
|
|
823
828
|
* @returns {boolean} true if data is not an object, false otherwise
|
|
824
829
|
*/
|
|
825
|
-
function isNotObject
|
|
830
|
+
function isNotObject( data ) {
|
|
826
831
|
return !isObject( data )
|
|
827
832
|
}
|
|
828
833
|
|
|
@@ -850,7 +855,7 @@ function isNotObject ( data ) {
|
|
|
850
855
|
* @param data {*} The data to check against the array of object type
|
|
851
856
|
* @returns {boolean} true if data is an array where all values are of object type, false otherwise
|
|
852
857
|
*/
|
|
853
|
-
function isArrayOfObject
|
|
858
|
+
function isArrayOfObject( data ) {
|
|
854
859
|
|
|
855
860
|
if ( isNotArray( data ) ) { return false }
|
|
856
861
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -871,7 +876,7 @@ function isArrayOfObject ( data ) {
|
|
|
871
876
|
* @param data {*} The data to check against the array of object type
|
|
872
877
|
* @returns {boolean} true if data is not an array where all values are of object type, false otherwise
|
|
873
878
|
*/
|
|
874
|
-
function isNotArrayOfObject
|
|
879
|
+
function isNotArrayOfObject( data ) {
|
|
875
880
|
|
|
876
881
|
if ( isNotArray( data ) ) { return true }
|
|
877
882
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -910,7 +915,7 @@ function isNotArrayOfObject ( data ) {
|
|
|
910
915
|
* @param data {*} The data to check against the single valued array
|
|
911
916
|
* @returns {boolean} true if data is an array with a single value, false otherwise
|
|
912
917
|
*/
|
|
913
|
-
function isArrayOfSingleElement
|
|
918
|
+
function isArrayOfSingleElement( data ) {
|
|
914
919
|
|
|
915
920
|
if ( isNotArray( data ) ) { return false }
|
|
916
921
|
|
|
@@ -946,7 +951,7 @@ function isArrayOfSingleElement ( data ) {
|
|
|
946
951
|
* @param data {*} The data to check against the string type
|
|
947
952
|
* @returns {boolean} true if data is a string, false otherwise.
|
|
948
953
|
*/
|
|
949
|
-
function isString
|
|
954
|
+
function isString( data ) {
|
|
950
955
|
return ( typeof data === 'string' || data instanceof String )
|
|
951
956
|
}
|
|
952
957
|
|
|
@@ -956,7 +961,7 @@ function isString ( data ) {
|
|
|
956
961
|
* @param data {*} The data to check against the string type
|
|
957
962
|
* @returns {boolean} true if data is not a string, false otherwise.
|
|
958
963
|
*/
|
|
959
|
-
function isNotString
|
|
964
|
+
function isNotString( data ) {
|
|
960
965
|
return !isString( data )
|
|
961
966
|
}
|
|
962
967
|
|
|
@@ -984,7 +989,7 @@ function isNotString ( data ) {
|
|
|
984
989
|
* @param data {*} The data to check against the array of strings
|
|
985
990
|
* @returns {boolean} true if data is not an empty array where all values are string, false otherwise
|
|
986
991
|
*/
|
|
987
|
-
function isArrayOfString
|
|
992
|
+
function isArrayOfString( data ) {
|
|
988
993
|
|
|
989
994
|
if ( isNotArray( data ) ) { return false }
|
|
990
995
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -1005,7 +1010,7 @@ function isArrayOfString ( data ) {
|
|
|
1005
1010
|
* @param data {*} The data to check against the array of strings
|
|
1006
1011
|
* @returns {boolean} true if data is not an empty array where all values are not string, false otherwise
|
|
1007
1012
|
*/
|
|
1008
|
-
function isNotArrayOfString
|
|
1013
|
+
function isNotArrayOfString( data ) {
|
|
1009
1014
|
|
|
1010
1015
|
if ( isNotArray( data ) ) { return true }
|
|
1011
1016
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -1044,7 +1049,7 @@ function isNotArrayOfString ( data ) {
|
|
|
1044
1049
|
* @param data {*} The data to check against the undefiness
|
|
1045
1050
|
* @returns {boolean} true if data is undefined, false otherwise.
|
|
1046
1051
|
*/
|
|
1047
|
-
function isUndefined
|
|
1052
|
+
function isUndefined( data ) {
|
|
1048
1053
|
return ( typeof data === 'undefined' )
|
|
1049
1054
|
}
|
|
1050
1055
|
|
|
@@ -1054,7 +1059,7 @@ function isUndefined ( data ) {
|
|
|
1054
1059
|
* @param data {*} The data to check against the undefiness
|
|
1055
1060
|
* @returns {boolean} true if data is defined, false otherwise.
|
|
1056
1061
|
*/
|
|
1057
|
-
function isNotUndefined
|
|
1062
|
+
function isNotUndefined( data ) {
|
|
1058
1063
|
return ( typeof data !== 'undefined' )
|
|
1059
1064
|
}
|
|
1060
1065
|
|
|
@@ -1082,7 +1087,7 @@ function isNotUndefined ( data ) {
|
|
|
1082
1087
|
* @param data {*} The data to check against the array of undefined
|
|
1083
1088
|
* @returns {boolean} true if data is not an empty array where all values are undefined, false otherwise
|
|
1084
1089
|
*/
|
|
1085
|
-
function isArrayOfUndefined
|
|
1090
|
+
function isArrayOfUndefined( data ) {
|
|
1086
1091
|
|
|
1087
1092
|
if ( isNotArray( data ) ) { return false }
|
|
1088
1093
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -1103,7 +1108,7 @@ function isArrayOfUndefined ( data ) {
|
|
|
1103
1108
|
* @param data {*} The data to check against the array of undefined
|
|
1104
1109
|
* @returns {boolean} true if data is not an empty array where all values are defined, false otherwise
|
|
1105
1110
|
*/
|
|
1106
|
-
function isNotArrayOfUndefined
|
|
1111
|
+
function isNotArrayOfUndefined( data ) {
|
|
1107
1112
|
|
|
1108
1113
|
if ( isNotArray( data ) ) { return true }
|
|
1109
1114
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -1142,7 +1147,7 @@ function isNotArrayOfUndefined ( data ) {
|
|
|
1142
1147
|
* @param data {*} The data to check against true value
|
|
1143
1148
|
* @returns {boolean} true if data is a boolean set to true, false otherwise.
|
|
1144
1149
|
*/
|
|
1145
|
-
function isTrue
|
|
1150
|
+
function isTrue( data ) {
|
|
1146
1151
|
return ( isBoolean( data ) && ( data === true ) )
|
|
1147
1152
|
}
|
|
1148
1153
|
|
|
@@ -1152,7 +1157,7 @@ function isTrue ( data ) {
|
|
|
1152
1157
|
* @param data {*} The data to check against false value
|
|
1153
1158
|
* @returns {boolean} true if data is a boolean set to false, false otherwise.
|
|
1154
1159
|
*/
|
|
1155
|
-
function isFalse
|
|
1160
|
+
function isFalse( data ) {
|
|
1156
1161
|
return ( isBoolean( data ) && ( data === false ) )
|
|
1157
1162
|
}
|
|
1158
1163
|
|
|
@@ -1180,7 +1185,7 @@ function isFalse ( data ) {
|
|
|
1180
1185
|
* @param data {*} The data to check against the positive maximum state
|
|
1181
1186
|
* @returns {boolean} true if data is positive maximum, false otherwise
|
|
1182
1187
|
*/
|
|
1183
|
-
function isMaxPositive
|
|
1188
|
+
function isMaxPositive( data ) {
|
|
1184
1189
|
return ( data === Number.MAX_VALUE )
|
|
1185
1190
|
}
|
|
1186
1191
|
|
|
@@ -1190,7 +1195,7 @@ function isMaxPositive ( data ) {
|
|
|
1190
1195
|
* @param data {*} The data to check against the maximum infinite state
|
|
1191
1196
|
* @returns {boolean} true if data is negative maximum, false otherwise
|
|
1192
1197
|
*/
|
|
1193
|
-
function isMaxNegative
|
|
1198
|
+
function isMaxNegative( data ) {
|
|
1194
1199
|
return ( data === -Number.MAX_VALUE )
|
|
1195
1200
|
}
|
|
1196
1201
|
|
|
@@ -1218,7 +1223,7 @@ function isMaxNegative ( data ) {
|
|
|
1218
1223
|
* @param data {*} The data to check against the positive minimum state
|
|
1219
1224
|
* @returns {boolean} true if data is positive minimum, false otherwise
|
|
1220
1225
|
*/
|
|
1221
|
-
function isMinPositive
|
|
1226
|
+
function isMinPositive( data ) {
|
|
1222
1227
|
return ( data === Number.MIN_VALUE )
|
|
1223
1228
|
}
|
|
1224
1229
|
|
|
@@ -1228,7 +1233,7 @@ function isMinPositive ( data ) {
|
|
|
1228
1233
|
* @param data {*} The data to check against the minimum infinite state
|
|
1229
1234
|
* @returns {boolean} true if data is negative minimum, false otherwise
|
|
1230
1235
|
*/
|
|
1231
|
-
function isMinNegative
|
|
1236
|
+
function isMinNegative( data ) {
|
|
1232
1237
|
return ( data === -Number.MIN_VALUE )
|
|
1233
1238
|
}
|
|
1234
1239
|
|
|
@@ -1256,7 +1261,7 @@ function isMinNegative ( data ) {
|
|
|
1256
1261
|
* @param data {*} The data to check against the maximum safe integer state
|
|
1257
1262
|
* @returns {boolean} true if data is a maximum safe integer, false otherwise
|
|
1258
1263
|
*/
|
|
1259
|
-
function isMaxSafeInteger
|
|
1264
|
+
function isMaxSafeInteger( data ) {
|
|
1260
1265
|
return ( data === Number.MAX_SAFE_INTEGER )
|
|
1261
1266
|
}
|
|
1262
1267
|
|
|
@@ -1268,7 +1273,7 @@ function isMaxSafeInteger ( data ) {
|
|
|
1268
1273
|
* @param data {*} The data to check against the minimum safe integer state
|
|
1269
1274
|
* @returns {boolean} true if data is a minimum safe integer, false otherwise
|
|
1270
1275
|
*/
|
|
1271
|
-
function isMinSafeInteger
|
|
1276
|
+
function isMinSafeInteger( data ) {
|
|
1272
1277
|
return ( data === Number.MIN_SAFE_INTEGER )
|
|
1273
1278
|
}
|
|
1274
1279
|
|
|
@@ -1298,7 +1303,7 @@ function isMinSafeInteger ( data ) {
|
|
|
1298
1303
|
* @param data {*} The data to check against the emptiness of the object
|
|
1299
1304
|
* @returns {boolean} true if data is an empty object, false otherwise
|
|
1300
1305
|
*/
|
|
1301
|
-
function isEmptyObject
|
|
1306
|
+
function isEmptyObject( data ) {
|
|
1302
1307
|
|
|
1303
1308
|
if ( isNotObject( data ) ) { return false }
|
|
1304
1309
|
|
|
@@ -1323,7 +1328,7 @@ function isEmptyObject ( data ) {
|
|
|
1323
1328
|
* @param data {*} The data to check against the emptiness of the object
|
|
1324
1329
|
* @returns {boolean} true if data is not an empty object, false otherwise
|
|
1325
1330
|
*/
|
|
1326
|
-
function isNotEmptyObject
|
|
1331
|
+
function isNotEmptyObject( data ) {
|
|
1327
1332
|
return !( isEmptyObject( data ) )
|
|
1328
1333
|
}
|
|
1329
1334
|
|
|
@@ -1351,7 +1356,7 @@ function isNotEmptyObject ( data ) {
|
|
|
1351
1356
|
* @param data {*} The data to check against the emptiness of the string
|
|
1352
1357
|
* @returns {boolean} true if data is an empty string, false otherwise.
|
|
1353
1358
|
*/
|
|
1354
|
-
function isEmptyString
|
|
1359
|
+
function isEmptyString( data ) {
|
|
1355
1360
|
|
|
1356
1361
|
if ( isNotString( data ) ) {
|
|
1357
1362
|
return false
|
|
@@ -1367,7 +1372,7 @@ function isEmptyString ( data ) {
|
|
|
1367
1372
|
* @param data {*} The data to check against the emptiness of the string
|
|
1368
1373
|
* @returns {boolean} true if data is not an empty string, false otherwise.
|
|
1369
1374
|
*/
|
|
1370
|
-
function isNotEmptyString
|
|
1375
|
+
function isNotEmptyString( data ) {
|
|
1371
1376
|
|
|
1372
1377
|
return !( isEmptyString( data ) )
|
|
1373
1378
|
|
|
@@ -1397,7 +1402,7 @@ function isNotEmptyString ( data ) {
|
|
|
1397
1402
|
* @param data {*} The data to check against the blankness of the string
|
|
1398
1403
|
* @returns {boolean} true if data is a blank string, false otherwise.
|
|
1399
1404
|
*/
|
|
1400
|
-
function isBlankString
|
|
1405
|
+
function isBlankString( data ) {
|
|
1401
1406
|
|
|
1402
1407
|
if ( isNotString( data ) ) { return false }
|
|
1403
1408
|
if ( isEmptyString( data ) ) { return false }
|
|
@@ -1411,7 +1416,7 @@ function isBlankString ( data ) {
|
|
|
1411
1416
|
* @param data {*} The data to check against the blankness of the string
|
|
1412
1417
|
* @returns {boolean} true if data is not a blank string, false otherwise.
|
|
1413
1418
|
*/
|
|
1414
|
-
function isNotBlankString
|
|
1419
|
+
function isNotBlankString( data ) {
|
|
1415
1420
|
|
|
1416
1421
|
return !( isBlankString( data ) )
|
|
1417
1422
|
|
|
@@ -1441,7 +1446,7 @@ function isNotBlankString ( data ) {
|
|
|
1441
1446
|
* @param data {*} The data to check against the symbol type
|
|
1442
1447
|
* @returns {boolean} true if data is a symbol, false otherwise.
|
|
1443
1448
|
*/
|
|
1444
|
-
function isSymbol
|
|
1449
|
+
function isSymbol( data ) {
|
|
1445
1450
|
return ( typeof data === 'symbol' )
|
|
1446
1451
|
}
|
|
1447
1452
|
|
|
@@ -1451,7 +1456,7 @@ function isSymbol ( data ) {
|
|
|
1451
1456
|
* @param data {*} The data to check against the symbol type
|
|
1452
1457
|
* @returns {boolean} true if data is not a symbol, false otherwise.
|
|
1453
1458
|
*/
|
|
1454
|
-
function isNotSymbol
|
|
1459
|
+
function isNotSymbol( data ) {
|
|
1455
1460
|
return ( typeof data !== 'symbol' )
|
|
1456
1461
|
}
|
|
1457
1462
|
|
|
@@ -1481,7 +1486,7 @@ function isNotSymbol ( data ) {
|
|
|
1481
1486
|
* @param data {*} The data to check against the emptiness
|
|
1482
1487
|
* @returns {boolean} true if data is considered as empty, false otherwise.
|
|
1483
1488
|
*/
|
|
1484
|
-
function isEmpty
|
|
1489
|
+
function isEmpty( data ) {
|
|
1485
1490
|
|
|
1486
1491
|
if ( isNotDefined( data ) ) { return false }
|
|
1487
1492
|
if ( isEmptyString( data ) ) { return true}
|
|
@@ -1498,7 +1503,7 @@ function isEmpty ( data ) {
|
|
|
1498
1503
|
* @param data {*} The data to check against the emptiness
|
|
1499
1504
|
* @returns {boolean} true if data is considered as not empty, false otherwise.
|
|
1500
1505
|
*/
|
|
1501
|
-
function isNotEmpty
|
|
1506
|
+
function isNotEmpty( data ) {
|
|
1502
1507
|
return !isEmpty( data )
|
|
1503
1508
|
}
|
|
1504
1509
|
|
|
@@ -1516,121 +1521,121 @@ function isNotEmpty ( data ) {
|
|
|
1516
1521
|
// Usefull when a simple data structure is used multiple times
|
|
1517
1522
|
validator.add( 'ColorType', color => {
|
|
1518
1523
|
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1524
|
+
const r = color.r
|
|
1525
|
+
if ( color.r === undefined || Itee.Validators.isNotNumber( r ) ) {
|
|
1526
|
+
return false
|
|
1527
|
+
}
|
|
1523
1528
|
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1529
|
+
const g = color.g
|
|
1530
|
+
if ( color.g === undefined || Itee.Validators.isNotNumber( g ) ) {
|
|
1531
|
+
return false
|
|
1532
|
+
}
|
|
1528
1533
|
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1534
|
+
const b = color.b
|
|
1535
|
+
if ( color.b === undefined || Itee.Validators.isNotNumber( b ) ) {
|
|
1536
|
+
return false
|
|
1537
|
+
}
|
|
1533
1538
|
|
|
1534
|
-
|
|
1535
|
-
|
|
1539
|
+
return true
|
|
1540
|
+
} )
|
|
1536
1541
|
|
|
1537
1542
|
// Using schema composition
|
|
1538
1543
|
// Usefull for design validation schema faster and based on previous declared validation types
|
|
1539
1544
|
validator.add( 'Range_0_255', ( value ) => {
|
|
1540
1545
|
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1546
|
+
if ( Itee.Validators.isNotNumber( value ) ) {
|
|
1547
|
+
return false
|
|
1548
|
+
}
|
|
1544
1549
|
|
|
1545
|
-
|
|
1550
|
+
return !(value <= 0 || value > 255)
|
|
1546
1551
|
|
|
1547
|
-
|
|
1552
|
+
} )
|
|
1548
1553
|
|
|
1549
1554
|
validator.add( 'ColorSchema', {
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1555
|
+
r: {
|
|
1556
|
+
required: true,
|
|
1557
|
+
type: 'Range_0_255'
|
|
1558
|
+
},
|
|
1559
|
+
g: {
|
|
1560
|
+
required: true,
|
|
1561
|
+
type: 'Range_0_255'
|
|
1562
|
+
},
|
|
1563
|
+
b: {
|
|
1564
|
+
required: true,
|
|
1565
|
+
type: 'Range_0_255'
|
|
1566
|
+
}
|
|
1567
|
+
} )
|
|
1563
1568
|
|
|
1564
1569
|
validator.add( 'ColorStructure', {
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
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
|
-
|
|
1570
|
+
color_from_type: {
|
|
1571
|
+
type: 'ColorType'
|
|
1572
|
+
},
|
|
1573
|
+
col_from_schema: {
|
|
1574
|
+
type: 'ColorSchema'
|
|
1575
|
+
},
|
|
1576
|
+
col_from_fn: {
|
|
1577
|
+
// Inner function
|
|
1578
|
+
// Usefull for specific validation requirement that cannot match other previous validation schema or type
|
|
1579
|
+
fn: function ColorValidator ( color ) {
|
|
1580
|
+
|
|
1581
|
+
const r = color.r
|
|
1582
|
+
if ( color.r === undefined || Itee.Validators.isNotNumber( r ) ) {
|
|
1583
|
+
return false
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
const g = color.g
|
|
1587
|
+
if ( color.g === undefined || Itee.Validators.isNotNumber( g ) ) {
|
|
1588
|
+
return false
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
const b = color.b
|
|
1592
|
+
if ( color.b === undefined || Itee.Validators.isNotNumber( b ) ) {
|
|
1593
|
+
return false
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
return true
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
} )
|
|
1595
1600
|
|
|
1596
1601
|
// The data to validate
|
|
1597
1602
|
const colorStruct = {
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1603
|
+
color_from_type: {
|
|
1604
|
+
r: 0,
|
|
1605
|
+
g: 1,
|
|
1606
|
+
b: 2
|
|
1607
|
+
},
|
|
1608
|
+
col_from_schema: {
|
|
1609
|
+
r: 10,
|
|
1610
|
+
g: 20,
|
|
1611
|
+
b: 30
|
|
1612
|
+
},
|
|
1613
|
+
col_from_fn: {
|
|
1614
|
+
r: 0,
|
|
1615
|
+
g: 127,
|
|
1616
|
+
b: 255
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1614
1619
|
|
|
1615
1620
|
// Execute
|
|
1616
1621
|
|
|
1617
1622
|
try {
|
|
1618
1623
|
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
+
if ( validator.check( colorStruct, 'ColorStructure' ) ) {
|
|
1625
|
+
alert( 'ColorStructure is valid !' )
|
|
1626
|
+
} else {
|
|
1627
|
+
alert( validator.errors )
|
|
1628
|
+
}
|
|
1624
1629
|
|
|
1625
|
-
} catch ( err ) {
|
|
1626
|
-
|
|
1627
|
-
}
|
|
1630
|
+
} catch ( err ) {
|
|
1631
|
+
alert( err )
|
|
1632
|
+
}
|
|
1628
1633
|
*
|
|
1629
1634
|
*/
|
|
1630
1635
|
|
|
1631
1636
|
class Validator {
|
|
1632
1637
|
|
|
1633
|
-
constructor
|
|
1638
|
+
constructor() {
|
|
1634
1639
|
|
|
1635
1640
|
/**
|
|
1636
1641
|
* The validators store, by default it contains validators for Boolean, Number, Integer, Float, Array, String, Object, Symbol and Function
|
|
@@ -1664,7 +1669,7 @@ class Validator {
|
|
|
1664
1669
|
* @param type {string} - A string that represent the type of data to validate
|
|
1665
1670
|
* @param validator {(function|object)} - A function or validation schema that represent the type of data to validate
|
|
1666
1671
|
*/
|
|
1667
|
-
add
|
|
1672
|
+
add( type, validator ) {
|
|
1668
1673
|
|
|
1669
1674
|
if ( isNotString( type ) ) { throw new TypeError( `Validator: Expect type to be a string` ) }
|
|
1670
1675
|
if ( isNotFunction( validator ) && isNotObject( validator ) ) { throw new TypeError( `Validator: Expect validator to be an object or a function` ) }
|
|
@@ -1679,7 +1684,7 @@ class Validator {
|
|
|
1679
1684
|
*
|
|
1680
1685
|
* @param type {string} - The type to remove
|
|
1681
1686
|
*/
|
|
1682
|
-
remove
|
|
1687
|
+
remove( type ) {
|
|
1683
1688
|
|
|
1684
1689
|
delete this.validators[ type ];
|
|
1685
1690
|
|
|
@@ -1690,7 +1695,7 @@ class Validator {
|
|
|
1690
1695
|
*
|
|
1691
1696
|
* @return {Array.<string>} - The list of registered type
|
|
1692
1697
|
*/
|
|
1693
|
-
getAvalaibleTypes
|
|
1698
|
+
getAvalaibleTypes() {
|
|
1694
1699
|
|
|
1695
1700
|
const availablesTypes = [];
|
|
1696
1701
|
|
|
@@ -1710,7 +1715,7 @@ class Validator {
|
|
|
1710
1715
|
* @param breakOnError {boolean} - Return on first validation error ( true by default )
|
|
1711
1716
|
* @return {boolean} - Return true is the data is validated, false otherwise
|
|
1712
1717
|
*/
|
|
1713
|
-
check
|
|
1718
|
+
check( data, type, breakOnError = true ) {
|
|
1714
1719
|
|
|
1715
1720
|
const validator = this.validators[ type ];
|
|
1716
1721
|
if ( isNotDefined( validator ) ) {
|
|
@@ -1816,7 +1821,7 @@ if ( isNotDefined( validatorInstance ) ) {
|
|
|
1816
1821
|
* @param data {*} The data to check against the array buffer type
|
|
1817
1822
|
* @returns {boolean} true if data is a array buffer, false otherwise.
|
|
1818
1823
|
*/
|
|
1819
|
-
function isArrayBuffer
|
|
1824
|
+
function isArrayBuffer( data ) {
|
|
1820
1825
|
return ( data instanceof ArrayBuffer )
|
|
1821
1826
|
}
|
|
1822
1827
|
|
|
@@ -1826,7 +1831,7 @@ function isArrayBuffer ( data ) {
|
|
|
1826
1831
|
* @param data {*} The data to check against the array buffer type
|
|
1827
1832
|
* @returns {boolean} true if data is not a array buffer, false otherwise.
|
|
1828
1833
|
*/
|
|
1829
|
-
function isNotArrayBuffer
|
|
1834
|
+
function isNotArrayBuffer( data ) {
|
|
1830
1835
|
return !isArrayBuffer( data )
|
|
1831
1836
|
}
|
|
1832
1837
|
|
|
@@ -1854,7 +1859,7 @@ function isNotArrayBuffer ( data ) {
|
|
|
1854
1859
|
* @param data {*} The data to check against the big int 64 array type
|
|
1855
1860
|
* @returns {boolean} true if data is a big int 64 array, false otherwise.
|
|
1856
1861
|
*/
|
|
1857
|
-
function isBigInt64Array
|
|
1862
|
+
function isBigInt64Array( data ) {
|
|
1858
1863
|
return ( data instanceof BigInt64Array )
|
|
1859
1864
|
}
|
|
1860
1865
|
|
|
@@ -1864,7 +1869,7 @@ function isBigInt64Array ( data ) {
|
|
|
1864
1869
|
* @param data {*} The data to check against the big int 64 array type
|
|
1865
1870
|
* @returns {boolean} true if data is not a big int 64 array, false otherwise.
|
|
1866
1871
|
*/
|
|
1867
|
-
function isNotBigInt64Array
|
|
1872
|
+
function isNotBigInt64Array( data ) {
|
|
1868
1873
|
return !isBigInt64Array( data )
|
|
1869
1874
|
}
|
|
1870
1875
|
|
|
@@ -1892,7 +1897,7 @@ function isNotBigInt64Array ( data ) {
|
|
|
1892
1897
|
* @param data {*} The data to check against the big unsigned int 64 array type
|
|
1893
1898
|
* @returns {boolean} true if data is a big unsigned int 64 array, false otherwise.
|
|
1894
1899
|
*/
|
|
1895
|
-
function isBigUint64Array
|
|
1900
|
+
function isBigUint64Array( data ) {
|
|
1896
1901
|
return ( data instanceof BigUint64Array )
|
|
1897
1902
|
}
|
|
1898
1903
|
|
|
@@ -1902,7 +1907,7 @@ function isBigUint64Array ( data ) {
|
|
|
1902
1907
|
* @param data {*} The data to check against the big unsigned int 64 array type
|
|
1903
1908
|
* @returns {boolean} true if data is not a big unsigned int 64 array, false otherwise.
|
|
1904
1909
|
*/
|
|
1905
|
-
function isNotBigUint64Array
|
|
1910
|
+
function isNotBigUint64Array( data ) {
|
|
1906
1911
|
return !isBigUint64Array( data )
|
|
1907
1912
|
}
|
|
1908
1913
|
|
|
@@ -1930,7 +1935,7 @@ function isNotBigUint64Array ( data ) {
|
|
|
1930
1935
|
* @param data {*} The data to check against the float 32 array type
|
|
1931
1936
|
* @returns {boolean} true if data is a float 32 array , false otherwise.
|
|
1932
1937
|
*/
|
|
1933
|
-
function isFloat32Array
|
|
1938
|
+
function isFloat32Array( data ) {
|
|
1934
1939
|
return ( data instanceof Float32Array )
|
|
1935
1940
|
}
|
|
1936
1941
|
|
|
@@ -1940,7 +1945,7 @@ function isFloat32Array ( data ) {
|
|
|
1940
1945
|
* @param data {*} The data to check against the float 32 array type
|
|
1941
1946
|
* @returns {boolean} true if data is not a float 32 array , false otherwise.
|
|
1942
1947
|
*/
|
|
1943
|
-
function isNotFloat32Array
|
|
1948
|
+
function isNotFloat32Array( data ) {
|
|
1944
1949
|
return !isFloat32Array( data )
|
|
1945
1950
|
}
|
|
1946
1951
|
|
|
@@ -1968,7 +1973,7 @@ function isNotFloat32Array ( data ) {
|
|
|
1968
1973
|
* @param data {*} The data to check against the float 64 array type
|
|
1969
1974
|
* @returns {boolean} true if data is a float 64 array , false otherwise.
|
|
1970
1975
|
*/
|
|
1971
|
-
function isFloat64Array
|
|
1976
|
+
function isFloat64Array( data ) {
|
|
1972
1977
|
return ( data instanceof Float64Array )
|
|
1973
1978
|
}
|
|
1974
1979
|
|
|
@@ -1978,7 +1983,7 @@ function isFloat64Array ( data ) {
|
|
|
1978
1983
|
* @param data {*} The data to check against the float 64 array type
|
|
1979
1984
|
* @returns {boolean} true if data is not a float 64 array , false otherwise.
|
|
1980
1985
|
*/
|
|
1981
|
-
function isNotFloat64Array
|
|
1986
|
+
function isNotFloat64Array( data ) {
|
|
1982
1987
|
return !isFloat64Array( data )
|
|
1983
1988
|
}
|
|
1984
1989
|
|
|
@@ -2006,7 +2011,7 @@ function isNotFloat64Array ( data ) {
|
|
|
2006
2011
|
* @param data {*} The data to check against the int 16 array type
|
|
2007
2012
|
* @returns {boolean} true if data is a int 16 array , false otherwise.
|
|
2008
2013
|
*/
|
|
2009
|
-
function isInt16Array
|
|
2014
|
+
function isInt16Array( data ) {
|
|
2010
2015
|
return ( data instanceof Int16Array )
|
|
2011
2016
|
}
|
|
2012
2017
|
|
|
@@ -2016,7 +2021,7 @@ function isInt16Array ( data ) {
|
|
|
2016
2021
|
* @param data {*} The data to check against the int 16 array type
|
|
2017
2022
|
* @returns {boolean} true if data is not a int 16 array , false otherwise.
|
|
2018
2023
|
*/
|
|
2019
|
-
function isNotInt16Array
|
|
2024
|
+
function isNotInt16Array( data ) {
|
|
2020
2025
|
return !isInt16Array( data )
|
|
2021
2026
|
}
|
|
2022
2027
|
|
|
@@ -2044,7 +2049,7 @@ function isNotInt16Array ( data ) {
|
|
|
2044
2049
|
* @param data {*} The data to check against the int 32 array type
|
|
2045
2050
|
* @returns {boolean} true if data is a int 32 array , false otherwise.
|
|
2046
2051
|
*/
|
|
2047
|
-
function isInt32Array
|
|
2052
|
+
function isInt32Array( data ) {
|
|
2048
2053
|
return ( data instanceof Int32Array )
|
|
2049
2054
|
}
|
|
2050
2055
|
|
|
@@ -2054,7 +2059,7 @@ function isInt32Array ( data ) {
|
|
|
2054
2059
|
* @param data {*} The data to check against the int 32 array type
|
|
2055
2060
|
* @returns {boolean} true if data is not a int 32 array , false otherwise.
|
|
2056
2061
|
*/
|
|
2057
|
-
function isNotInt32Array
|
|
2062
|
+
function isNotInt32Array( data ) {
|
|
2058
2063
|
return !isInt32Array( data )
|
|
2059
2064
|
}
|
|
2060
2065
|
|
|
@@ -2082,7 +2087,7 @@ function isNotInt32Array ( data ) {
|
|
|
2082
2087
|
* @param data {*} The data to check against the int 8 array type
|
|
2083
2088
|
* @returns {boolean} true if data is a int 8 array , false otherwise.
|
|
2084
2089
|
*/
|
|
2085
|
-
function isInt8Array
|
|
2090
|
+
function isInt8Array( data ) {
|
|
2086
2091
|
return ( data instanceof Int8Array )
|
|
2087
2092
|
}
|
|
2088
2093
|
|
|
@@ -2092,7 +2097,7 @@ function isInt8Array ( data ) {
|
|
|
2092
2097
|
* @param data {*} The data to check against the int 8 array type
|
|
2093
2098
|
* @returns {boolean} true if data is not a int 8 array , false otherwise.
|
|
2094
2099
|
*/
|
|
2095
|
-
function isNotInt8Array
|
|
2100
|
+
function isNotInt8Array( data ) {
|
|
2096
2101
|
return !isInt8Array( data )
|
|
2097
2102
|
}
|
|
2098
2103
|
|
|
@@ -2120,7 +2125,7 @@ function isNotInt8Array ( data ) {
|
|
|
2120
2125
|
* @param data {*} The data to check against the unsigned int 16 array type
|
|
2121
2126
|
* @returns {boolean} true if data is a unsigned int 16 array , false otherwise.
|
|
2122
2127
|
*/
|
|
2123
|
-
function isUint16Array
|
|
2128
|
+
function isUint16Array( data ) {
|
|
2124
2129
|
return ( data instanceof Uint16Array )
|
|
2125
2130
|
}
|
|
2126
2131
|
|
|
@@ -2130,7 +2135,7 @@ function isUint16Array ( data ) {
|
|
|
2130
2135
|
* @param data {*} The data to check against the unsigned int 16 array type
|
|
2131
2136
|
* @returns {boolean} true if data is not a unsigned int 16 array , false otherwise.
|
|
2132
2137
|
*/
|
|
2133
|
-
function isNotUint16Array
|
|
2138
|
+
function isNotUint16Array( data ) {
|
|
2134
2139
|
return !isUint16Array( data )
|
|
2135
2140
|
}
|
|
2136
2141
|
|
|
@@ -2158,7 +2163,7 @@ function isNotUint16Array ( data ) {
|
|
|
2158
2163
|
* @param data {*} The data to check against the unsigned int 32 array type
|
|
2159
2164
|
* @returns {boolean} true if data is a unsigned int 32 array , false otherwise.
|
|
2160
2165
|
*/
|
|
2161
|
-
function isUint32Array
|
|
2166
|
+
function isUint32Array( data ) {
|
|
2162
2167
|
return ( data instanceof Uint32Array )
|
|
2163
2168
|
}
|
|
2164
2169
|
|
|
@@ -2168,7 +2173,7 @@ function isUint32Array ( data ) {
|
|
|
2168
2173
|
* @param data {*} The data to check against the unsigned int 32 array type
|
|
2169
2174
|
* @returns {boolean} true if data is not a unsigned int 32 array , false otherwise.
|
|
2170
2175
|
*/
|
|
2171
|
-
function isNotUint32Array
|
|
2176
|
+
function isNotUint32Array( data ) {
|
|
2172
2177
|
return !isUint32Array( data )
|
|
2173
2178
|
}
|
|
2174
2179
|
|
|
@@ -2196,7 +2201,7 @@ function isNotUint32Array ( data ) {
|
|
|
2196
2201
|
* @param data {*} The data to check against the unsigned int 8 array type
|
|
2197
2202
|
* @returns {boolean} true if data is a unsigned int 8 array , false otherwise.
|
|
2198
2203
|
*/
|
|
2199
|
-
function isUint8Array
|
|
2204
|
+
function isUint8Array( data ) {
|
|
2200
2205
|
return ( data instanceof Uint8Array )
|
|
2201
2206
|
}
|
|
2202
2207
|
|
|
@@ -2206,7 +2211,7 @@ function isUint8Array ( data ) {
|
|
|
2206
2211
|
* @param data {*} The data to check against the unsigned int 8 array type
|
|
2207
2212
|
* @returns {boolean} true if data is not a unsigned int 8 array , false otherwise.
|
|
2208
2213
|
*/
|
|
2209
|
-
function isNotUint8Array
|
|
2214
|
+
function isNotUint8Array( data ) {
|
|
2210
2215
|
return !isUint8Array( data )
|
|
2211
2216
|
}
|
|
2212
2217
|
|
|
@@ -2234,7 +2239,7 @@ function isNotUint8Array ( data ) {
|
|
|
2234
2239
|
* @param data {*} The data to check against the unsigned clamped int 8 array type
|
|
2235
2240
|
* @returns {boolean} true if data is a unsigned clamped int 8 array , false otherwise.
|
|
2236
2241
|
*/
|
|
2237
|
-
function isUint8ClampedArray
|
|
2242
|
+
function isUint8ClampedArray( data ) {
|
|
2238
2243
|
return ( data instanceof Uint8ClampedArray )
|
|
2239
2244
|
}
|
|
2240
2245
|
|
|
@@ -2244,7 +2249,7 @@ function isUint8ClampedArray ( data ) {
|
|
|
2244
2249
|
* @param data {*} The data to check against the unsigned clamped int 8 array type
|
|
2245
2250
|
* @returns {boolean} true if data is not a unsigned clamped int 8 array , false otherwise.
|
|
2246
2251
|
*/
|
|
2247
|
-
function isNotUint8ClampedArray
|
|
2252
|
+
function isNotUint8ClampedArray( data ) {
|
|
2248
2253
|
return !isUint8ClampedArray( data )
|
|
2249
2254
|
}
|
|
2250
2255
|
|
|
@@ -2304,7 +2309,7 @@ const ABSOLUTE_ZERO_FAHRENHEIT = -459.67;
|
|
|
2304
2309
|
* @param data {*}
|
|
2305
2310
|
* @return {boolean}
|
|
2306
2311
|
*/
|
|
2307
|
-
function isCelsius
|
|
2312
|
+
function isCelsius( data ) {
|
|
2308
2313
|
return ( isNumber( data ) && data >= ABSOLUTE_ZERO_CELSIUS )
|
|
2309
2314
|
}
|
|
2310
2315
|
|
|
@@ -2313,7 +2318,7 @@ function isCelsius ( data ) {
|
|
|
2313
2318
|
* @param data {*}
|
|
2314
2319
|
* @return {boolean}
|
|
2315
2320
|
*/
|
|
2316
|
-
function isNotCelsius
|
|
2321
|
+
function isNotCelsius( data ) {
|
|
2317
2322
|
return !isCelsius( data )
|
|
2318
2323
|
}
|
|
2319
2324
|
|
|
@@ -2340,7 +2345,7 @@ function isNotCelsius ( data ) {
|
|
|
2340
2345
|
* @param data {*}
|
|
2341
2346
|
* @return {boolean}
|
|
2342
2347
|
*/
|
|
2343
|
-
function isFahrenheit
|
|
2348
|
+
function isFahrenheit( data ) {
|
|
2344
2349
|
return ( isNumber( data ) && data >= ABSOLUTE_ZERO_FAHRENHEIT )
|
|
2345
2350
|
}
|
|
2346
2351
|
|
|
@@ -2349,7 +2354,7 @@ function isFahrenheit ( data ) {
|
|
|
2349
2354
|
* @param data {*}
|
|
2350
2355
|
* @return {boolean}
|
|
2351
2356
|
*/
|
|
2352
|
-
function isNotFahrenheit
|
|
2357
|
+
function isNotFahrenheit( data ) {
|
|
2353
2358
|
return !isFahrenheit( data )
|
|
2354
2359
|
}
|
|
2355
2360
|
|
|
@@ -2376,7 +2381,7 @@ function isNotFahrenheit ( data ) {
|
|
|
2376
2381
|
* @param data {*}
|
|
2377
2382
|
* @return {boolean}
|
|
2378
2383
|
*/
|
|
2379
|
-
function isKelvin
|
|
2384
|
+
function isKelvin( data ) {
|
|
2380
2385
|
return ( isNumber( data ) && data >= ABSOLUTE_ZERO_KELVIN )
|
|
2381
2386
|
}
|
|
2382
2387
|
|
|
@@ -2385,7 +2390,7 @@ function isKelvin ( data ) {
|
|
|
2385
2390
|
* @param data {*}
|
|
2386
2391
|
* @return {boolean}
|
|
2387
2392
|
*/
|
|
2388
|
-
function isNotKelvin
|
|
2393
|
+
function isNotKelvin( data ) {
|
|
2389
2394
|
return !isKelvin( data )
|
|
2390
2395
|
}
|
|
2391
2396
|
|
|
@@ -2412,7 +2417,7 @@ function isNotKelvin ( data ) {
|
|
|
2412
2417
|
* @param data {*}
|
|
2413
2418
|
* @return {boolean}
|
|
2414
2419
|
*/
|
|
2415
|
-
function isTemperature
|
|
2420
|
+
function isTemperature( data ) {
|
|
2416
2421
|
return ( isKelvin( data ) || isCelsius( data ) || isFahrenheit( data ) )
|
|
2417
2422
|
}
|
|
2418
2423
|
|
|
@@ -2421,7 +2426,7 @@ function isTemperature ( data ) {
|
|
|
2421
2426
|
* @param data {*}
|
|
2422
2427
|
* @return {boolean}
|
|
2423
2428
|
*/
|
|
2424
|
-
function isNotTemperature
|
|
2429
|
+
function isNotTemperature( data ) {
|
|
2425
2430
|
return ( isNotKelvin( data ) && isNotCelsius( data ) && isNotFahrenheit( data ) )
|
|
2426
2431
|
}
|
|
2427
2432
|
|