@creative-web-solution/front-library 7.1.10 → 7.1.11
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 +5 -0
- package/Modules/Validator/Tools/IsDate.ts +29 -11
- package/README.md +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @see extra/modules/validator.md for details
|
|
7
7
|
*/
|
|
8
|
-
export default function isDate( value: string, format = 'd/m/y' ): boolean {
|
|
8
|
+
export default function isDate( value: string, format = 'd/m/y' ): boolean {
|
|
9
|
+
format = format.toLocaleLowerCase();
|
|
10
|
+
|
|
9
11
|
const RE_SEPARATOR = ( /[^dmy]/ ).exec( format );
|
|
10
12
|
|
|
11
13
|
if ( !RE_SEPARATOR ) {
|
|
@@ -18,22 +20,38 @@ export default function isDate( value: string, format = 'd/m/y' ): boolean {
|
|
|
18
20
|
return false;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
+
const ARR_FORMAT = format.split( SEPARATOR );
|
|
24
|
+
const ARR_VALUE = value.split( SEPARATOR );
|
|
23
25
|
|
|
24
|
-
if (
|
|
26
|
+
if ( ARR_FORMAT.length !== ARR_VALUE.length ) {
|
|
25
27
|
return false;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
const PARSED_DATE = {
|
|
31
|
+
"d": -1,
|
|
32
|
+
"m": -1,
|
|
33
|
+
"y": -1
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
ARR_FORMAT.forEach( ( format, index ) => {
|
|
37
|
+
const VALUE = Number( ARR_VALUE[ index ] );
|
|
38
|
+
|
|
39
|
+
if ( format.indexOf( 'y' ) > -1 ) {
|
|
40
|
+
PARSED_DATE.y = VALUE;
|
|
41
|
+
}
|
|
42
|
+
else if ( format.indexOf( 'm' ) > -1 ) {
|
|
43
|
+
PARSED_DATE.m = VALUE - 1;
|
|
44
|
+
}
|
|
45
|
+
else if ( format.indexOf( 'd' ) > -1 ) {
|
|
46
|
+
PARSED_DATE.d = VALUE;
|
|
47
|
+
}
|
|
48
|
+
} )
|
|
31
49
|
|
|
32
|
-
const date = new Date( y, m, d );
|
|
50
|
+
const date = new Date( PARSED_DATE.y, PARSED_DATE.m, PARSED_DATE.d );
|
|
33
51
|
|
|
34
52
|
return (
|
|
35
|
-
date.getDate() === d &&
|
|
36
|
-
date.getMonth() === m &&
|
|
37
|
-
date.getFullYear() === y
|
|
53
|
+
date.getDate() === PARSED_DATE.d &&
|
|
54
|
+
date.getMonth() === PARSED_DATE.m &&
|
|
55
|
+
date.getFullYear() === PARSED_DATE.y
|
|
38
56
|
);
|
|
39
57
|
}
|
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@creative-web-solution/front-library",
|
|
3
3
|
"title": "Frontend library",
|
|
4
4
|
"description": "Frontend functions and modules",
|
|
5
|
-
"version": "7.1.
|
|
5
|
+
"version": "7.1.11",
|
|
6
6
|
"homepage": "https://github.com/creative-web-solution/front-library",
|
|
7
7
|
"author": "Creative Web Solution <contact@cws-studio.com> (https://www.cws-studio.com)",
|
|
8
8
|
"keywords": [],
|