@creative-web-solution/front-library 7.1.11 → 7.1.12
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 +8 -51
- package/README.md +1 -1
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,57 +1,14 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
3
|
+
|
|
4
|
+
dayjs.extend( customParseFormat )
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* Test if the value is a date
|
|
3
8
|
*
|
|
4
|
-
* @param format - d for day, m for month and y for year. Only in lowercase. January = 1
|
|
5
|
-
*
|
|
6
9
|
* @see extra/modules/validator.md for details
|
|
7
10
|
*/
|
|
8
|
-
export default function isDate( value: string, format = '
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const RE_SEPARATOR = ( /[^dmy]/ ).exec( format );
|
|
12
|
-
|
|
13
|
-
if ( !RE_SEPARATOR ) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const SEPARATOR = RE_SEPARATOR[ 0 ];
|
|
18
|
-
|
|
19
|
-
if ( !( new RegExp( `^[0-9${ SEPARATOR }]+$` ) ).test( value ) ) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const ARR_FORMAT = format.split( SEPARATOR );
|
|
24
|
-
const ARR_VALUE = value.split( SEPARATOR );
|
|
25
|
-
|
|
26
|
-
if ( ARR_FORMAT.length !== ARR_VALUE.length ) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
|
|
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
|
-
} )
|
|
49
|
-
|
|
50
|
-
const date = new Date( PARSED_DATE.y, PARSED_DATE.m, PARSED_DATE.d );
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
date.getDate() === PARSED_DATE.d &&
|
|
54
|
-
date.getMonth() === PARSED_DATE.m &&
|
|
55
|
-
date.getFullYear() === PARSED_DATE.y
|
|
56
|
-
);
|
|
11
|
+
export default function isDate( value: string, format = 'DD/MM/YYYY' ): boolean {
|
|
12
|
+
const PARSED_DATE = dayjs( value, format, true );
|
|
13
|
+
return PARSED_DATE.isValid()
|
|
57
14
|
}
|
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.12",
|
|
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": [],
|
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
"npm": ">=6.0.0"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {},
|
|
20
|
-
"dependencies": {
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"dayjs": "1.11.4"
|
|
22
|
+
},
|
|
21
23
|
"devDependencies": {
|
|
22
24
|
"babelify": "10.0.0",
|
|
23
25
|
"@babel/preset-env": "^7.14.8",
|