@bolttech/form-engine-core 0.0.2-beta.3 → 0.0.2-beta.4
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/index.esm.js +27 -38
- package/package.json +1 -1
package/index.esm.js
CHANGED
|
@@ -1962,16 +1962,6 @@ const conditions = (value, validations) => {
|
|
|
1962
1962
|
return !result;
|
|
1963
1963
|
};
|
|
1964
1964
|
|
|
1965
|
-
/**
|
|
1966
|
-
* @internal
|
|
1967
|
-
* Parses date value to avoid type format errors.
|
|
1968
|
-
*
|
|
1969
|
-
* @param {string} value - the value to be parsed into a valid date.
|
|
1970
|
-
* @returns {string | null} - returns a pareable string format or null to handle validation exceptions.
|
|
1971
|
-
*/
|
|
1972
|
-
const parseDateValue = value => {
|
|
1973
|
-
return (value === null || value === void 0 ? void 0 : value.toString()) ? value.toString() : null;
|
|
1974
|
-
};
|
|
1975
1965
|
/**
|
|
1976
1966
|
* @internal
|
|
1977
1967
|
* Validates if a date string matches a specific date format.
|
|
@@ -1996,7 +1986,6 @@ const parseDateValue = value => {
|
|
|
1996
1986
|
* invalidStringDate("1997/25/07", "MMDDYYYY");
|
|
1997
1987
|
*/
|
|
1998
1988
|
const invalidStringDate = (value, format) => {
|
|
1999
|
-
if (parseDateValue(value) === null) return false;
|
|
2000
1989
|
if (!value.includes('/') && !value.includes('-') || !format) {
|
|
2001
1990
|
return true;
|
|
2002
1991
|
}
|
|
@@ -2049,21 +2038,15 @@ const getIntervalsDate = (date, intervals) => {
|
|
|
2049
2038
|
* console.log(formattedDate2); // '12/01/2023'
|
|
2050
2039
|
*/
|
|
2051
2040
|
const dateRearrangeMapper = {
|
|
2052
|
-
DDMMYYYY:
|
|
2053
|
-
const value = parseDateValue(val);
|
|
2054
|
-
if (value === null) return '';
|
|
2041
|
+
DDMMYYYY: value => {
|
|
2055
2042
|
const dateParts = value.split(value.includes('/') ? '/' : '-');
|
|
2056
2043
|
return `${dateParts[1]}/${dateParts[0]}/${dateParts[2]}`;
|
|
2057
2044
|
},
|
|
2058
|
-
YYYYMMDD:
|
|
2059
|
-
const value = parseDateValue(val);
|
|
2060
|
-
if (value === null) return '';
|
|
2045
|
+
YYYYMMDD: value => {
|
|
2061
2046
|
const dateParts = value.split(value.includes('/') ? '/' : '-');
|
|
2062
2047
|
return `${dateParts[1]}/${dateParts[2]}/${dateParts[0]}`;
|
|
2063
2048
|
},
|
|
2064
|
-
YYYYDDMM:
|
|
2065
|
-
const value = parseDateValue(val);
|
|
2066
|
-
if (value === null) return '';
|
|
2049
|
+
YYYYDDMM: value => {
|
|
2067
2050
|
const dateParts = value.split(value.includes('/') ? '/' : '-');
|
|
2068
2051
|
return `${dateParts[2]}/${dateParts[1]}/${dateParts[0]}`;
|
|
2069
2052
|
},
|
|
@@ -2096,7 +2079,6 @@ const dateRearrangeMapper = {
|
|
|
2096
2079
|
*/
|
|
2097
2080
|
const betweenDates = (value, validations) => {
|
|
2098
2081
|
var _a;
|
|
2099
|
-
if (parseDateValue(value) === null) return false;
|
|
2100
2082
|
let fail = false;
|
|
2101
2083
|
if (((_a = validations.betweenDates) === null || _a === void 0 ? void 0 : _a.length) != 2) return false;
|
|
2102
2084
|
for (const validation of validations.betweenDates) {
|
|
@@ -2142,27 +2124,23 @@ const betweenDates = (value, validations) => {
|
|
|
2142
2124
|
* ```
|
|
2143
2125
|
*/
|
|
2144
2126
|
const date = (value, validations) => {
|
|
2145
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m
|
|
2146
|
-
if (parseDateValue(value) === null) return true;
|
|
2127
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
2147
2128
|
if (!((_b = (_a = validations.date) === null || _a === void 0 ? void 0 : _a.target) === null || _b === void 0 ? void 0 : _b.value) && !((_d = (_c = validations.date) === null || _c === void 0 ? void 0 : _c.origin) === null || _d === void 0 ? void 0 : _d.intervals)) {
|
|
2148
2129
|
return false;
|
|
2149
2130
|
}
|
|
2150
|
-
const originValue =
|
|
2151
|
-
if (originValue === null) return false;
|
|
2131
|
+
const originValue = validations.date.origin.value || value;
|
|
2152
2132
|
const mappedValue = dateRearrangeMapper[(_e = validations.date) === null || _e === void 0 ? void 0 : _e.origin.format](originValue).toString();
|
|
2153
2133
|
let originDate = new Date(mappedValue);
|
|
2154
2134
|
let targetDate = new Date();
|
|
2155
2135
|
let target = new Date();
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
if ((_j = (_h = validations.date) === null || _h === void 0 ? void 0 : _h.target) === null || _j === void 0 ? void 0 : _j.format) {
|
|
2159
|
-
target = new Date(dateRearrangeMapper[(_l = (_k = validations.date) === null || _k === void 0 ? void 0 : _k.target) === null || _l === void 0 ? void 0 : _l.format](targetValue).toString());
|
|
2136
|
+
if ((_g = (_f = validations.date) === null || _f === void 0 ? void 0 : _f.target) === null || _g === void 0 ? void 0 : _g.format) {
|
|
2137
|
+
target = new Date(dateRearrangeMapper[(_j = (_h = validations.date) === null || _h === void 0 ? void 0 : _h.target) === null || _j === void 0 ? void 0 : _j.format](validations.date.target.value).toString());
|
|
2160
2138
|
targetDate = target;
|
|
2161
2139
|
}
|
|
2162
2140
|
if (validations.date.origin.intervals) {
|
|
2163
2141
|
targetDate = getIntervalsDate(originDate, validations.date.origin.intervals);
|
|
2164
2142
|
const date = new Date();
|
|
2165
|
-
if (((
|
|
2143
|
+
if (((_k = validations.date.target) === null || _k === void 0 ? void 0 : _k.value) && target) {
|
|
2166
2144
|
date.setDate(target.getDate());
|
|
2167
2145
|
date.setMonth(target.getMonth());
|
|
2168
2146
|
}
|
|
@@ -2171,7 +2149,7 @@ const date = (value, validations) => {
|
|
|
2171
2149
|
if (validations.date.onlyValidDate && (!(targetDate instanceof Date && isFinite(targetDate)) || !(targetDate instanceof Date && isFinite(originDate)) || originValue.length < 8)) {
|
|
2172
2150
|
return true;
|
|
2173
2151
|
}
|
|
2174
|
-
if (invalidStringDate(mappedValue, (
|
|
2152
|
+
if (invalidStringDate(mappedValue, (_l = validations.date) === null || _l === void 0 ? void 0 : _l.origin.format)) {
|
|
2175
2153
|
return false;
|
|
2176
2154
|
}
|
|
2177
2155
|
const originTimestamp = originDate.getTime();
|
|
@@ -2184,7 +2162,7 @@ const date = (value, validations) => {
|
|
|
2184
2162
|
'===': originTimestamp === targetTimestamp,
|
|
2185
2163
|
'!==': originTimestamp !== targetTimestamp
|
|
2186
2164
|
};
|
|
2187
|
-
return operationsMapper[(
|
|
2165
|
+
return operationsMapper[(_m = validations.date) === null || _m === void 0 ? void 0 : _m.operator];
|
|
2188
2166
|
};
|
|
2189
2167
|
/**
|
|
2190
2168
|
* @function validDate
|
|
@@ -2206,7 +2184,6 @@ const date = (value, validations) => {
|
|
|
2206
2184
|
* ```
|
|
2207
2185
|
*/
|
|
2208
2186
|
const validDate = (value, validations) => {
|
|
2209
|
-
if (parseDateValue(value) === null) return false;
|
|
2210
2187
|
if (!validations.validDate || !value) return false;
|
|
2211
2188
|
if (/[^a-zA-Z0-9\s-]/.test(value)) return true;
|
|
2212
2189
|
const dateParts = dateRearrangeMapper[validations.validDate](value).toString().split(/[/-]/);
|
|
@@ -3279,9 +3256,12 @@ class FormCore {
|
|
|
3279
3256
|
const result = splittedString.map(splittedStringVal => {
|
|
3280
3257
|
// skip operator logic parsing and pass element directly
|
|
3281
3258
|
if (splittedStringVal.length <= 1) {
|
|
3282
|
-
return
|
|
3259
|
+
return {
|
|
3260
|
+
parse: false,
|
|
3261
|
+
value: getTemplateValue(splittedStringVal[0])
|
|
3262
|
+
};
|
|
3283
3263
|
}
|
|
3284
|
-
|
|
3264
|
+
const value = splittedStringVal.filter(Boolean).reduce((acc, curr) => {
|
|
3285
3265
|
if (curr.match(TEMPLATE_REGEX_OPERATOR_MATCHER)) {
|
|
3286
3266
|
return `${acc}${curr}`;
|
|
3287
3267
|
}
|
|
@@ -3320,12 +3300,21 @@ class FormCore {
|
|
|
3320
3300
|
}
|
|
3321
3301
|
return `${acc}${value}`;
|
|
3322
3302
|
}, '');
|
|
3303
|
+
return {
|
|
3304
|
+
parse: true,
|
|
3305
|
+
value
|
|
3306
|
+
};
|
|
3323
3307
|
});
|
|
3324
|
-
return result.map(
|
|
3308
|
+
return result.map(({
|
|
3309
|
+
parse,
|
|
3310
|
+
value
|
|
3311
|
+
}) => {
|
|
3325
3312
|
try {
|
|
3326
|
-
return new Function(`return ${
|
|
3313
|
+
return parse ? new Function(`return ${value}`)() : value;
|
|
3327
3314
|
} catch (_a) {
|
|
3328
|
-
|
|
3315
|
+
console.warn(`unhandled parsing on ${expression} returning`);
|
|
3316
|
+
console.warn(value);
|
|
3317
|
+
return value;
|
|
3329
3318
|
}
|
|
3330
3319
|
});
|
|
3331
3320
|
}
|