@alfalab/core-components-date-input 1.2.13 → 1.3.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 +11 -0
- package/dist/Component.d.ts +16 -18
- package/dist/Component.js +65 -28
- package/dist/cssm/Component.d.ts +16 -18
- package/dist/cssm/Component.js +64 -27
- package/dist/cssm/index.js +4 -6
- package/dist/cssm/utils/format.d.ts +3 -1
- package/dist/cssm/utils/format.js +16 -0
- package/dist/cssm/utils/index.d.ts +0 -1
- package/dist/cssm/utils/index.js +2 -5
- package/dist/cssm/utils/native-supports.d.ts +1 -3
- package/dist/cssm/utils/native-supports.js +0 -4
- package/dist/esm/Component.d.ts +16 -18
- package/dist/esm/Component.js +67 -31
- package/dist/esm/index.css +4 -4
- package/dist/esm/index.js +4 -4
- package/dist/esm/utils/format.d.ts +3 -1
- package/dist/esm/utils/format.js +17 -3
- package/dist/esm/utils/index.d.ts +0 -1
- package/dist/esm/utils/index.js +2 -3
- package/dist/esm/utils/native-supports.d.ts +1 -3
- package/dist/esm/utils/native-supports.js +1 -3
- package/dist/index.css +4 -4
- package/dist/index.js +4 -6
- package/dist/modern/Component.d.ts +16 -18
- package/dist/modern/Component.js +67 -29
- package/dist/modern/index.css +4 -4
- package/dist/modern/index.js +4 -4
- package/dist/modern/utils/format.d.ts +3 -1
- package/dist/modern/utils/format.js +13 -3
- package/dist/modern/utils/index.d.ts +0 -1
- package/dist/modern/utils/index.js +2 -3
- package/dist/modern/utils/native-supports.d.ts +1 -3
- package/dist/modern/utils/native-supports.js +1 -3
- package/dist/utils/format.d.ts +3 -1
- package/dist/utils/format.js +16 -0
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +2 -5
- package/dist/utils/native-supports.d.ts +1 -3
- package/dist/utils/native-supports.js +0 -4
- package/package.json +5 -4
- package/dist/cssm/utils/date-correction-pipe.d.ts +0 -9
- package/dist/cssm/utils/date-correction-pipe.js +0 -59
- package/dist/esm/utils/date-correction-pipe.d.ts +0 -9
- package/dist/esm/utils/date-correction-pipe.js +0 -54
- package/dist/modern/utils/date-correction-pipe.d.ts +0 -9
- package/dist/modern/utils/date-correction-pipe.js +0 -52
- package/dist/utils/date-correction-pipe.d.ts +0 -9
- package/dist/utils/date-correction-pipe.js +0 -59
|
@@ -4,4 +4,6 @@ declare const DATE_MASK: (string | RegExp)[];
|
|
|
4
4
|
declare const isCompleteDateInput: (input: string) => boolean;
|
|
5
5
|
declare const formatDate: (date: number | Date, dateFormat?: string) => string;
|
|
6
6
|
declare const parseDateString: (value: string, dateFormat?: string) => Date;
|
|
7
|
-
|
|
7
|
+
declare const isValid: (inputValue?: string | undefined) => boolean;
|
|
8
|
+
declare const format: (value: string) => string;
|
|
9
|
+
export { DATE_FORMAT, NATIVE_DATE_FORMAT, DATE_MASK, isCompleteDateInput, formatDate, parseDateString, isValid, format };
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import { format, parse } from 'date-fns';
|
|
1
|
+
import { format as format$1, parse, isValid as isValid$1 } from 'date-fns';
|
|
2
2
|
|
|
3
3
|
const DATE_FORMAT = 'dd.MM.yyyy';
|
|
4
4
|
const NATIVE_DATE_FORMAT = 'yyyy-MM-dd';
|
|
5
5
|
const DATE_MASK = [/\d/, /\d/, '.', /\d/, /\d/, '.', /\d/, /\d/, /\d/, /\d/];
|
|
6
6
|
const isCompleteDateInput = (input) => input.length === DATE_MASK.length;
|
|
7
|
-
const formatDate = (date, dateFormat = DATE_FORMAT) => format(date, dateFormat);
|
|
7
|
+
const formatDate = (date, dateFormat = DATE_FORMAT) => format$1(date, dateFormat);
|
|
8
8
|
const parseDateString = (value, dateFormat = DATE_FORMAT) => parse(value, dateFormat, new Date());
|
|
9
|
+
const isValid = (inputValue) => !inputValue || (isCompleteDateInput(inputValue) && isValid$1(parseDateString(inputValue)));
|
|
10
|
+
const format = (value) => value
|
|
11
|
+
.replace(/^(\d\d)(\d)$/, '$1.$2') // 121 => 12.1
|
|
12
|
+
.replace(/^(\d\d)\.(\d\d)(\d)$/, '$1.$2.$3') // 12.122 => 12.12.2
|
|
13
|
+
.replace(/^(\d\d)\d\.(.*)/, '$1.$2') // 123.12.2005 => 12.12.2005
|
|
14
|
+
.replace(/^(\d\d\.\d\d)\d\.(.*)/, '$1.$2') // 12.123.2005 => 12.12.2005
|
|
15
|
+
.replace(/^(\d\d\.\d\d\.\d\d\d\d).*/, '$1') // 12.12.20056 => 12.12.2005
|
|
16
|
+
.replace(/\.$/, '') // 12. => 12
|
|
17
|
+
.replace(/^(\d\d\.\d\d)(\d\d\d\d)/, '$1.$2') // 12.122005 => 12.12.2005
|
|
18
|
+
.replace(/^(\d\d)(\d\d\.\d\d\d\d)/, '$1.$2'); // 1212.2005 => 12.12.2005
|
|
9
19
|
|
|
10
|
-
export { DATE_FORMAT, DATE_MASK, NATIVE_DATE_FORMAT, formatDate, isCompleteDateInput, parseDateString };
|
|
20
|
+
export { DATE_FORMAT, DATE_MASK, NATIVE_DATE_FORMAT, format, formatDate, isCompleteDateInput, isValid, parseDateString };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import 'date-fns';
|
|
2
|
-
export { DATE_FORMAT, DATE_MASK, NATIVE_DATE_FORMAT, formatDate, isCompleteDateInput, parseDateString } from './format.js';
|
|
3
|
-
export {
|
|
4
|
-
export { IS_BROWSER, SUPPORTS_INPUT_TYPE_DATE, isInputDateSupported } from './native-supports.js';
|
|
2
|
+
export { DATE_FORMAT, DATE_MASK, NATIVE_DATE_FORMAT, format, formatDate, isCompleteDateInput, isValid, parseDateString } from './format.js';
|
|
3
|
+
export { isInputDateSupported } from './native-supports.js';
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
declare const IS_BROWSER: boolean;
|
|
2
|
-
declare const SUPPORTS_INPUT_TYPE_DATE: boolean;
|
|
3
1
|
/**
|
|
4
2
|
* Возвращает `true`, если поддерживается `input[type="date"]`
|
|
5
3
|
*/
|
|
6
4
|
declare function isInputDateSupported(): boolean;
|
|
7
|
-
export {
|
|
5
|
+
export { isInputDateSupported };
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const IS_BROWSER = typeof window !== 'undefined';
|
|
2
|
-
const SUPPORTS_INPUT_TYPE_DATE = IS_BROWSER && isInputDateSupported();
|
|
3
1
|
/**
|
|
4
2
|
* Возвращает `true`, если поддерживается `input[type="date"]`
|
|
5
3
|
*/
|
|
@@ -11,4 +9,4 @@ function isInputDateSupported() {
|
|
|
11
9
|
return input.value !== value;
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
export {
|
|
12
|
+
export { isInputDateSupported };
|
package/dist/utils/format.d.ts
CHANGED
|
@@ -4,4 +4,6 @@ declare const DATE_MASK: (string | RegExp)[];
|
|
|
4
4
|
declare const isCompleteDateInput: (input: string) => boolean;
|
|
5
5
|
declare const formatDate: (date: number | Date, dateFormat?: string) => string;
|
|
6
6
|
declare const parseDateString: (value: string, dateFormat?: string) => Date;
|
|
7
|
-
|
|
7
|
+
declare const isValid: (inputValue?: string | undefined) => boolean;
|
|
8
|
+
declare const format: (value: string) => string;
|
|
9
|
+
export { DATE_FORMAT, NATIVE_DATE_FORMAT, DATE_MASK, isCompleteDateInput, formatDate, parseDateString, isValid, format };
|
package/dist/utils/format.js
CHANGED
|
@@ -16,10 +16,26 @@ var parseDateString = function (value, dateFormat) {
|
|
|
16
16
|
if (dateFormat === void 0) { dateFormat = DATE_FORMAT; }
|
|
17
17
|
return dateFns.parse(value, dateFormat, new Date());
|
|
18
18
|
};
|
|
19
|
+
var isValid = function (inputValue) {
|
|
20
|
+
return !inputValue || (isCompleteDateInput(inputValue) && dateFns.isValid(parseDateString(inputValue)));
|
|
21
|
+
};
|
|
22
|
+
var format = function (value) {
|
|
23
|
+
return value
|
|
24
|
+
.replace(/^(\d\d)(\d)$/, '$1.$2') // 121 => 12.1
|
|
25
|
+
.replace(/^(\d\d)\.(\d\d)(\d)$/, '$1.$2.$3') // 12.122 => 12.12.2
|
|
26
|
+
.replace(/^(\d\d)\d\.(.*)/, '$1.$2') // 123.12.2005 => 12.12.2005
|
|
27
|
+
.replace(/^(\d\d\.\d\d)\d\.(.*)/, '$1.$2') // 12.123.2005 => 12.12.2005
|
|
28
|
+
.replace(/^(\d\d\.\d\d\.\d\d\d\d).*/, '$1') // 12.12.20056 => 12.12.2005
|
|
29
|
+
.replace(/\.$/, '') // 12. => 12
|
|
30
|
+
.replace(/^(\d\d\.\d\d)(\d\d\d\d)/, '$1.$2') // 12.122005 => 12.12.2005
|
|
31
|
+
.replace(/^(\d\d)(\d\d\.\d\d\d\d)/, '$1.$2');
|
|
32
|
+
}; // 1212.2005 => 12.12.2005
|
|
19
33
|
|
|
20
34
|
exports.DATE_FORMAT = DATE_FORMAT;
|
|
21
35
|
exports.DATE_MASK = DATE_MASK;
|
|
22
36
|
exports.NATIVE_DATE_FORMAT = NATIVE_DATE_FORMAT;
|
|
37
|
+
exports.format = format;
|
|
23
38
|
exports.formatDate = formatDate;
|
|
24
39
|
exports.isCompleteDateInput = isCompleteDateInput;
|
|
40
|
+
exports.isValid = isValid;
|
|
25
41
|
exports.parseDateString = parseDateString;
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
require('date-fns');
|
|
6
6
|
var utils_format = require('./format.js');
|
|
7
|
-
var utils_dateCorrectionPipe = require('./date-correction-pipe.js');
|
|
8
7
|
var utils_nativeSupports = require('./native-supports.js');
|
|
9
8
|
|
|
10
9
|
|
|
@@ -12,11 +11,9 @@ var utils_nativeSupports = require('./native-supports.js');
|
|
|
12
11
|
exports.DATE_FORMAT = utils_format.DATE_FORMAT;
|
|
13
12
|
exports.DATE_MASK = utils_format.DATE_MASK;
|
|
14
13
|
exports.NATIVE_DATE_FORMAT = utils_format.NATIVE_DATE_FORMAT;
|
|
14
|
+
exports.format = utils_format.format;
|
|
15
15
|
exports.formatDate = utils_format.formatDate;
|
|
16
16
|
exports.isCompleteDateInput = utils_format.isCompleteDateInput;
|
|
17
|
+
exports.isValid = utils_format.isValid;
|
|
17
18
|
exports.parseDateString = utils_format.parseDateString;
|
|
18
|
-
exports.createAutoCorrectedDatePipe = utils_dateCorrectionPipe.createAutoCorrectedDatePipe;
|
|
19
|
-
exports.mask = utils_dateCorrectionPipe.mask;
|
|
20
|
-
exports.IS_BROWSER = utils_nativeSupports.IS_BROWSER;
|
|
21
|
-
exports.SUPPORTS_INPUT_TYPE_DATE = utils_nativeSupports.SUPPORTS_INPUT_TYPE_DATE;
|
|
22
19
|
exports.isInputDateSupported = utils_nativeSupports.isInputDateSupported;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
declare const IS_BROWSER: boolean;
|
|
2
|
-
declare const SUPPORTS_INPUT_TYPE_DATE: boolean;
|
|
3
1
|
/**
|
|
4
2
|
* Возвращает `true`, если поддерживается `input[type="date"]`
|
|
5
3
|
*/
|
|
6
4
|
declare function isInputDateSupported(): boolean;
|
|
7
|
-
export {
|
|
5
|
+
export { isInputDateSupported };
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var IS_BROWSER = typeof window !== 'undefined';
|
|
6
|
-
var SUPPORTS_INPUT_TYPE_DATE = IS_BROWSER && isInputDateSupported();
|
|
7
5
|
/**
|
|
8
6
|
* Возвращает `true`, если поддерживается `input[type="date"]`
|
|
9
7
|
*/
|
|
@@ -15,6 +13,4 @@ function isInputDateSupported() {
|
|
|
15
13
|
return input.value !== value;
|
|
16
14
|
}
|
|
17
15
|
|
|
18
|
-
exports.IS_BROWSER = IS_BROWSER;
|
|
19
|
-
exports.SUPPORTS_INPUT_TYPE_DATE = SUPPORTS_INPUT_TYPE_DATE;
|
|
20
16
|
exports.isInputDateSupported = isInputDateSupported;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alfalab/core-components-date-input",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
"react": "^16.9.0 || ^17.0.1"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@alfalab/core-components-
|
|
23
|
-
"date-fns": "^2.16.1"
|
|
22
|
+
"@alfalab/core-components-input": "^8.0.7",
|
|
23
|
+
"date-fns": "^2.16.1",
|
|
24
|
+
"react-merge-refs": "^1.1.0"
|
|
24
25
|
},
|
|
25
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "45ff10d1efc81a4a1afb82c6b6eca1b428c7c459"
|
|
26
27
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
declare const mask: (string | RegExp)[];
|
|
2
|
-
declare function createAutoCorrectedDatePipe({ minYear, maxYear }?: {
|
|
3
|
-
minYear?: number | undefined;
|
|
4
|
-
maxYear?: number | undefined;
|
|
5
|
-
}, dateFormat?: string): (conformedValue: string) => false | {
|
|
6
|
-
value: string;
|
|
7
|
-
indexesOfPipedChars: number[];
|
|
8
|
-
};
|
|
9
|
-
export { mask, createAutoCorrectedDatePipe };
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var maxValueMonth = [31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
6
|
-
var formatOrder = ['yyyy', 'yy', 'mm', 'dd', 'HH', 'MM', 'SS'];
|
|
7
|
-
var mask = [/\d/, /\d/, '.', /\d/, /\d/, '.', /\d/, /\d/, /\d/, /\d/];
|
|
8
|
-
function createAutoCorrectedDatePipe(_a, dateFormat) {
|
|
9
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.minYear, minYear = _c === void 0 ? 1800 : _c, _d = _b.maxYear, maxYear = _d === void 0 ? 2100 : _d;
|
|
10
|
-
if (dateFormat === void 0) { dateFormat = 'dd mm yyyy'; }
|
|
11
|
-
var dateFormatArray = dateFormat
|
|
12
|
-
.split(/[^dmyHMS]+/)
|
|
13
|
-
.sort(function (a, b) { return formatOrder.indexOf(a) - formatOrder.indexOf(b); });
|
|
14
|
-
return function (conformedValue) {
|
|
15
|
-
var indexesOfPipedChars = [];
|
|
16
|
-
var maxValue = { dd: 31, mm: 12, yy: 99, yyyy: maxYear, HH: 23, MM: 59, SS: 59 };
|
|
17
|
-
var minValue = { dd: 1, mm: 1, yy: 0, yyyy: minYear, HH: 0, MM: 0, SS: 0 };
|
|
18
|
-
var conformedValueArr = conformedValue.split('');
|
|
19
|
-
// Check first digit
|
|
20
|
-
dateFormatArray.forEach(function (format) {
|
|
21
|
-
var position = dateFormat.indexOf(format);
|
|
22
|
-
var maxFirstDigit = parseInt(maxValue[format].toString().substr(0, 1), 10);
|
|
23
|
-
if (parseInt(conformedValueArr[position], 10) > maxFirstDigit) {
|
|
24
|
-
conformedValueArr[position + 1] = conformedValueArr[position];
|
|
25
|
-
conformedValueArr[position] = '0';
|
|
26
|
-
indexesOfPipedChars.push(position);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
// Check for invalid date
|
|
30
|
-
var month = 0;
|
|
31
|
-
var isInvalid = dateFormatArray.some(function (format) {
|
|
32
|
-
var position = dateFormat.indexOf(format);
|
|
33
|
-
var length = format.length;
|
|
34
|
-
var textValue = conformedValue.substr(position, length).replace(/\D/g, '');
|
|
35
|
-
var value = parseInt(textValue, 10);
|
|
36
|
-
if (format === 'mm') {
|
|
37
|
-
month = value || 0;
|
|
38
|
-
}
|
|
39
|
-
var maxValueForFormat = format === 'dd' ? maxValueMonth[month] : maxValue[format];
|
|
40
|
-
if (format === 'yyyy' && (minYear !== 1 || maxYear !== 9999)) {
|
|
41
|
-
var scopedMaxValue = parseInt(maxValue[format].toString().substring(0, textValue.length), 10);
|
|
42
|
-
var scopedMinValue = parseInt(minValue[format].toString().substring(0, textValue.length), 10);
|
|
43
|
-
return value < scopedMinValue || value > scopedMaxValue;
|
|
44
|
-
}
|
|
45
|
-
return (value > maxValueForFormat ||
|
|
46
|
-
(textValue.length === length && value < minValue[format]));
|
|
47
|
-
});
|
|
48
|
-
if (isInvalid) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
value: conformedValueArr.join(''),
|
|
53
|
-
indexesOfPipedChars: indexesOfPipedChars,
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
exports.createAutoCorrectedDatePipe = createAutoCorrectedDatePipe;
|
|
59
|
-
exports.mask = mask;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
declare const mask: (string | RegExp)[];
|
|
2
|
-
declare function createAutoCorrectedDatePipe({ minYear, maxYear }?: {
|
|
3
|
-
minYear?: number | undefined;
|
|
4
|
-
maxYear?: number | undefined;
|
|
5
|
-
}, dateFormat?: string): (conformedValue: string) => false | {
|
|
6
|
-
value: string;
|
|
7
|
-
indexesOfPipedChars: number[];
|
|
8
|
-
};
|
|
9
|
-
export { mask, createAutoCorrectedDatePipe };
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
var maxValueMonth = [31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
2
|
-
var formatOrder = ['yyyy', 'yy', 'mm', 'dd', 'HH', 'MM', 'SS'];
|
|
3
|
-
var mask = [/\d/, /\d/, '.', /\d/, /\d/, '.', /\d/, /\d/, /\d/, /\d/];
|
|
4
|
-
function createAutoCorrectedDatePipe(_a, dateFormat) {
|
|
5
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.minYear, minYear = _c === void 0 ? 1800 : _c, _d = _b.maxYear, maxYear = _d === void 0 ? 2100 : _d;
|
|
6
|
-
if (dateFormat === void 0) { dateFormat = 'dd mm yyyy'; }
|
|
7
|
-
var dateFormatArray = dateFormat
|
|
8
|
-
.split(/[^dmyHMS]+/)
|
|
9
|
-
.sort(function (a, b) { return formatOrder.indexOf(a) - formatOrder.indexOf(b); });
|
|
10
|
-
return function (conformedValue) {
|
|
11
|
-
var indexesOfPipedChars = [];
|
|
12
|
-
var maxValue = { dd: 31, mm: 12, yy: 99, yyyy: maxYear, HH: 23, MM: 59, SS: 59 };
|
|
13
|
-
var minValue = { dd: 1, mm: 1, yy: 0, yyyy: minYear, HH: 0, MM: 0, SS: 0 };
|
|
14
|
-
var conformedValueArr = conformedValue.split('');
|
|
15
|
-
// Check first digit
|
|
16
|
-
dateFormatArray.forEach(function (format) {
|
|
17
|
-
var position = dateFormat.indexOf(format);
|
|
18
|
-
var maxFirstDigit = parseInt(maxValue[format].toString().substr(0, 1), 10);
|
|
19
|
-
if (parseInt(conformedValueArr[position], 10) > maxFirstDigit) {
|
|
20
|
-
conformedValueArr[position + 1] = conformedValueArr[position];
|
|
21
|
-
conformedValueArr[position] = '0';
|
|
22
|
-
indexesOfPipedChars.push(position);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
// Check for invalid date
|
|
26
|
-
var month = 0;
|
|
27
|
-
var isInvalid = dateFormatArray.some(function (format) {
|
|
28
|
-
var position = dateFormat.indexOf(format);
|
|
29
|
-
var length = format.length;
|
|
30
|
-
var textValue = conformedValue.substr(position, length).replace(/\D/g, '');
|
|
31
|
-
var value = parseInt(textValue, 10);
|
|
32
|
-
if (format === 'mm') {
|
|
33
|
-
month = value || 0;
|
|
34
|
-
}
|
|
35
|
-
var maxValueForFormat = format === 'dd' ? maxValueMonth[month] : maxValue[format];
|
|
36
|
-
if (format === 'yyyy' && (minYear !== 1 || maxYear !== 9999)) {
|
|
37
|
-
var scopedMaxValue = parseInt(maxValue[format].toString().substring(0, textValue.length), 10);
|
|
38
|
-
var scopedMinValue = parseInt(minValue[format].toString().substring(0, textValue.length), 10);
|
|
39
|
-
return value < scopedMinValue || value > scopedMaxValue;
|
|
40
|
-
}
|
|
41
|
-
return (value > maxValueForFormat ||
|
|
42
|
-
(textValue.length === length && value < minValue[format]));
|
|
43
|
-
});
|
|
44
|
-
if (isInvalid) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
value: conformedValueArr.join(''),
|
|
49
|
-
indexesOfPipedChars: indexesOfPipedChars,
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export { createAutoCorrectedDatePipe, mask };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
declare const mask: (string | RegExp)[];
|
|
2
|
-
declare function createAutoCorrectedDatePipe({ minYear, maxYear }?: {
|
|
3
|
-
minYear?: number | undefined;
|
|
4
|
-
maxYear?: number | undefined;
|
|
5
|
-
}, dateFormat?: string): (conformedValue: string) => false | {
|
|
6
|
-
value: string;
|
|
7
|
-
indexesOfPipedChars: number[];
|
|
8
|
-
};
|
|
9
|
-
export { mask, createAutoCorrectedDatePipe };
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
const maxValueMonth = [31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
2
|
-
const formatOrder = ['yyyy', 'yy', 'mm', 'dd', 'HH', 'MM', 'SS'];
|
|
3
|
-
const mask = [/\d/, /\d/, '.', /\d/, /\d/, '.', /\d/, /\d/, /\d/, /\d/];
|
|
4
|
-
function createAutoCorrectedDatePipe({ minYear = 1800, maxYear = 2100 } = {}, dateFormat = 'dd mm yyyy') {
|
|
5
|
-
const dateFormatArray = dateFormat
|
|
6
|
-
.split(/[^dmyHMS]+/)
|
|
7
|
-
.sort((a, b) => formatOrder.indexOf(a) - formatOrder.indexOf(b));
|
|
8
|
-
return (conformedValue) => {
|
|
9
|
-
const indexesOfPipedChars = [];
|
|
10
|
-
const maxValue = { dd: 31, mm: 12, yy: 99, yyyy: maxYear, HH: 23, MM: 59, SS: 59 };
|
|
11
|
-
const minValue = { dd: 1, mm: 1, yy: 0, yyyy: minYear, HH: 0, MM: 0, SS: 0 };
|
|
12
|
-
const conformedValueArr = conformedValue.split('');
|
|
13
|
-
// Check first digit
|
|
14
|
-
dateFormatArray.forEach(format => {
|
|
15
|
-
const position = dateFormat.indexOf(format);
|
|
16
|
-
const maxFirstDigit = parseInt(maxValue[format].toString().substr(0, 1), 10);
|
|
17
|
-
if (parseInt(conformedValueArr[position], 10) > maxFirstDigit) {
|
|
18
|
-
conformedValueArr[position + 1] = conformedValueArr[position];
|
|
19
|
-
conformedValueArr[position] = '0';
|
|
20
|
-
indexesOfPipedChars.push(position);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
// Check for invalid date
|
|
24
|
-
let month = 0;
|
|
25
|
-
const isInvalid = dateFormatArray.some(format => {
|
|
26
|
-
const position = dateFormat.indexOf(format);
|
|
27
|
-
const { length } = format;
|
|
28
|
-
const textValue = conformedValue.substr(position, length).replace(/\D/g, '');
|
|
29
|
-
const value = parseInt(textValue, 10);
|
|
30
|
-
if (format === 'mm') {
|
|
31
|
-
month = value || 0;
|
|
32
|
-
}
|
|
33
|
-
const maxValueForFormat = format === 'dd' ? maxValueMonth[month] : maxValue[format];
|
|
34
|
-
if (format === 'yyyy' && (minYear !== 1 || maxYear !== 9999)) {
|
|
35
|
-
const scopedMaxValue = parseInt(maxValue[format].toString().substring(0, textValue.length), 10);
|
|
36
|
-
const scopedMinValue = parseInt(minValue[format].toString().substring(0, textValue.length), 10);
|
|
37
|
-
return value < scopedMinValue || value > scopedMaxValue;
|
|
38
|
-
}
|
|
39
|
-
return (value > maxValueForFormat ||
|
|
40
|
-
(textValue.length === length && value < minValue[format]));
|
|
41
|
-
});
|
|
42
|
-
if (isInvalid) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
value: conformedValueArr.join(''),
|
|
47
|
-
indexesOfPipedChars,
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export { createAutoCorrectedDatePipe, mask };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
declare const mask: (string | RegExp)[];
|
|
2
|
-
declare function createAutoCorrectedDatePipe({ minYear, maxYear }?: {
|
|
3
|
-
minYear?: number | undefined;
|
|
4
|
-
maxYear?: number | undefined;
|
|
5
|
-
}, dateFormat?: string): (conformedValue: string) => false | {
|
|
6
|
-
value: string;
|
|
7
|
-
indexesOfPipedChars: number[];
|
|
8
|
-
};
|
|
9
|
-
export { mask, createAutoCorrectedDatePipe };
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var maxValueMonth = [31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
6
|
-
var formatOrder = ['yyyy', 'yy', 'mm', 'dd', 'HH', 'MM', 'SS'];
|
|
7
|
-
var mask = [/\d/, /\d/, '.', /\d/, /\d/, '.', /\d/, /\d/, /\d/, /\d/];
|
|
8
|
-
function createAutoCorrectedDatePipe(_a, dateFormat) {
|
|
9
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.minYear, minYear = _c === void 0 ? 1800 : _c, _d = _b.maxYear, maxYear = _d === void 0 ? 2100 : _d;
|
|
10
|
-
if (dateFormat === void 0) { dateFormat = 'dd mm yyyy'; }
|
|
11
|
-
var dateFormatArray = dateFormat
|
|
12
|
-
.split(/[^dmyHMS]+/)
|
|
13
|
-
.sort(function (a, b) { return formatOrder.indexOf(a) - formatOrder.indexOf(b); });
|
|
14
|
-
return function (conformedValue) {
|
|
15
|
-
var indexesOfPipedChars = [];
|
|
16
|
-
var maxValue = { dd: 31, mm: 12, yy: 99, yyyy: maxYear, HH: 23, MM: 59, SS: 59 };
|
|
17
|
-
var minValue = { dd: 1, mm: 1, yy: 0, yyyy: minYear, HH: 0, MM: 0, SS: 0 };
|
|
18
|
-
var conformedValueArr = conformedValue.split('');
|
|
19
|
-
// Check first digit
|
|
20
|
-
dateFormatArray.forEach(function (format) {
|
|
21
|
-
var position = dateFormat.indexOf(format);
|
|
22
|
-
var maxFirstDigit = parseInt(maxValue[format].toString().substr(0, 1), 10);
|
|
23
|
-
if (parseInt(conformedValueArr[position], 10) > maxFirstDigit) {
|
|
24
|
-
conformedValueArr[position + 1] = conformedValueArr[position];
|
|
25
|
-
conformedValueArr[position] = '0';
|
|
26
|
-
indexesOfPipedChars.push(position);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
// Check for invalid date
|
|
30
|
-
var month = 0;
|
|
31
|
-
var isInvalid = dateFormatArray.some(function (format) {
|
|
32
|
-
var position = dateFormat.indexOf(format);
|
|
33
|
-
var length = format.length;
|
|
34
|
-
var textValue = conformedValue.substr(position, length).replace(/\D/g, '');
|
|
35
|
-
var value = parseInt(textValue, 10);
|
|
36
|
-
if (format === 'mm') {
|
|
37
|
-
month = value || 0;
|
|
38
|
-
}
|
|
39
|
-
var maxValueForFormat = format === 'dd' ? maxValueMonth[month] : maxValue[format];
|
|
40
|
-
if (format === 'yyyy' && (minYear !== 1 || maxYear !== 9999)) {
|
|
41
|
-
var scopedMaxValue = parseInt(maxValue[format].toString().substring(0, textValue.length), 10);
|
|
42
|
-
var scopedMinValue = parseInt(minValue[format].toString().substring(0, textValue.length), 10);
|
|
43
|
-
return value < scopedMinValue || value > scopedMaxValue;
|
|
44
|
-
}
|
|
45
|
-
return (value > maxValueForFormat ||
|
|
46
|
-
(textValue.length === length && value < minValue[format]));
|
|
47
|
-
});
|
|
48
|
-
if (isInvalid) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
value: conformedValueArr.join(''),
|
|
53
|
-
indexesOfPipedChars: indexesOfPipedChars,
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
exports.createAutoCorrectedDatePipe = createAutoCorrectedDatePipe;
|
|
59
|
-
exports.mask = mask;
|