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,14 +1,19 @@
|
|
|
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
|
'use strict';
|
|
3
12
|
|
|
4
13
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
14
|
|
|
6
15
|
var fs = require('fs');
|
|
7
16
|
|
|
8
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
-
|
|
10
|
-
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
11
|
-
|
|
12
17
|
/**
|
|
13
18
|
* @author [Tristan Valcke]{@link https://github.com/Itee}
|
|
14
19
|
* @license [BSD-3-Clause]{@link https://opensource.org/licenses/BSD-3-Clause}
|
|
@@ -33,7 +38,7 @@ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
|
33
38
|
* @param data {*} The data to check against the array type
|
|
34
39
|
* @returns {boolean} true if data is array, false otherwise
|
|
35
40
|
*/
|
|
36
|
-
function isArray
|
|
41
|
+
function isArray( data ) {
|
|
37
42
|
return Array.isArray( data )
|
|
38
43
|
}
|
|
39
44
|
|
|
@@ -43,7 +48,7 @@ function isArray ( data ) {
|
|
|
43
48
|
* @param data {*} The data to check against the array type
|
|
44
49
|
* @returns {boolean} true if data is not array, false otherwise
|
|
45
50
|
*/
|
|
46
|
-
function isNotArray
|
|
51
|
+
function isNotArray( data ) {
|
|
47
52
|
return !Array.isArray( data )
|
|
48
53
|
}
|
|
49
54
|
|
|
@@ -71,7 +76,7 @@ function isNotArray ( data ) {
|
|
|
71
76
|
* @param data {*} The data to check against the empty array
|
|
72
77
|
* @returns {boolean} true if data is an empty array, false otherwise
|
|
73
78
|
*/
|
|
74
|
-
function isEmptyArray
|
|
79
|
+
function isEmptyArray( data ) {
|
|
75
80
|
|
|
76
81
|
if ( isNotArray( data ) ) { return false }
|
|
77
82
|
|
|
@@ -85,7 +90,7 @@ function isEmptyArray ( data ) {
|
|
|
85
90
|
* @param data {*} The data to check against the empty array
|
|
86
91
|
* @returns {boolean} true if data is not an empty array, false otherwise
|
|
87
92
|
*/
|
|
88
|
-
function isNotEmptyArray
|
|
93
|
+
function isNotEmptyArray( data ) {
|
|
89
94
|
|
|
90
95
|
if ( isNotArray( data ) ) { return true }
|
|
91
96
|
|
|
@@ -117,7 +122,7 @@ function isNotEmptyArray ( data ) {
|
|
|
117
122
|
* @param data {*} The data to check against the array of array type
|
|
118
123
|
* @returns {boolean} true if data is an array of array, false otherwise
|
|
119
124
|
*/
|
|
120
|
-
function isArrayOfArray
|
|
125
|
+
function isArrayOfArray( data ) {
|
|
121
126
|
|
|
122
127
|
if ( isNotArray( data ) ) { return false }
|
|
123
128
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -138,7 +143,7 @@ function isArrayOfArray ( data ) {
|
|
|
138
143
|
* @param data {*} The data to check against the array of array type
|
|
139
144
|
* @returns {boolean} true if data is not an array of array, false otherwise
|
|
140
145
|
*/
|
|
141
|
-
function isNotArrayOfArray
|
|
146
|
+
function isNotArrayOfArray( data ) {
|
|
142
147
|
|
|
143
148
|
if ( isNotArray( data ) ) { return true }
|
|
144
149
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -177,7 +182,7 @@ function isNotArrayOfArray ( data ) {
|
|
|
177
182
|
* @param data {*} The data to check against the booleaness
|
|
178
183
|
* @returns {boolean} true if data is a boolean, false otherwise.
|
|
179
184
|
*/
|
|
180
|
-
function isBoolean
|
|
185
|
+
function isBoolean( data ) {
|
|
181
186
|
return ( typeof data === 'boolean' )
|
|
182
187
|
}
|
|
183
188
|
|
|
@@ -187,7 +192,7 @@ function isBoolean ( data ) {
|
|
|
187
192
|
* @param data {*} The data to check against the booleaness
|
|
188
193
|
* @returns {boolean} true if data is not a boolean, false otherwise.
|
|
189
194
|
*/
|
|
190
|
-
function isNotBoolean
|
|
195
|
+
function isNotBoolean( data ) {
|
|
191
196
|
return ( typeof data !== 'boolean' )
|
|
192
197
|
}
|
|
193
198
|
|
|
@@ -215,7 +220,7 @@ function isNotBoolean ( data ) {
|
|
|
215
220
|
* @param data {*} The data to check against the array of booleans
|
|
216
221
|
* @returns {boolean} true if data is not an empty array where all values are boolean, false otherwise
|
|
217
222
|
*/
|
|
218
|
-
function isArrayOfBoolean
|
|
223
|
+
function isArrayOfBoolean( data ) {
|
|
219
224
|
|
|
220
225
|
if ( isNotArray( data ) ) { return false }
|
|
221
226
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -236,7 +241,7 @@ function isArrayOfBoolean ( data ) {
|
|
|
236
241
|
* @param data {*} The data to check against the array of booleans
|
|
237
242
|
* @returns {boolean} true if data is not an empty array where all values are not boolean, false otherwise
|
|
238
243
|
*/
|
|
239
|
-
function isNotArrayOfBoolean
|
|
244
|
+
function isNotArrayOfBoolean( data ) {
|
|
240
245
|
|
|
241
246
|
if ( isNotArray( data ) ) { return true }
|
|
242
247
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -275,7 +280,7 @@ function isNotArrayOfBoolean ( data ) {
|
|
|
275
280
|
* @param data {*} The data to check against the functionality
|
|
276
281
|
* @returns {boolean} true if data is a function, false otherwise.
|
|
277
282
|
*/
|
|
278
|
-
function isFunction
|
|
283
|
+
function isFunction( data ) {
|
|
279
284
|
return ( typeof data === 'function' )
|
|
280
285
|
}
|
|
281
286
|
|
|
@@ -285,7 +290,7 @@ function isFunction ( data ) {
|
|
|
285
290
|
* @param data {*} The data to check against the functionality
|
|
286
291
|
* @returns {boolean} true if data is not a function, false otherwise.
|
|
287
292
|
*/
|
|
288
|
-
function isNotFunction
|
|
293
|
+
function isNotFunction( data ) {
|
|
289
294
|
return ( typeof data !== 'function' )
|
|
290
295
|
}
|
|
291
296
|
|
|
@@ -313,7 +318,7 @@ function isNotFunction ( data ) {
|
|
|
313
318
|
* @param data {*} The data to check against the array of functions
|
|
314
319
|
* @returns {boolean} true if data is not an empty array where all values are functions, false otherwise
|
|
315
320
|
*/
|
|
316
|
-
function isArrayOfFunction
|
|
321
|
+
function isArrayOfFunction( data ) {
|
|
317
322
|
|
|
318
323
|
if ( isNotArray( data ) ) { return false }
|
|
319
324
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -334,7 +339,7 @@ function isArrayOfFunction ( data ) {
|
|
|
334
339
|
* @param data {*} The data to check against the array of functions
|
|
335
340
|
* @returns {boolean} true if data is not an empty array where all values are not functions, false otherwise
|
|
336
341
|
*/
|
|
337
|
-
function isNotArrayOfFunction
|
|
342
|
+
function isNotArrayOfFunction( data ) {
|
|
338
343
|
|
|
339
344
|
if ( isNotArray( data ) ) { return true }
|
|
340
345
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -373,7 +378,7 @@ function isNotArrayOfFunction ( data ) {
|
|
|
373
378
|
* @param data {*} The data to check against the single valued array
|
|
374
379
|
* @returns {boolean} true if data is an array with multiples values, false otherwise
|
|
375
380
|
*/
|
|
376
|
-
function isArrayOfMultiElement
|
|
381
|
+
function isArrayOfMultiElement( data ) {
|
|
377
382
|
|
|
378
383
|
if ( isNotArray( data ) ) { return false }
|
|
379
384
|
|
|
@@ -405,7 +410,7 @@ function isArrayOfMultiElement ( data ) {
|
|
|
405
410
|
* @param data {*} The data to check against the nullity
|
|
406
411
|
* @returns {boolean} true if data is null, false otherwise.
|
|
407
412
|
*/
|
|
408
|
-
function isNull
|
|
413
|
+
function isNull( data ) {
|
|
409
414
|
return ( data === null )
|
|
410
415
|
}
|
|
411
416
|
|
|
@@ -417,7 +422,7 @@ function isNull ( data ) {
|
|
|
417
422
|
* @param data {*} The data to check against the nullity
|
|
418
423
|
* @returns {boolean} true if data is not null, false otherwise.
|
|
419
424
|
*/
|
|
420
|
-
function isNotNull
|
|
425
|
+
function isNotNull( data ) {
|
|
421
426
|
return ( data !== null )
|
|
422
427
|
}
|
|
423
428
|
|
|
@@ -444,7 +449,7 @@ function isNotNull ( data ) {
|
|
|
444
449
|
* @param data {*} The data to check against the array of null type
|
|
445
450
|
* @returns {boolean} true if data is not an empty array where all values are null, false otherwise
|
|
446
451
|
*/
|
|
447
|
-
function isArrayOfNull
|
|
452
|
+
function isArrayOfNull( data ) {
|
|
448
453
|
|
|
449
454
|
if ( isNotArray( data ) ) { return false }
|
|
450
455
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -465,7 +470,7 @@ function isArrayOfNull ( data ) {
|
|
|
465
470
|
* @param data {*} The data to check against the array of null type
|
|
466
471
|
* @returns {boolean} true if data is not an empty array where all values are not null, false otherwise
|
|
467
472
|
*/
|
|
468
|
-
function isNotArrayOfNull
|
|
473
|
+
function isNotArrayOfNull( data ) {
|
|
469
474
|
|
|
470
475
|
if ( isNotArray( data ) ) { return true }
|
|
471
476
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -504,7 +509,7 @@ function isNotArrayOfNull ( data ) {
|
|
|
504
509
|
* @param data {*} The data to check against the existence
|
|
505
510
|
* @returns {boolean} true if data is not null and not undefined, false otherwise.
|
|
506
511
|
*/
|
|
507
|
-
function isDefined
|
|
512
|
+
function isDefined( data ) {
|
|
508
513
|
return ( ( data !== null ) && ( typeof data !== 'undefined' ) )
|
|
509
514
|
}
|
|
510
515
|
|
|
@@ -514,7 +519,7 @@ function isDefined ( data ) {
|
|
|
514
519
|
* @param data {*} The data to check against the existence
|
|
515
520
|
* @returns {boolean} true if data is null or undefined, false otherwise.
|
|
516
521
|
*/
|
|
517
|
-
function isNotDefined
|
|
522
|
+
function isNotDefined( data ) {
|
|
518
523
|
return ( ( data === null ) || ( typeof data === 'undefined' ) )
|
|
519
524
|
}
|
|
520
525
|
|
|
@@ -536,20 +541,6 @@ function isNotDefined ( data ) {
|
|
|
536
541
|
*
|
|
537
542
|
*/
|
|
538
543
|
|
|
539
|
-
/**
|
|
540
|
-
* Check if the given data is an infinite number
|
|
541
|
-
*
|
|
542
|
-
* @param data {*} The data to check against the infinite state
|
|
543
|
-
* @returns {boolean} true if data is infinite, false otherwise
|
|
544
|
-
*/
|
|
545
|
-
function isInfinite ( data ) {
|
|
546
|
-
|
|
547
|
-
// Todo: is required to check notnumber ?
|
|
548
|
-
if ( isNotNumber( data ) ) { return false }
|
|
549
|
-
if ( Number.isNaN( data ) ) { return false }
|
|
550
|
-
|
|
551
|
-
return !Number.isFinite( data )
|
|
552
|
-
}
|
|
553
544
|
|
|
554
545
|
/**
|
|
555
546
|
* Check if the given data is an infinite negative number
|
|
@@ -557,7 +548,7 @@ function isInfinite ( data ) {
|
|
|
557
548
|
* @param data {*} The data to check against the negative infinite state
|
|
558
549
|
* @returns {boolean} true if data is negative infinite, false otherwise
|
|
559
550
|
*/
|
|
560
|
-
function isInfiniteNegative
|
|
551
|
+
function isInfiniteNegative( data ) {
|
|
561
552
|
return ( data === Number.NEGATIVE_INFINITY )
|
|
562
553
|
}
|
|
563
554
|
|
|
@@ -567,17 +558,27 @@ function isInfiniteNegative ( data ) {
|
|
|
567
558
|
* @param data {*} The data to check against the positive infinite state
|
|
568
559
|
* @returns {boolean} true if data is positive infinite, false otherwise
|
|
569
560
|
*/
|
|
570
|
-
function isInfinitePositive
|
|
561
|
+
function isInfinitePositive( data ) {
|
|
571
562
|
return ( data === Number.POSITIVE_INFINITY )
|
|
572
563
|
}
|
|
573
564
|
|
|
565
|
+
/**
|
|
566
|
+
* Check if the given data is an infinite number
|
|
567
|
+
*
|
|
568
|
+
* @param data {*} The data to check against the infinite state
|
|
569
|
+
* @returns {boolean} true if data is infinite, false otherwise
|
|
570
|
+
*/
|
|
571
|
+
function isInfinite( data ) {
|
|
572
|
+
return isInfiniteNegative( data ) || isInfinitePositive( data )
|
|
573
|
+
}
|
|
574
|
+
|
|
574
575
|
/**
|
|
575
576
|
* Check if the given data is a finite number
|
|
576
577
|
*
|
|
577
578
|
* @param data {*} The data to check against the finite state
|
|
578
579
|
* @returns {boolean} true if data is finite, false otherwise
|
|
579
580
|
*/
|
|
580
|
-
function isFinite
|
|
581
|
+
function isFinite( data ) {
|
|
581
582
|
return Number.isFinite( data )
|
|
582
583
|
}
|
|
583
584
|
|
|
@@ -607,7 +608,7 @@ function isFinite ( data ) {
|
|
|
607
608
|
* @param data {*} The data to check against the zero value
|
|
608
609
|
* @returns {boolean} true if data is zero, false otherwise
|
|
609
610
|
*/
|
|
610
|
-
function isZero
|
|
611
|
+
function isZero( data ) {
|
|
611
612
|
//Todo protect truthy values
|
|
612
613
|
return ( data === 0 )
|
|
613
614
|
}
|
|
@@ -618,7 +619,7 @@ function isZero ( data ) {
|
|
|
618
619
|
* @param data {*} The data to check against the positive zero value
|
|
619
620
|
* @returns {boolean} true if data is a positive zero, false otherwise
|
|
620
621
|
*/
|
|
621
|
-
function isZeroPositive
|
|
622
|
+
function isZeroPositive( data ) {
|
|
622
623
|
return ( data === 0 && ( 1 / data ) === Number.POSITIVE_INFINITY )
|
|
623
624
|
}
|
|
624
625
|
|
|
@@ -628,7 +629,7 @@ function isZeroPositive ( data ) {
|
|
|
628
629
|
* @param data {*} The data to check against the negative zero value
|
|
629
630
|
* @returns {boolean} true if data is a negative zero, false otherwise
|
|
630
631
|
*/
|
|
631
|
-
function isZeroNegative
|
|
632
|
+
function isZeroNegative( data ) {
|
|
632
633
|
return ( data === 0 && ( 1 / data ) === Number.NEGATIVE_INFINITY )
|
|
633
634
|
}
|
|
634
635
|
|
|
@@ -656,7 +657,7 @@ function isZeroNegative ( data ) {
|
|
|
656
657
|
* @param data {*} The data to check against the maximum safe integer state
|
|
657
658
|
* @returns {boolean} true if data is a number, false otherwise.
|
|
658
659
|
*/
|
|
659
|
-
function isNumber
|
|
660
|
+
function isNumber( data ) {
|
|
660
661
|
|
|
661
662
|
if ( isNotDefined( data ) ) { return false }
|
|
662
663
|
|
|
@@ -670,7 +671,7 @@ function isNumber ( data ) {
|
|
|
670
671
|
* @param data {*} The data to check against the positivity
|
|
671
672
|
* @returns {boolean} true if data is a positive number, false otherwise.
|
|
672
673
|
*/
|
|
673
|
-
function isNumberPositive
|
|
674
|
+
function isNumberPositive( data ) {
|
|
674
675
|
|
|
675
676
|
if ( isNotNumber( data ) ) { return false }
|
|
676
677
|
|
|
@@ -685,7 +686,7 @@ function isNumberPositive ( data ) {
|
|
|
685
686
|
* @param data {*} The data to check against the negativity
|
|
686
687
|
* @returns {boolean} true if data is a negative number, false otherwise.
|
|
687
688
|
*/
|
|
688
|
-
function isNumberNegative
|
|
689
|
+
function isNumberNegative( data ) {
|
|
689
690
|
return ( isNumber( data ) && data < 0 )
|
|
690
691
|
}
|
|
691
692
|
|
|
@@ -695,7 +696,7 @@ function isNumberNegative ( data ) {
|
|
|
695
696
|
* @param data {*} The data to check against the number type
|
|
696
697
|
* @returns {boolean} true if data is not of type number or not a number, false otherwise.
|
|
697
698
|
*/
|
|
698
|
-
function isNotNumber
|
|
699
|
+
function isNotNumber( data ) {
|
|
699
700
|
return !( isNumber( data ) )
|
|
700
701
|
}
|
|
701
702
|
|
|
@@ -705,7 +706,7 @@ function isNotNumber ( data ) {
|
|
|
705
706
|
* @param data {*} The data to check against the integer state
|
|
706
707
|
* @returns {boolean} true if data is an integer, false otherwise
|
|
707
708
|
*/
|
|
708
|
-
function isInteger
|
|
709
|
+
function isInteger( data ) {
|
|
709
710
|
return Number.isInteger( data )
|
|
710
711
|
}
|
|
711
712
|
|
|
@@ -715,7 +716,7 @@ function isInteger ( data ) {
|
|
|
715
716
|
* @param data {*} The data to check against the floating point
|
|
716
717
|
* @returns {boolean} true if data is a float, false otherwise
|
|
717
718
|
*/
|
|
718
|
-
function isFloat
|
|
719
|
+
function isFloat( data ) {
|
|
719
720
|
|
|
720
721
|
if ( isNotNumber( data ) ) { return false }
|
|
721
722
|
if ( Number.isNaN( data ) ) { return false }
|
|
@@ -731,7 +732,7 @@ function isFloat ( data ) {
|
|
|
731
732
|
* @param data {*} The data to check against the NaN state
|
|
732
733
|
* @returns {boolean} true if data is not a number, false otherwise.
|
|
733
734
|
*/
|
|
734
|
-
function isNaN
|
|
735
|
+
function isNaN( data ) {
|
|
735
736
|
return Number.isNaN( data )
|
|
736
737
|
}
|
|
737
738
|
|
|
@@ -759,7 +760,7 @@ function isNaN ( data ) {
|
|
|
759
760
|
* @param data {*} The data to check against the array of numbers
|
|
760
761
|
* @returns {boolean} true if data is not an empty array where all values are numbers, false otherwise
|
|
761
762
|
*/
|
|
762
|
-
function isArrayOfNumber
|
|
763
|
+
function isArrayOfNumber( data ) {
|
|
763
764
|
|
|
764
765
|
if ( isNotArray( data ) ) { return false }
|
|
765
766
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -780,7 +781,7 @@ function isArrayOfNumber ( data ) {
|
|
|
780
781
|
* @param data {*} The data to check against the array of numbers
|
|
781
782
|
* @returns {boolean} true if data is not an empty array where all values are not numbers, false otherwise
|
|
782
783
|
*/
|
|
783
|
-
function isNotArrayOfNumber
|
|
784
|
+
function isNotArrayOfNumber( data ) {
|
|
784
785
|
|
|
785
786
|
if ( isNotArray( data ) ) { return true }
|
|
786
787
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -819,7 +820,7 @@ function isNotArrayOfNumber ( data ) {
|
|
|
819
820
|
* @param data {*} The data to check against the object type
|
|
820
821
|
* @returns {boolean} true if data is object, false otherwise
|
|
821
822
|
*/
|
|
822
|
-
function isObject
|
|
823
|
+
function isObject( data ) {
|
|
823
824
|
|
|
824
825
|
if ( isNotDefined( data ) ) { return false }
|
|
825
826
|
|
|
@@ -832,7 +833,7 @@ function isObject ( data ) {
|
|
|
832
833
|
* @param data {*} The data to check against the object type
|
|
833
834
|
* @returns {boolean} true if data is not an object, false otherwise
|
|
834
835
|
*/
|
|
835
|
-
function isNotObject
|
|
836
|
+
function isNotObject( data ) {
|
|
836
837
|
return !isObject( data )
|
|
837
838
|
}
|
|
838
839
|
|
|
@@ -860,7 +861,7 @@ function isNotObject ( data ) {
|
|
|
860
861
|
* @param data {*} The data to check against the array of object type
|
|
861
862
|
* @returns {boolean} true if data is an array where all values are of object type, false otherwise
|
|
862
863
|
*/
|
|
863
|
-
function isArrayOfObject
|
|
864
|
+
function isArrayOfObject( data ) {
|
|
864
865
|
|
|
865
866
|
if ( isNotArray( data ) ) { return false }
|
|
866
867
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -881,7 +882,7 @@ function isArrayOfObject ( data ) {
|
|
|
881
882
|
* @param data {*} The data to check against the array of object type
|
|
882
883
|
* @returns {boolean} true if data is not an array where all values are of object type, false otherwise
|
|
883
884
|
*/
|
|
884
|
-
function isNotArrayOfObject
|
|
885
|
+
function isNotArrayOfObject( data ) {
|
|
885
886
|
|
|
886
887
|
if ( isNotArray( data ) ) { return true }
|
|
887
888
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -920,7 +921,7 @@ function isNotArrayOfObject ( data ) {
|
|
|
920
921
|
* @param data {*} The data to check against the single valued array
|
|
921
922
|
* @returns {boolean} true if data is an array with a single value, false otherwise
|
|
922
923
|
*/
|
|
923
|
-
function isArrayOfSingleElement
|
|
924
|
+
function isArrayOfSingleElement( data ) {
|
|
924
925
|
|
|
925
926
|
if ( isNotArray( data ) ) { return false }
|
|
926
927
|
|
|
@@ -956,7 +957,7 @@ function isArrayOfSingleElement ( data ) {
|
|
|
956
957
|
* @param data {*} The data to check against the string type
|
|
957
958
|
* @returns {boolean} true if data is a string, false otherwise.
|
|
958
959
|
*/
|
|
959
|
-
function isString
|
|
960
|
+
function isString( data ) {
|
|
960
961
|
return ( typeof data === 'string' || data instanceof String )
|
|
961
962
|
}
|
|
962
963
|
|
|
@@ -966,7 +967,7 @@ function isString ( data ) {
|
|
|
966
967
|
* @param data {*} The data to check against the string type
|
|
967
968
|
* @returns {boolean} true if data is not a string, false otherwise.
|
|
968
969
|
*/
|
|
969
|
-
function isNotString
|
|
970
|
+
function isNotString( data ) {
|
|
970
971
|
return !isString( data )
|
|
971
972
|
}
|
|
972
973
|
|
|
@@ -994,7 +995,7 @@ function isNotString ( data ) {
|
|
|
994
995
|
* @param data {*} The data to check against the array of strings
|
|
995
996
|
* @returns {boolean} true if data is not an empty array where all values are string, false otherwise
|
|
996
997
|
*/
|
|
997
|
-
function isArrayOfString
|
|
998
|
+
function isArrayOfString( data ) {
|
|
998
999
|
|
|
999
1000
|
if ( isNotArray( data ) ) { return false }
|
|
1000
1001
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -1015,7 +1016,7 @@ function isArrayOfString ( data ) {
|
|
|
1015
1016
|
* @param data {*} The data to check against the array of strings
|
|
1016
1017
|
* @returns {boolean} true if data is not an empty array where all values are not string, false otherwise
|
|
1017
1018
|
*/
|
|
1018
|
-
function isNotArrayOfString
|
|
1019
|
+
function isNotArrayOfString( data ) {
|
|
1019
1020
|
|
|
1020
1021
|
if ( isNotArray( data ) ) { return true }
|
|
1021
1022
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -1054,7 +1055,7 @@ function isNotArrayOfString ( data ) {
|
|
|
1054
1055
|
* @param data {*} The data to check against the undefiness
|
|
1055
1056
|
* @returns {boolean} true if data is undefined, false otherwise.
|
|
1056
1057
|
*/
|
|
1057
|
-
function isUndefined
|
|
1058
|
+
function isUndefined( data ) {
|
|
1058
1059
|
return ( typeof data === 'undefined' )
|
|
1059
1060
|
}
|
|
1060
1061
|
|
|
@@ -1064,7 +1065,7 @@ function isUndefined ( data ) {
|
|
|
1064
1065
|
* @param data {*} The data to check against the undefiness
|
|
1065
1066
|
* @returns {boolean} true if data is defined, false otherwise.
|
|
1066
1067
|
*/
|
|
1067
|
-
function isNotUndefined
|
|
1068
|
+
function isNotUndefined( data ) {
|
|
1068
1069
|
return ( typeof data !== 'undefined' )
|
|
1069
1070
|
}
|
|
1070
1071
|
|
|
@@ -1092,7 +1093,7 @@ function isNotUndefined ( data ) {
|
|
|
1092
1093
|
* @param data {*} The data to check against the array of undefined
|
|
1093
1094
|
* @returns {boolean} true if data is not an empty array where all values are undefined, false otherwise
|
|
1094
1095
|
*/
|
|
1095
|
-
function isArrayOfUndefined
|
|
1096
|
+
function isArrayOfUndefined( data ) {
|
|
1096
1097
|
|
|
1097
1098
|
if ( isNotArray( data ) ) { return false }
|
|
1098
1099
|
if ( isEmptyArray( data ) ) { return false }
|
|
@@ -1113,7 +1114,7 @@ function isArrayOfUndefined ( data ) {
|
|
|
1113
1114
|
* @param data {*} The data to check against the array of undefined
|
|
1114
1115
|
* @returns {boolean} true if data is not an empty array where all values are defined, false otherwise
|
|
1115
1116
|
*/
|
|
1116
|
-
function isNotArrayOfUndefined
|
|
1117
|
+
function isNotArrayOfUndefined( data ) {
|
|
1117
1118
|
|
|
1118
1119
|
if ( isNotArray( data ) ) { return true }
|
|
1119
1120
|
if ( isEmptyArray( data ) ) { return true }
|
|
@@ -1152,7 +1153,7 @@ function isNotArrayOfUndefined ( data ) {
|
|
|
1152
1153
|
* @param data {*} The data to check against true value
|
|
1153
1154
|
* @returns {boolean} true if data is a boolean set to true, false otherwise.
|
|
1154
1155
|
*/
|
|
1155
|
-
function isTrue
|
|
1156
|
+
function isTrue( data ) {
|
|
1156
1157
|
return ( isBoolean( data ) && ( data === true ) )
|
|
1157
1158
|
}
|
|
1158
1159
|
|
|
@@ -1162,7 +1163,7 @@ function isTrue ( data ) {
|
|
|
1162
1163
|
* @param data {*} The data to check against false value
|
|
1163
1164
|
* @returns {boolean} true if data is a boolean set to false, false otherwise.
|
|
1164
1165
|
*/
|
|
1165
|
-
function isFalse
|
|
1166
|
+
function isFalse( data ) {
|
|
1166
1167
|
return ( isBoolean( data ) && ( data === false ) )
|
|
1167
1168
|
}
|
|
1168
1169
|
|
|
@@ -1190,7 +1191,7 @@ function isFalse ( data ) {
|
|
|
1190
1191
|
* @param data {*} The data to check against the positive maximum state
|
|
1191
1192
|
* @returns {boolean} true if data is positive maximum, false otherwise
|
|
1192
1193
|
*/
|
|
1193
|
-
function isMaxPositive
|
|
1194
|
+
function isMaxPositive( data ) {
|
|
1194
1195
|
return ( data === Number.MAX_VALUE )
|
|
1195
1196
|
}
|
|
1196
1197
|
|
|
@@ -1200,7 +1201,7 @@ function isMaxPositive ( data ) {
|
|
|
1200
1201
|
* @param data {*} The data to check against the maximum infinite state
|
|
1201
1202
|
* @returns {boolean} true if data is negative maximum, false otherwise
|
|
1202
1203
|
*/
|
|
1203
|
-
function isMaxNegative
|
|
1204
|
+
function isMaxNegative( data ) {
|
|
1204
1205
|
return ( data === -Number.MAX_VALUE )
|
|
1205
1206
|
}
|
|
1206
1207
|
|
|
@@ -1228,7 +1229,7 @@ function isMaxNegative ( data ) {
|
|
|
1228
1229
|
* @param data {*} The data to check against the positive minimum state
|
|
1229
1230
|
* @returns {boolean} true if data is positive minimum, false otherwise
|
|
1230
1231
|
*/
|
|
1231
|
-
function isMinPositive
|
|
1232
|
+
function isMinPositive( data ) {
|
|
1232
1233
|
return ( data === Number.MIN_VALUE )
|
|
1233
1234
|
}
|
|
1234
1235
|
|
|
@@ -1238,7 +1239,7 @@ function isMinPositive ( data ) {
|
|
|
1238
1239
|
* @param data {*} The data to check against the minimum infinite state
|
|
1239
1240
|
* @returns {boolean} true if data is negative minimum, false otherwise
|
|
1240
1241
|
*/
|
|
1241
|
-
function isMinNegative
|
|
1242
|
+
function isMinNegative( data ) {
|
|
1242
1243
|
return ( data === -Number.MIN_VALUE )
|
|
1243
1244
|
}
|
|
1244
1245
|
|
|
@@ -1266,7 +1267,7 @@ function isMinNegative ( data ) {
|
|
|
1266
1267
|
* @param data {*} The data to check against the maximum safe integer state
|
|
1267
1268
|
* @returns {boolean} true if data is a maximum safe integer, false otherwise
|
|
1268
1269
|
*/
|
|
1269
|
-
function isMaxSafeInteger
|
|
1270
|
+
function isMaxSafeInteger( data ) {
|
|
1270
1271
|
return ( data === Number.MAX_SAFE_INTEGER )
|
|
1271
1272
|
}
|
|
1272
1273
|
|
|
@@ -1278,7 +1279,7 @@ function isMaxSafeInteger ( data ) {
|
|
|
1278
1279
|
* @param data {*} The data to check against the minimum safe integer state
|
|
1279
1280
|
* @returns {boolean} true if data is a minimum safe integer, false otherwise
|
|
1280
1281
|
*/
|
|
1281
|
-
function isMinSafeInteger
|
|
1282
|
+
function isMinSafeInteger( data ) {
|
|
1282
1283
|
return ( data === Number.MIN_SAFE_INTEGER )
|
|
1283
1284
|
}
|
|
1284
1285
|
|
|
@@ -1308,7 +1309,7 @@ function isMinSafeInteger ( data ) {
|
|
|
1308
1309
|
* @param data {*} The data to check against the emptiness of the object
|
|
1309
1310
|
* @returns {boolean} true if data is an empty object, false otherwise
|
|
1310
1311
|
*/
|
|
1311
|
-
function isEmptyObject
|
|
1312
|
+
function isEmptyObject( data ) {
|
|
1312
1313
|
|
|
1313
1314
|
if ( isNotObject( data ) ) { return false }
|
|
1314
1315
|
|
|
@@ -1333,7 +1334,7 @@ function isEmptyObject ( data ) {
|
|
|
1333
1334
|
* @param data {*} The data to check against the emptiness of the object
|
|
1334
1335
|
* @returns {boolean} true if data is not an empty object, false otherwise
|
|
1335
1336
|
*/
|
|
1336
|
-
function isNotEmptyObject
|
|
1337
|
+
function isNotEmptyObject( data ) {
|
|
1337
1338
|
return !( isEmptyObject( data ) )
|
|
1338
1339
|
}
|
|
1339
1340
|
|
|
@@ -1361,7 +1362,7 @@ function isNotEmptyObject ( data ) {
|
|
|
1361
1362
|
* @param data {*} The data to check against the emptiness of the string
|
|
1362
1363
|
* @returns {boolean} true if data is an empty string, false otherwise.
|
|
1363
1364
|
*/
|
|
1364
|
-
function isEmptyString
|
|
1365
|
+
function isEmptyString( data ) {
|
|
1365
1366
|
|
|
1366
1367
|
if ( isNotString( data ) ) {
|
|
1367
1368
|
return false
|
|
@@ -1377,7 +1378,7 @@ function isEmptyString ( data ) {
|
|
|
1377
1378
|
* @param data {*} The data to check against the emptiness of the string
|
|
1378
1379
|
* @returns {boolean} true if data is not an empty string, false otherwise.
|
|
1379
1380
|
*/
|
|
1380
|
-
function isNotEmptyString
|
|
1381
|
+
function isNotEmptyString( data ) {
|
|
1381
1382
|
|
|
1382
1383
|
return !( isEmptyString( data ) )
|
|
1383
1384
|
|
|
@@ -1407,7 +1408,7 @@ function isNotEmptyString ( data ) {
|
|
|
1407
1408
|
* @param data {*} The data to check against the blankness of the string
|
|
1408
1409
|
* @returns {boolean} true if data is a blank string, false otherwise.
|
|
1409
1410
|
*/
|
|
1410
|
-
function isBlankString
|
|
1411
|
+
function isBlankString( data ) {
|
|
1411
1412
|
|
|
1412
1413
|
if ( isNotString( data ) ) { return false }
|
|
1413
1414
|
if ( isEmptyString( data ) ) { return false }
|
|
@@ -1421,7 +1422,7 @@ function isBlankString ( data ) {
|
|
|
1421
1422
|
* @param data {*} The data to check against the blankness of the string
|
|
1422
1423
|
* @returns {boolean} true if data is not a blank string, false otherwise.
|
|
1423
1424
|
*/
|
|
1424
|
-
function isNotBlankString
|
|
1425
|
+
function isNotBlankString( data ) {
|
|
1425
1426
|
|
|
1426
1427
|
return !( isBlankString( data ) )
|
|
1427
1428
|
|
|
@@ -1451,7 +1452,7 @@ function isNotBlankString ( data ) {
|
|
|
1451
1452
|
* @param data {*} The data to check against the symbol type
|
|
1452
1453
|
* @returns {boolean} true if data is a symbol, false otherwise.
|
|
1453
1454
|
*/
|
|
1454
|
-
function isSymbol
|
|
1455
|
+
function isSymbol( data ) {
|
|
1455
1456
|
return ( typeof data === 'symbol' )
|
|
1456
1457
|
}
|
|
1457
1458
|
|
|
@@ -1461,7 +1462,7 @@ function isSymbol ( data ) {
|
|
|
1461
1462
|
* @param data {*} The data to check against the symbol type
|
|
1462
1463
|
* @returns {boolean} true if data is not a symbol, false otherwise.
|
|
1463
1464
|
*/
|
|
1464
|
-
function isNotSymbol
|
|
1465
|
+
function isNotSymbol( data ) {
|
|
1465
1466
|
return ( typeof data !== 'symbol' )
|
|
1466
1467
|
}
|
|
1467
1468
|
|
|
@@ -1491,7 +1492,7 @@ function isNotSymbol ( data ) {
|
|
|
1491
1492
|
* @param data {*} The data to check against the emptiness
|
|
1492
1493
|
* @returns {boolean} true if data is considered as empty, false otherwise.
|
|
1493
1494
|
*/
|
|
1494
|
-
function isEmpty
|
|
1495
|
+
function isEmpty( data ) {
|
|
1495
1496
|
|
|
1496
1497
|
if ( isNotDefined( data ) ) { return false }
|
|
1497
1498
|
if ( isEmptyString( data ) ) { return true}
|
|
@@ -1508,7 +1509,7 @@ function isEmpty ( data ) {
|
|
|
1508
1509
|
* @param data {*} The data to check against the emptiness
|
|
1509
1510
|
* @returns {boolean} true if data is considered as not empty, false otherwise.
|
|
1510
1511
|
*/
|
|
1511
|
-
function isNotEmpty
|
|
1512
|
+
function isNotEmpty( data ) {
|
|
1512
1513
|
return !isEmpty( data )
|
|
1513
1514
|
}
|
|
1514
1515
|
|
|
@@ -1526,121 +1527,121 @@ function isNotEmpty ( data ) {
|
|
|
1526
1527
|
// Usefull when a simple data structure is used multiple times
|
|
1527
1528
|
validator.add( 'ColorType', color => {
|
|
1528
1529
|
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1530
|
+
const r = color.r
|
|
1531
|
+
if ( color.r === undefined || Itee.Validators.isNotNumber( r ) ) {
|
|
1532
|
+
return false
|
|
1533
|
+
}
|
|
1533
1534
|
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1535
|
+
const g = color.g
|
|
1536
|
+
if ( color.g === undefined || Itee.Validators.isNotNumber( g ) ) {
|
|
1537
|
+
return false
|
|
1538
|
+
}
|
|
1538
1539
|
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1540
|
+
const b = color.b
|
|
1541
|
+
if ( color.b === undefined || Itee.Validators.isNotNumber( b ) ) {
|
|
1542
|
+
return false
|
|
1543
|
+
}
|
|
1543
1544
|
|
|
1544
|
-
|
|
1545
|
-
|
|
1545
|
+
return true
|
|
1546
|
+
} )
|
|
1546
1547
|
|
|
1547
1548
|
// Using schema composition
|
|
1548
1549
|
// Usefull for design validation schema faster and based on previous declared validation types
|
|
1549
1550
|
validator.add( 'Range_0_255', ( value ) => {
|
|
1550
1551
|
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1552
|
+
if ( Itee.Validators.isNotNumber( value ) ) {
|
|
1553
|
+
return false
|
|
1554
|
+
}
|
|
1554
1555
|
|
|
1555
|
-
|
|
1556
|
+
return !(value <= 0 || value > 255)
|
|
1556
1557
|
|
|
1557
|
-
|
|
1558
|
+
} )
|
|
1558
1559
|
|
|
1559
1560
|
validator.add( 'ColorSchema', {
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1561
|
+
r: {
|
|
1562
|
+
required: true,
|
|
1563
|
+
type: 'Range_0_255'
|
|
1564
|
+
},
|
|
1565
|
+
g: {
|
|
1566
|
+
required: true,
|
|
1567
|
+
type: 'Range_0_255'
|
|
1568
|
+
},
|
|
1569
|
+
b: {
|
|
1570
|
+
required: true,
|
|
1571
|
+
type: 'Range_0_255'
|
|
1572
|
+
}
|
|
1573
|
+
} )
|
|
1573
1574
|
|
|
1574
1575
|
validator.add( 'ColorStructure', {
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1576
|
+
color_from_type: {
|
|
1577
|
+
type: 'ColorType'
|
|
1578
|
+
},
|
|
1579
|
+
col_from_schema: {
|
|
1580
|
+
type: 'ColorSchema'
|
|
1581
|
+
},
|
|
1582
|
+
col_from_fn: {
|
|
1583
|
+
// Inner function
|
|
1584
|
+
// Usefull for specific validation requirement that cannot match other previous validation schema or type
|
|
1585
|
+
fn: function ColorValidator ( color ) {
|
|
1586
|
+
|
|
1587
|
+
const r = color.r
|
|
1588
|
+
if ( color.r === undefined || Itee.Validators.isNotNumber( r ) ) {
|
|
1589
|
+
return false
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
const g = color.g
|
|
1593
|
+
if ( color.g === undefined || Itee.Validators.isNotNumber( g ) ) {
|
|
1594
|
+
return false
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
const b = color.b
|
|
1598
|
+
if ( color.b === undefined || Itee.Validators.isNotNumber( b ) ) {
|
|
1599
|
+
return false
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
return true
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
} )
|
|
1605
1606
|
|
|
1606
1607
|
// The data to validate
|
|
1607
1608
|
const colorStruct = {
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1609
|
+
color_from_type: {
|
|
1610
|
+
r: 0,
|
|
1611
|
+
g: 1,
|
|
1612
|
+
b: 2
|
|
1613
|
+
},
|
|
1614
|
+
col_from_schema: {
|
|
1615
|
+
r: 10,
|
|
1616
|
+
g: 20,
|
|
1617
|
+
b: 30
|
|
1618
|
+
},
|
|
1619
|
+
col_from_fn: {
|
|
1620
|
+
r: 0,
|
|
1621
|
+
g: 127,
|
|
1622
|
+
b: 255
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1624
1625
|
|
|
1625
1626
|
// Execute
|
|
1626
1627
|
|
|
1627
1628
|
try {
|
|
1628
1629
|
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1630
|
+
if ( validator.check( colorStruct, 'ColorStructure' ) ) {
|
|
1631
|
+
alert( 'ColorStructure is valid !' )
|
|
1632
|
+
} else {
|
|
1633
|
+
alert( validator.errors )
|
|
1634
|
+
}
|
|
1634
1635
|
|
|
1635
|
-
} catch ( err ) {
|
|
1636
|
-
|
|
1637
|
-
}
|
|
1636
|
+
} catch ( err ) {
|
|
1637
|
+
alert( err )
|
|
1638
|
+
}
|
|
1638
1639
|
*
|
|
1639
1640
|
*/
|
|
1640
1641
|
|
|
1641
1642
|
class Validator {
|
|
1642
1643
|
|
|
1643
|
-
constructor
|
|
1644
|
+
constructor() {
|
|
1644
1645
|
|
|
1645
1646
|
/**
|
|
1646
1647
|
* The validators store, by default it contains validators for Boolean, Number, Integer, Float, Array, String, Object, Symbol and Function
|
|
@@ -1674,7 +1675,7 @@ class Validator {
|
|
|
1674
1675
|
* @param type {string} - A string that represent the type of data to validate
|
|
1675
1676
|
* @param validator {(function|object)} - A function or validation schema that represent the type of data to validate
|
|
1676
1677
|
*/
|
|
1677
|
-
add
|
|
1678
|
+
add( type, validator ) {
|
|
1678
1679
|
|
|
1679
1680
|
if ( isNotString( type ) ) { throw new TypeError( `Validator: Expect type to be a string` ) }
|
|
1680
1681
|
if ( isNotFunction( validator ) && isNotObject( validator ) ) { throw new TypeError( `Validator: Expect validator to be an object or a function` ) }
|
|
@@ -1689,7 +1690,7 @@ class Validator {
|
|
|
1689
1690
|
*
|
|
1690
1691
|
* @param type {string} - The type to remove
|
|
1691
1692
|
*/
|
|
1692
|
-
remove
|
|
1693
|
+
remove( type ) {
|
|
1693
1694
|
|
|
1694
1695
|
delete this.validators[ type ];
|
|
1695
1696
|
|
|
@@ -1700,7 +1701,7 @@ class Validator {
|
|
|
1700
1701
|
*
|
|
1701
1702
|
* @return {Array.<string>} - The list of registered type
|
|
1702
1703
|
*/
|
|
1703
|
-
getAvalaibleTypes
|
|
1704
|
+
getAvalaibleTypes() {
|
|
1704
1705
|
|
|
1705
1706
|
const availablesTypes = [];
|
|
1706
1707
|
|
|
@@ -1720,7 +1721,7 @@ class Validator {
|
|
|
1720
1721
|
* @param breakOnError {boolean} - Return on first validation error ( true by default )
|
|
1721
1722
|
* @return {boolean} - Return true is the data is validated, false otherwise
|
|
1722
1723
|
*/
|
|
1723
|
-
check
|
|
1724
|
+
check( data, type, breakOnError = true ) {
|
|
1724
1725
|
|
|
1725
1726
|
const validator = this.validators[ type ];
|
|
1726
1727
|
if ( isNotDefined( validator ) ) {
|
|
@@ -1826,7 +1827,7 @@ if ( isNotDefined( exports.Validator ) ) {
|
|
|
1826
1827
|
* @param data {*} The data to check against the array buffer type
|
|
1827
1828
|
* @returns {boolean} true if data is a array buffer, false otherwise.
|
|
1828
1829
|
*/
|
|
1829
|
-
function isArrayBuffer
|
|
1830
|
+
function isArrayBuffer( data ) {
|
|
1830
1831
|
return ( data instanceof ArrayBuffer )
|
|
1831
1832
|
}
|
|
1832
1833
|
|
|
@@ -1836,7 +1837,7 @@ function isArrayBuffer ( data ) {
|
|
|
1836
1837
|
* @param data {*} The data to check against the array buffer type
|
|
1837
1838
|
* @returns {boolean} true if data is not a array buffer, false otherwise.
|
|
1838
1839
|
*/
|
|
1839
|
-
function isNotArrayBuffer
|
|
1840
|
+
function isNotArrayBuffer( data ) {
|
|
1840
1841
|
return !isArrayBuffer( data )
|
|
1841
1842
|
}
|
|
1842
1843
|
|
|
@@ -1864,7 +1865,7 @@ function isNotArrayBuffer ( data ) {
|
|
|
1864
1865
|
* @param data {*} The data to check against the big int 64 array type
|
|
1865
1866
|
* @returns {boolean} true if data is a big int 64 array, false otherwise.
|
|
1866
1867
|
*/
|
|
1867
|
-
function isBigInt64Array
|
|
1868
|
+
function isBigInt64Array( data ) {
|
|
1868
1869
|
return ( data instanceof BigInt64Array )
|
|
1869
1870
|
}
|
|
1870
1871
|
|
|
@@ -1874,7 +1875,7 @@ function isBigInt64Array ( data ) {
|
|
|
1874
1875
|
* @param data {*} The data to check against the big int 64 array type
|
|
1875
1876
|
* @returns {boolean} true if data is not a big int 64 array, false otherwise.
|
|
1876
1877
|
*/
|
|
1877
|
-
function isNotBigInt64Array
|
|
1878
|
+
function isNotBigInt64Array( data ) {
|
|
1878
1879
|
return !isBigInt64Array( data )
|
|
1879
1880
|
}
|
|
1880
1881
|
|
|
@@ -1902,7 +1903,7 @@ function isNotBigInt64Array ( data ) {
|
|
|
1902
1903
|
* @param data {*} The data to check against the big unsigned int 64 array type
|
|
1903
1904
|
* @returns {boolean} true if data is a big unsigned int 64 array, false otherwise.
|
|
1904
1905
|
*/
|
|
1905
|
-
function isBigUint64Array
|
|
1906
|
+
function isBigUint64Array( data ) {
|
|
1906
1907
|
return ( data instanceof BigUint64Array )
|
|
1907
1908
|
}
|
|
1908
1909
|
|
|
@@ -1912,7 +1913,7 @@ function isBigUint64Array ( data ) {
|
|
|
1912
1913
|
* @param data {*} The data to check against the big unsigned int 64 array type
|
|
1913
1914
|
* @returns {boolean} true if data is not a big unsigned int 64 array, false otherwise.
|
|
1914
1915
|
*/
|
|
1915
|
-
function isNotBigUint64Array
|
|
1916
|
+
function isNotBigUint64Array( data ) {
|
|
1916
1917
|
return !isBigUint64Array( data )
|
|
1917
1918
|
}
|
|
1918
1919
|
|
|
@@ -1940,7 +1941,7 @@ function isNotBigUint64Array ( data ) {
|
|
|
1940
1941
|
* @param data {*} The data to check against the float 32 array type
|
|
1941
1942
|
* @returns {boolean} true if data is a float 32 array , false otherwise.
|
|
1942
1943
|
*/
|
|
1943
|
-
function isFloat32Array
|
|
1944
|
+
function isFloat32Array( data ) {
|
|
1944
1945
|
return ( data instanceof Float32Array )
|
|
1945
1946
|
}
|
|
1946
1947
|
|
|
@@ -1950,7 +1951,7 @@ function isFloat32Array ( data ) {
|
|
|
1950
1951
|
* @param data {*} The data to check against the float 32 array type
|
|
1951
1952
|
* @returns {boolean} true if data is not a float 32 array , false otherwise.
|
|
1952
1953
|
*/
|
|
1953
|
-
function isNotFloat32Array
|
|
1954
|
+
function isNotFloat32Array( data ) {
|
|
1954
1955
|
return !isFloat32Array( data )
|
|
1955
1956
|
}
|
|
1956
1957
|
|
|
@@ -1978,7 +1979,7 @@ function isNotFloat32Array ( data ) {
|
|
|
1978
1979
|
* @param data {*} The data to check against the float 64 array type
|
|
1979
1980
|
* @returns {boolean} true if data is a float 64 array , false otherwise.
|
|
1980
1981
|
*/
|
|
1981
|
-
function isFloat64Array
|
|
1982
|
+
function isFloat64Array( data ) {
|
|
1982
1983
|
return ( data instanceof Float64Array )
|
|
1983
1984
|
}
|
|
1984
1985
|
|
|
@@ -1988,7 +1989,7 @@ function isFloat64Array ( data ) {
|
|
|
1988
1989
|
* @param data {*} The data to check against the float 64 array type
|
|
1989
1990
|
* @returns {boolean} true if data is not a float 64 array , false otherwise.
|
|
1990
1991
|
*/
|
|
1991
|
-
function isNotFloat64Array
|
|
1992
|
+
function isNotFloat64Array( data ) {
|
|
1992
1993
|
return !isFloat64Array( data )
|
|
1993
1994
|
}
|
|
1994
1995
|
|
|
@@ -2016,7 +2017,7 @@ function isNotFloat64Array ( data ) {
|
|
|
2016
2017
|
* @param data {*} The data to check against the int 16 array type
|
|
2017
2018
|
* @returns {boolean} true if data is a int 16 array , false otherwise.
|
|
2018
2019
|
*/
|
|
2019
|
-
function isInt16Array
|
|
2020
|
+
function isInt16Array( data ) {
|
|
2020
2021
|
return ( data instanceof Int16Array )
|
|
2021
2022
|
}
|
|
2022
2023
|
|
|
@@ -2026,7 +2027,7 @@ function isInt16Array ( data ) {
|
|
|
2026
2027
|
* @param data {*} The data to check against the int 16 array type
|
|
2027
2028
|
* @returns {boolean} true if data is not a int 16 array , false otherwise.
|
|
2028
2029
|
*/
|
|
2029
|
-
function isNotInt16Array
|
|
2030
|
+
function isNotInt16Array( data ) {
|
|
2030
2031
|
return !isInt16Array( data )
|
|
2031
2032
|
}
|
|
2032
2033
|
|
|
@@ -2054,7 +2055,7 @@ function isNotInt16Array ( data ) {
|
|
|
2054
2055
|
* @param data {*} The data to check against the int 32 array type
|
|
2055
2056
|
* @returns {boolean} true if data is a int 32 array , false otherwise.
|
|
2056
2057
|
*/
|
|
2057
|
-
function isInt32Array
|
|
2058
|
+
function isInt32Array( data ) {
|
|
2058
2059
|
return ( data instanceof Int32Array )
|
|
2059
2060
|
}
|
|
2060
2061
|
|
|
@@ -2064,7 +2065,7 @@ function isInt32Array ( data ) {
|
|
|
2064
2065
|
* @param data {*} The data to check against the int 32 array type
|
|
2065
2066
|
* @returns {boolean} true if data is not a int 32 array , false otherwise.
|
|
2066
2067
|
*/
|
|
2067
|
-
function isNotInt32Array
|
|
2068
|
+
function isNotInt32Array( data ) {
|
|
2068
2069
|
return !isInt32Array( data )
|
|
2069
2070
|
}
|
|
2070
2071
|
|
|
@@ -2092,7 +2093,7 @@ function isNotInt32Array ( data ) {
|
|
|
2092
2093
|
* @param data {*} The data to check against the int 8 array type
|
|
2093
2094
|
* @returns {boolean} true if data is a int 8 array , false otherwise.
|
|
2094
2095
|
*/
|
|
2095
|
-
function isInt8Array
|
|
2096
|
+
function isInt8Array( data ) {
|
|
2096
2097
|
return ( data instanceof Int8Array )
|
|
2097
2098
|
}
|
|
2098
2099
|
|
|
@@ -2102,7 +2103,7 @@ function isInt8Array ( data ) {
|
|
|
2102
2103
|
* @param data {*} The data to check against the int 8 array type
|
|
2103
2104
|
* @returns {boolean} true if data is not a int 8 array , false otherwise.
|
|
2104
2105
|
*/
|
|
2105
|
-
function isNotInt8Array
|
|
2106
|
+
function isNotInt8Array( data ) {
|
|
2106
2107
|
return !isInt8Array( data )
|
|
2107
2108
|
}
|
|
2108
2109
|
|
|
@@ -2130,7 +2131,7 @@ function isNotInt8Array ( data ) {
|
|
|
2130
2131
|
* @param data {*} The data to check against the unsigned int 16 array type
|
|
2131
2132
|
* @returns {boolean} true if data is a unsigned int 16 array , false otherwise.
|
|
2132
2133
|
*/
|
|
2133
|
-
function isUint16Array
|
|
2134
|
+
function isUint16Array( data ) {
|
|
2134
2135
|
return ( data instanceof Uint16Array )
|
|
2135
2136
|
}
|
|
2136
2137
|
|
|
@@ -2140,7 +2141,7 @@ function isUint16Array ( data ) {
|
|
|
2140
2141
|
* @param data {*} The data to check against the unsigned int 16 array type
|
|
2141
2142
|
* @returns {boolean} true if data is not a unsigned int 16 array , false otherwise.
|
|
2142
2143
|
*/
|
|
2143
|
-
function isNotUint16Array
|
|
2144
|
+
function isNotUint16Array( data ) {
|
|
2144
2145
|
return !isUint16Array( data )
|
|
2145
2146
|
}
|
|
2146
2147
|
|
|
@@ -2168,7 +2169,7 @@ function isNotUint16Array ( data ) {
|
|
|
2168
2169
|
* @param data {*} The data to check against the unsigned int 32 array type
|
|
2169
2170
|
* @returns {boolean} true if data is a unsigned int 32 array , false otherwise.
|
|
2170
2171
|
*/
|
|
2171
|
-
function isUint32Array
|
|
2172
|
+
function isUint32Array( data ) {
|
|
2172
2173
|
return ( data instanceof Uint32Array )
|
|
2173
2174
|
}
|
|
2174
2175
|
|
|
@@ -2178,7 +2179,7 @@ function isUint32Array ( data ) {
|
|
|
2178
2179
|
* @param data {*} The data to check against the unsigned int 32 array type
|
|
2179
2180
|
* @returns {boolean} true if data is not a unsigned int 32 array , false otherwise.
|
|
2180
2181
|
*/
|
|
2181
|
-
function isNotUint32Array
|
|
2182
|
+
function isNotUint32Array( data ) {
|
|
2182
2183
|
return !isUint32Array( data )
|
|
2183
2184
|
}
|
|
2184
2185
|
|
|
@@ -2206,7 +2207,7 @@ function isNotUint32Array ( data ) {
|
|
|
2206
2207
|
* @param data {*} The data to check against the unsigned int 8 array type
|
|
2207
2208
|
* @returns {boolean} true if data is a unsigned int 8 array , false otherwise.
|
|
2208
2209
|
*/
|
|
2209
|
-
function isUint8Array
|
|
2210
|
+
function isUint8Array( data ) {
|
|
2210
2211
|
return ( data instanceof Uint8Array )
|
|
2211
2212
|
}
|
|
2212
2213
|
|
|
@@ -2216,7 +2217,7 @@ function isUint8Array ( data ) {
|
|
|
2216
2217
|
* @param data {*} The data to check against the unsigned int 8 array type
|
|
2217
2218
|
* @returns {boolean} true if data is not a unsigned int 8 array , false otherwise.
|
|
2218
2219
|
*/
|
|
2219
|
-
function isNotUint8Array
|
|
2220
|
+
function isNotUint8Array( data ) {
|
|
2220
2221
|
return !isUint8Array( data )
|
|
2221
2222
|
}
|
|
2222
2223
|
|
|
@@ -2244,7 +2245,7 @@ function isNotUint8Array ( data ) {
|
|
|
2244
2245
|
* @param data {*} The data to check against the unsigned clamped int 8 array type
|
|
2245
2246
|
* @returns {boolean} true if data is a unsigned clamped int 8 array , false otherwise.
|
|
2246
2247
|
*/
|
|
2247
|
-
function isUint8ClampedArray
|
|
2248
|
+
function isUint8ClampedArray( data ) {
|
|
2248
2249
|
return ( data instanceof Uint8ClampedArray )
|
|
2249
2250
|
}
|
|
2250
2251
|
|
|
@@ -2254,7 +2255,7 @@ function isUint8ClampedArray ( data ) {
|
|
|
2254
2255
|
* @param data {*} The data to check against the unsigned clamped int 8 array type
|
|
2255
2256
|
* @returns {boolean} true if data is not a unsigned clamped int 8 array , false otherwise.
|
|
2256
2257
|
*/
|
|
2257
|
-
function isNotUint8ClampedArray
|
|
2258
|
+
function isNotUint8ClampedArray( data ) {
|
|
2258
2259
|
return !isUint8ClampedArray( data )
|
|
2259
2260
|
}
|
|
2260
2261
|
|
|
@@ -2314,7 +2315,7 @@ const ABSOLUTE_ZERO_FAHRENHEIT = -459.67;
|
|
|
2314
2315
|
* @param data {*}
|
|
2315
2316
|
* @return {boolean}
|
|
2316
2317
|
*/
|
|
2317
|
-
function isCelsius
|
|
2318
|
+
function isCelsius( data ) {
|
|
2318
2319
|
return ( isNumber( data ) && data >= ABSOLUTE_ZERO_CELSIUS )
|
|
2319
2320
|
}
|
|
2320
2321
|
|
|
@@ -2323,7 +2324,7 @@ function isCelsius ( data ) {
|
|
|
2323
2324
|
* @param data {*}
|
|
2324
2325
|
* @return {boolean}
|
|
2325
2326
|
*/
|
|
2326
|
-
function isNotCelsius
|
|
2327
|
+
function isNotCelsius( data ) {
|
|
2327
2328
|
return !isCelsius( data )
|
|
2328
2329
|
}
|
|
2329
2330
|
|
|
@@ -2350,7 +2351,7 @@ function isNotCelsius ( data ) {
|
|
|
2350
2351
|
* @param data {*}
|
|
2351
2352
|
* @return {boolean}
|
|
2352
2353
|
*/
|
|
2353
|
-
function isFahrenheit
|
|
2354
|
+
function isFahrenheit( data ) {
|
|
2354
2355
|
return ( isNumber( data ) && data >= ABSOLUTE_ZERO_FAHRENHEIT )
|
|
2355
2356
|
}
|
|
2356
2357
|
|
|
@@ -2359,7 +2360,7 @@ function isFahrenheit ( data ) {
|
|
|
2359
2360
|
* @param data {*}
|
|
2360
2361
|
* @return {boolean}
|
|
2361
2362
|
*/
|
|
2362
|
-
function isNotFahrenheit
|
|
2363
|
+
function isNotFahrenheit( data ) {
|
|
2363
2364
|
return !isFahrenheit( data )
|
|
2364
2365
|
}
|
|
2365
2366
|
|
|
@@ -2386,7 +2387,7 @@ function isNotFahrenheit ( data ) {
|
|
|
2386
2387
|
* @param data {*}
|
|
2387
2388
|
* @return {boolean}
|
|
2388
2389
|
*/
|
|
2389
|
-
function isKelvin
|
|
2390
|
+
function isKelvin( data ) {
|
|
2390
2391
|
return ( isNumber( data ) && data >= ABSOLUTE_ZERO_KELVIN )
|
|
2391
2392
|
}
|
|
2392
2393
|
|
|
@@ -2395,7 +2396,7 @@ function isKelvin ( data ) {
|
|
|
2395
2396
|
* @param data {*}
|
|
2396
2397
|
* @return {boolean}
|
|
2397
2398
|
*/
|
|
2398
|
-
function isNotKelvin
|
|
2399
|
+
function isNotKelvin( data ) {
|
|
2399
2400
|
return !isKelvin( data )
|
|
2400
2401
|
}
|
|
2401
2402
|
|
|
@@ -2422,7 +2423,7 @@ function isNotKelvin ( data ) {
|
|
|
2422
2423
|
* @param data {*}
|
|
2423
2424
|
* @return {boolean}
|
|
2424
2425
|
*/
|
|
2425
|
-
function isTemperature
|
|
2426
|
+
function isTemperature( data ) {
|
|
2426
2427
|
return ( isKelvin( data ) || isCelsius( data ) || isFahrenheit( data ) )
|
|
2427
2428
|
}
|
|
2428
2429
|
|
|
@@ -2431,7 +2432,7 @@ function isTemperature ( data ) {
|
|
|
2431
2432
|
* @param data {*}
|
|
2432
2433
|
* @return {boolean}
|
|
2433
2434
|
*/
|
|
2434
|
-
function isNotTemperature
|
|
2435
|
+
function isNotTemperature( data ) {
|
|
2435
2436
|
return ( isNotKelvin( data ) && isNotCelsius( data ) && isNotFahrenheit( data ) )
|
|
2436
2437
|
}
|
|
2437
2438
|
|
|
@@ -2462,13 +2463,13 @@ function isNotTemperature ( data ) {
|
|
|
2462
2463
|
* @param path {string|Buffer|URL} The data to check against the block device path type
|
|
2463
2464
|
* @returns {boolean} true if path is a block device path, false otherwise
|
|
2464
2465
|
*/
|
|
2465
|
-
function isBlockDevicePath
|
|
2466
|
-
if( isNotString(path) && !(path instanceof Buffer) && !(path instanceof URL) ) {
|
|
2467
|
-
throw new TypeError('Invalid path type! Expect string, buffer or url.')
|
|
2466
|
+
function isBlockDevicePath( path ) {
|
|
2467
|
+
if ( isNotString( path ) && !( path instanceof Buffer ) && !( path instanceof URL ) ) {
|
|
2468
|
+
throw new TypeError( 'Invalid path type! Expect string, buffer or url.' )
|
|
2468
2469
|
}
|
|
2469
2470
|
|
|
2470
|
-
const stat =
|
|
2471
|
-
return isDefined(stat) && stat.isBlockDevice()
|
|
2471
|
+
const stat = fs.statSync( path, { throwIfNoEntry: false } );
|
|
2472
|
+
return isDefined( stat ) && stat.isBlockDevice()
|
|
2472
2473
|
}
|
|
2473
2474
|
|
|
2474
2475
|
/**
|
|
@@ -2477,7 +2478,7 @@ function isBlockDevicePath ( path ) {
|
|
|
2477
2478
|
* @param path {string|Buffer|URL} The data to check against the block device path type
|
|
2478
2479
|
* @returns {boolean} true if path is not a block device path, false otherwise
|
|
2479
2480
|
*/
|
|
2480
|
-
function isNotBlockDevicePath
|
|
2481
|
+
function isNotBlockDevicePath( path ) {
|
|
2481
2482
|
return !isBlockDevicePath( path )
|
|
2482
2483
|
}
|
|
2483
2484
|
|
|
@@ -2508,8 +2509,8 @@ function isNotBlockDevicePath ( path ) {
|
|
|
2508
2509
|
* @param data {*} The data to check against the path type
|
|
2509
2510
|
* @returns {boolean} true if data is a valid path, false otherwise
|
|
2510
2511
|
*/
|
|
2511
|
-
function isValidPath
|
|
2512
|
-
return
|
|
2512
|
+
function isValidPath( data ) {
|
|
2513
|
+
return fs.existsSync( data )
|
|
2513
2514
|
}
|
|
2514
2515
|
|
|
2515
2516
|
/**
|
|
@@ -2518,7 +2519,7 @@ function isValidPath ( data ) {
|
|
|
2518
2519
|
* @param data {*} The data to check against the path type
|
|
2519
2520
|
* @returns {boolean} true if data is a valid path, false otherwise
|
|
2520
2521
|
*/
|
|
2521
|
-
function isInvalidPath
|
|
2522
|
+
function isInvalidPath( data ) {
|
|
2522
2523
|
return !isValidPath( data )
|
|
2523
2524
|
}
|
|
2524
2525
|
|
|
@@ -2546,7 +2547,7 @@ function isInvalidPath ( data ) {
|
|
|
2546
2547
|
* @param data {*} The data to check against the block device path type
|
|
2547
2548
|
* @returns {boolean} true if data is a valid block device path, false otherwise
|
|
2548
2549
|
*/
|
|
2549
|
-
function isValidBlockDevicePath
|
|
2550
|
+
function isValidBlockDevicePath( data ) {
|
|
2550
2551
|
return ( isValidPath( data ) && isBlockDevicePath( data ) )
|
|
2551
2552
|
}
|
|
2552
2553
|
|
|
@@ -2556,7 +2557,7 @@ function isValidBlockDevicePath ( data ) {
|
|
|
2556
2557
|
* @param data {*} The data to check against the block device path type
|
|
2557
2558
|
* @returns {boolean} true if data is an invalid block device path, false otherwise
|
|
2558
2559
|
*/
|
|
2559
|
-
function isInvalidBlockDevicePath
|
|
2560
|
+
function isInvalidBlockDevicePath( data ) {
|
|
2560
2561
|
return !isValidBlockDevicePath( data )
|
|
2561
2562
|
}
|
|
2562
2563
|
|
|
@@ -2587,13 +2588,13 @@ function isInvalidBlockDevicePath ( data ) {
|
|
|
2587
2588
|
* @param path {string|Buffer|URL} The data to check against the character device path type
|
|
2588
2589
|
* @returns {boolean} true if path is a character device path, false otherwise
|
|
2589
2590
|
*/
|
|
2590
|
-
function isCharacterDevicePath
|
|
2591
|
-
if( isNotString(path) && !(path instanceof Buffer) && !(path instanceof URL) ) {
|
|
2592
|
-
throw new TypeError('Invalid path type! Expect string, buffer or url.')
|
|
2591
|
+
function isCharacterDevicePath( path ) {
|
|
2592
|
+
if ( isNotString( path ) && !( path instanceof Buffer ) && !( path instanceof URL ) ) {
|
|
2593
|
+
throw new TypeError( 'Invalid path type! Expect string, buffer or url.' )
|
|
2593
2594
|
}
|
|
2594
2595
|
|
|
2595
|
-
const stat =
|
|
2596
|
-
return isDefined(stat) && stat.isCharacterDevice()
|
|
2596
|
+
const stat = fs.statSync( path, { throwIfNoEntry: false } );
|
|
2597
|
+
return isDefined( stat ) && stat.isCharacterDevice()
|
|
2597
2598
|
}
|
|
2598
2599
|
|
|
2599
2600
|
/**
|
|
@@ -2602,7 +2603,7 @@ function isCharacterDevicePath ( path ) {
|
|
|
2602
2603
|
* @param path {string|Buffer|URL} The data to check against the character device path type
|
|
2603
2604
|
* @returns {boolean} true if path is not a character device path, false otherwise
|
|
2604
2605
|
*/
|
|
2605
|
-
function isNotCharacterDevicePath
|
|
2606
|
+
function isNotCharacterDevicePath( path ) {
|
|
2606
2607
|
return !isCharacterDevicePath( path )
|
|
2607
2608
|
}
|
|
2608
2609
|
|
|
@@ -2630,7 +2631,7 @@ function isNotCharacterDevicePath ( path ) {
|
|
|
2630
2631
|
* @param data {*} The data to check against the character device path type
|
|
2631
2632
|
* @returns {boolean} true if data is a valid character device path, false otherwise
|
|
2632
2633
|
*/
|
|
2633
|
-
function isValidCharacterDevicePath
|
|
2634
|
+
function isValidCharacterDevicePath( data ) {
|
|
2634
2635
|
return ( isValidPath( data ) && isCharacterDevicePath( data ) )
|
|
2635
2636
|
}
|
|
2636
2637
|
|
|
@@ -2640,7 +2641,7 @@ function isValidCharacterDevicePath ( data ) {
|
|
|
2640
2641
|
* @param data {*} The data to check against the character device path type
|
|
2641
2642
|
* @returns {boolean} true if data is an invalid character device path, false otherwise
|
|
2642
2643
|
*/
|
|
2643
|
-
function isInvalidCharacterDevicePath
|
|
2644
|
+
function isInvalidCharacterDevicePath( data ) {
|
|
2644
2645
|
return !isValidCharacterDevicePath( data )
|
|
2645
2646
|
}
|
|
2646
2647
|
|
|
@@ -2671,13 +2672,13 @@ function isInvalidCharacterDevicePath ( data ) {
|
|
|
2671
2672
|
* @param path {string|Buffer|URL} The data to check against the directory path type
|
|
2672
2673
|
* @returns {boolean} true if path is a directory path, false otherwise
|
|
2673
2674
|
*/
|
|
2674
|
-
function isDirectoryPath
|
|
2675
|
-
if( isNotString(path) && !(path instanceof Buffer) && !(path instanceof URL) ) {
|
|
2676
|
-
throw new TypeError('Invalid path type! Expect string, buffer or url.')
|
|
2675
|
+
function isDirectoryPath( path ) {
|
|
2676
|
+
if ( isNotString( path ) && !( path instanceof Buffer ) && !( path instanceof URL ) ) {
|
|
2677
|
+
throw new TypeError( 'Invalid path type! Expect string, buffer or url.' )
|
|
2677
2678
|
}
|
|
2678
2679
|
|
|
2679
|
-
const stat =
|
|
2680
|
-
return isDefined(stat) && stat.isDirectory()
|
|
2680
|
+
const stat = fs.statSync( path, { throwIfNoEntry: false } );
|
|
2681
|
+
return isDefined( stat ) && stat.isDirectory()
|
|
2681
2682
|
}
|
|
2682
2683
|
|
|
2683
2684
|
/**
|
|
@@ -2686,7 +2687,7 @@ function isDirectoryPath ( path ) {
|
|
|
2686
2687
|
* @param path {string|Buffer|URL} The data to check against the directory path type
|
|
2687
2688
|
* @returns {boolean} true if path is a not directory path, false otherwise
|
|
2688
2689
|
*/
|
|
2689
|
-
function isNotDirectoryPath
|
|
2690
|
+
function isNotDirectoryPath( path ) {
|
|
2690
2691
|
return !isDirectoryPath( path )
|
|
2691
2692
|
}
|
|
2692
2693
|
|
|
@@ -2717,8 +2718,8 @@ function isNotDirectoryPath ( path ) {
|
|
|
2717
2718
|
* @param directoryPath {string|Buffer|URL} The directory path to check the emptiness
|
|
2718
2719
|
* @returns {boolean} true if directory is empty, false otherwise
|
|
2719
2720
|
*/
|
|
2720
|
-
function isEmptyDirectory
|
|
2721
|
-
return isDirectoryPath(directoryPath) && (
|
|
2721
|
+
function isEmptyDirectory( directoryPath ) {
|
|
2722
|
+
return isDirectoryPath( directoryPath ) && ( fs.readdirSync( directoryPath ).length === 0 )
|
|
2722
2723
|
}
|
|
2723
2724
|
|
|
2724
2725
|
/**
|
|
@@ -2727,7 +2728,7 @@ function isEmptyDirectory ( directoryPath ) {
|
|
|
2727
2728
|
* @param directoryPath {string|Buffer|URL} The directory path to check the emptiness
|
|
2728
2729
|
* @returns {boolean} true if directory is not empty, false otherwise
|
|
2729
2730
|
*/
|
|
2730
|
-
function isNotEmptyDirectory
|
|
2731
|
+
function isNotEmptyDirectory( directoryPath ) {
|
|
2731
2732
|
return !isEmptyDirectory( directoryPath )
|
|
2732
2733
|
}
|
|
2733
2734
|
|
|
@@ -2755,7 +2756,7 @@ function isNotEmptyDirectory ( directoryPath ) {
|
|
|
2755
2756
|
* @param data {*} The data to check against the directory path type
|
|
2756
2757
|
* @returns {boolean} true if data is a valid directory path, false otherwise
|
|
2757
2758
|
*/
|
|
2758
|
-
function isValidDirectoryPath
|
|
2759
|
+
function isValidDirectoryPath( data ) {
|
|
2759
2760
|
return ( isValidPath( data ) && isDirectoryPath( data ) )
|
|
2760
2761
|
}
|
|
2761
2762
|
|
|
@@ -2765,7 +2766,7 @@ function isValidDirectoryPath ( data ) {
|
|
|
2765
2766
|
* @param data {*} The data to check against the directory path type
|
|
2766
2767
|
* @returns {boolean} true if data is an invalid directory path, false otherwise
|
|
2767
2768
|
*/
|
|
2768
|
-
function isInvalidDirectoryPath
|
|
2769
|
+
function isInvalidDirectoryPath( data ) {
|
|
2769
2770
|
return !isValidDirectoryPath( data )
|
|
2770
2771
|
}
|
|
2771
2772
|
|
|
@@ -2796,13 +2797,13 @@ function isInvalidDirectoryPath ( data ) {
|
|
|
2796
2797
|
* @param path {string|Buffer|URL} The data to check against the fifo path type
|
|
2797
2798
|
* @returns {boolean} true if path is a fifo path, false otherwise
|
|
2798
2799
|
*/
|
|
2799
|
-
function isFIFOPath
|
|
2800
|
-
if( isNotString(path) && !(path instanceof Buffer) && !(path instanceof URL) ) {
|
|
2801
|
-
throw new TypeError('Invalid path type! Expect string, buffer or url.')
|
|
2800
|
+
function isFIFOPath( path ) {
|
|
2801
|
+
if ( isNotString( path ) && !( path instanceof Buffer ) && !( path instanceof URL ) ) {
|
|
2802
|
+
throw new TypeError( 'Invalid path type! Expect string, buffer or url.' )
|
|
2802
2803
|
}
|
|
2803
2804
|
|
|
2804
|
-
const stat =
|
|
2805
|
-
return isDefined(stat) && stat.isFIFO()
|
|
2805
|
+
const stat = fs.statSync( path, { throwIfNoEntry: false } );
|
|
2806
|
+
return isDefined( stat ) && stat.isFIFO()
|
|
2806
2807
|
}
|
|
2807
2808
|
|
|
2808
2809
|
/**
|
|
@@ -2811,7 +2812,7 @@ function isFIFOPath ( path ) {
|
|
|
2811
2812
|
* @param path {string|Buffer|URL} The data to check against the fifo path type
|
|
2812
2813
|
* @returns {boolean} true if path is not a fifo path, false otherwise
|
|
2813
2814
|
*/
|
|
2814
|
-
function isNotFIFOPath
|
|
2815
|
+
function isNotFIFOPath( path ) {
|
|
2815
2816
|
return !isFIFOPath( path )
|
|
2816
2817
|
}
|
|
2817
2818
|
|
|
@@ -2842,7 +2843,7 @@ function isNotFIFOPath ( path ) {
|
|
|
2842
2843
|
* @param data {*} The data to check against the fifo path type
|
|
2843
2844
|
* @returns {boolean} true if data is a valid fifo path, false otherwise
|
|
2844
2845
|
*/
|
|
2845
|
-
function isValidFIFOPath
|
|
2846
|
+
function isValidFIFOPath( data ) {
|
|
2846
2847
|
return ( isValidPath( data ) && isFIFOPath( data ) )
|
|
2847
2848
|
}
|
|
2848
2849
|
|
|
@@ -2852,7 +2853,7 @@ function isValidFIFOPath ( data ) {
|
|
|
2852
2853
|
* @param data {*} The data to check against the fifo path type
|
|
2853
2854
|
* @returns {boolean} true if data is an invalid fifo path, false otherwise
|
|
2854
2855
|
*/
|
|
2855
|
-
function isInvalidFIFOPath
|
|
2856
|
+
function isInvalidFIFOPath( data ) {
|
|
2856
2857
|
return !isValidFIFOPath( data )
|
|
2857
2858
|
}
|
|
2858
2859
|
|
|
@@ -2883,13 +2884,13 @@ function isInvalidFIFOPath ( data ) {
|
|
|
2883
2884
|
* @param path {string|Buffer|URL} The data to check against the file path type
|
|
2884
2885
|
* @returns {boolean} true if path is a file path, false otherwise
|
|
2885
2886
|
*/
|
|
2886
|
-
function isFilePath
|
|
2887
|
-
if( isNotString(path) && !(path instanceof Buffer) && !(path instanceof URL) ) {
|
|
2888
|
-
throw new TypeError('Invalid path type! Expect string, buffer or url.')
|
|
2887
|
+
function isFilePath( path ) {
|
|
2888
|
+
if ( isNotString( path ) && !( path instanceof Buffer ) && !( path instanceof URL ) ) {
|
|
2889
|
+
throw new TypeError( 'Invalid path type! Expect string, buffer or url.' )
|
|
2889
2890
|
}
|
|
2890
2891
|
|
|
2891
|
-
const stat =
|
|
2892
|
-
return isDefined(stat) && stat.isFile()
|
|
2892
|
+
const stat = fs.statSync( path, { throwIfNoEntry: false } );
|
|
2893
|
+
return isDefined( stat ) && stat.isFile()
|
|
2893
2894
|
}
|
|
2894
2895
|
|
|
2895
2896
|
/**
|
|
@@ -2898,7 +2899,7 @@ function isFilePath ( path ) {
|
|
|
2898
2899
|
* @param path {string|Buffer|URL} The data to check against the file path type
|
|
2899
2900
|
* @returns {boolean} true if path is not a file path, false otherwise
|
|
2900
2901
|
*/
|
|
2901
|
-
function isNotFilePath
|
|
2902
|
+
function isNotFilePath( path ) {
|
|
2902
2903
|
return !isFilePath( path )
|
|
2903
2904
|
}
|
|
2904
2905
|
|
|
@@ -2930,12 +2931,12 @@ function isNotFilePath ( path ) {
|
|
|
2930
2931
|
* @param threshold {number} An amount of byte below which it consider the file as empty ( 0 as default ).
|
|
2931
2932
|
* @returns {boolean} true if file is empty, false otherwise
|
|
2932
2933
|
*/
|
|
2933
|
-
function isEmptyFile
|
|
2934
|
-
if( isNotString(filePath) && !(filePath instanceof Buffer) && !(filePath instanceof URL) ) {
|
|
2935
|
-
throw new TypeError('Invalid path type! Expect string, buffer or url.')
|
|
2934
|
+
function isEmptyFile( filePath, threshold = 0 ) {
|
|
2935
|
+
if ( isNotString( filePath ) && !( filePath instanceof Buffer ) && !( filePath instanceof URL ) ) {
|
|
2936
|
+
throw new TypeError( 'Invalid path type! Expect string, buffer or url.' )
|
|
2936
2937
|
}
|
|
2937
2938
|
|
|
2938
|
-
return isFilePath(filePath) && (
|
|
2939
|
+
return isFilePath( filePath ) && ( fs.statSync( filePath ).size <= threshold )
|
|
2939
2940
|
}
|
|
2940
2941
|
|
|
2941
2942
|
/**
|
|
@@ -2945,8 +2946,8 @@ function isEmptyFile ( filePath, threshold = 0 ) {
|
|
|
2945
2946
|
* @param threshold {number} An amount of byte above which it consider the file as not empty ( 0 as default ).
|
|
2946
2947
|
* @returns {boolean} true if file is not empty, false otherwise
|
|
2947
2948
|
*/
|
|
2948
|
-
function isNotEmptyFile
|
|
2949
|
-
return !isEmptyFile(filePath, threshold)
|
|
2949
|
+
function isNotEmptyFile( filePath, threshold = 0 ) {
|
|
2950
|
+
return !isEmptyFile( filePath, threshold )
|
|
2950
2951
|
}
|
|
2951
2952
|
|
|
2952
2953
|
/**
|
|
@@ -2973,7 +2974,7 @@ function isNotEmptyFile ( filePath, threshold = 0 ) {
|
|
|
2973
2974
|
* @param data {*} The data to check against the file path type
|
|
2974
2975
|
* @returns {boolean} true if data is a valid file path, false otherwise
|
|
2975
2976
|
*/
|
|
2976
|
-
function isValidFilePath
|
|
2977
|
+
function isValidFilePath( data ) {
|
|
2977
2978
|
return ( isValidPath( data ) && isFilePath( data ) )
|
|
2978
2979
|
}
|
|
2979
2980
|
|
|
@@ -2983,7 +2984,7 @@ function isValidFilePath ( data ) {
|
|
|
2983
2984
|
* @param data {*} The data to check against the file path type
|
|
2984
2985
|
* @returns {boolean} true if data is an invalid file path, false otherwise
|
|
2985
2986
|
*/
|
|
2986
|
-
function isInvalidFilePath
|
|
2987
|
+
function isInvalidFilePath( data ) {
|
|
2987
2988
|
return !isValidFilePath( data )
|
|
2988
2989
|
}
|
|
2989
2990
|
|
|
@@ -3014,13 +3015,13 @@ function isInvalidFilePath ( data ) {
|
|
|
3014
3015
|
* @param path {string|Buffer|URL} The data to check against the socket path type
|
|
3015
3016
|
* @returns {boolean} true if path is a socket path, false otherwise
|
|
3016
3017
|
*/
|
|
3017
|
-
function isSocketPath
|
|
3018
|
-
if( isNotString(path) && !(path instanceof Buffer) && !(path instanceof URL) ) {
|
|
3019
|
-
throw new TypeError('Invalid path type! Expect string, buffer or url.')
|
|
3018
|
+
function isSocketPath( path ) {
|
|
3019
|
+
if ( isNotString( path ) && !( path instanceof Buffer ) && !( path instanceof URL ) ) {
|
|
3020
|
+
throw new TypeError( 'Invalid path type! Expect string, buffer or url.' )
|
|
3020
3021
|
}
|
|
3021
3022
|
|
|
3022
|
-
const stat =
|
|
3023
|
-
return isDefined(stat) && stat.isSocket()
|
|
3023
|
+
const stat = fs.statSync( path, { throwIfNoEntry: false } );
|
|
3024
|
+
return isDefined( stat ) && stat.isSocket()
|
|
3024
3025
|
}
|
|
3025
3026
|
|
|
3026
3027
|
/**
|
|
@@ -3029,7 +3030,7 @@ function isSocketPath ( path ) {
|
|
|
3029
3030
|
* @param path {string|Buffer|URL} The data to check against the socket path type
|
|
3030
3031
|
* @returns {boolean} true if path is not a socket path, false otherwise
|
|
3031
3032
|
*/
|
|
3032
|
-
function isNotSocketPath
|
|
3033
|
+
function isNotSocketPath( path ) {
|
|
3033
3034
|
return !isSocketPath( path )
|
|
3034
3035
|
}
|
|
3035
3036
|
|
|
@@ -3057,7 +3058,7 @@ function isNotSocketPath ( path ) {
|
|
|
3057
3058
|
* @param data {*} The data to check against the socket path type
|
|
3058
3059
|
* @returns {boolean} true if data is a valid socket path, false otherwise
|
|
3059
3060
|
*/
|
|
3060
|
-
function isValidSocketPath
|
|
3061
|
+
function isValidSocketPath( data ) {
|
|
3061
3062
|
return ( isValidPath( data ) && isSocketPath( data ) )
|
|
3062
3063
|
}
|
|
3063
3064
|
|
|
@@ -3067,7 +3068,7 @@ function isValidSocketPath ( data ) {
|
|
|
3067
3068
|
* @param data {*} The data to check against the socket path type
|
|
3068
3069
|
* @returns {boolean} true if data is an invalid socket path, false otherwise
|
|
3069
3070
|
*/
|
|
3070
|
-
function isInvalidSocketPath
|
|
3071
|
+
function isInvalidSocketPath( data ) {
|
|
3071
3072
|
return !isValidSocketPath( data )
|
|
3072
3073
|
}
|
|
3073
3074
|
|
|
@@ -3098,13 +3099,13 @@ function isInvalidSocketPath ( data ) {
|
|
|
3098
3099
|
* @param path {string|Buffer|URL} The data to check against the symbolic link path type
|
|
3099
3100
|
* @returns {boolean} true if path is a symbolic link path, false otherwise
|
|
3100
3101
|
*/
|
|
3101
|
-
function isSymbolicLinkPath
|
|
3102
|
-
if( isNotString(path) && !(path instanceof Buffer) && !(path instanceof URL) ) {
|
|
3103
|
-
throw new TypeError('Invalid path type! Expect string, buffer or url.')
|
|
3102
|
+
function isSymbolicLinkPath( path ) {
|
|
3103
|
+
if ( isNotString( path ) && !( path instanceof Buffer ) && !( path instanceof URL ) ) {
|
|
3104
|
+
throw new TypeError( 'Invalid path type! Expect string, buffer or url.' )
|
|
3104
3105
|
}
|
|
3105
3106
|
|
|
3106
|
-
const stat =
|
|
3107
|
-
return isDefined(stat) && stat.isSymbolicLink()
|
|
3107
|
+
const stat = fs.statSync( path, { throwIfNoEntry: false } );
|
|
3108
|
+
return isDefined( stat ) && stat.isSymbolicLink()
|
|
3108
3109
|
}
|
|
3109
3110
|
|
|
3110
3111
|
/**
|
|
@@ -3113,7 +3114,7 @@ function isSymbolicLinkPath ( path ) {
|
|
|
3113
3114
|
* @param path {string|Buffer|URL} The data to check against the symbolic link path type
|
|
3114
3115
|
* @returns {boolean} true if path is not a symbolic link path, false otherwise
|
|
3115
3116
|
*/
|
|
3116
|
-
function isNotSymbolicLinkPath
|
|
3117
|
+
function isNotSymbolicLinkPath( path ) {
|
|
3117
3118
|
return !isSymbolicLinkPath( path )
|
|
3118
3119
|
}
|
|
3119
3120
|
|
|
@@ -3141,7 +3142,7 @@ function isNotSymbolicLinkPath ( path ) {
|
|
|
3141
3142
|
* @param data {*} The data to check against the symbolic link path type
|
|
3142
3143
|
* @returns {boolean} true if data is a valid symbolic link path, false otherwise
|
|
3143
3144
|
*/
|
|
3144
|
-
function isValidSymbolicLinkPath
|
|
3145
|
+
function isValidSymbolicLinkPath( data ) {
|
|
3145
3146
|
return ( isValidPath( data ) && isSymbolicLinkPath( data ) )
|
|
3146
3147
|
}
|
|
3147
3148
|
|
|
@@ -3151,7 +3152,7 @@ function isValidSymbolicLinkPath ( data ) {
|
|
|
3151
3152
|
* @param data {*} The data to check against the symbolic link path type
|
|
3152
3153
|
* @returns {boolean} true if data is an invalid symbolic link path, false otherwise
|
|
3153
3154
|
*/
|
|
3154
|
-
function isInvalidSymbolicLinkPath
|
|
3155
|
+
function isInvalidSymbolicLinkPath( data ) {
|
|
3155
3156
|
return !isValidSymbolicLinkPath( data )
|
|
3156
3157
|
}
|
|
3157
3158
|
|