@nattyjs/validation-decorators 0.0.1-beta.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/README.md +11 -0
- package/dist/index.cjs +1589 -0
- package/dist/index.d.ts +404 -0
- package/dist/index.mjs +1515 -0
- package/package.json +20 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1589 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const ValidatorNames = {
|
|
6
|
+
required: "required",
|
|
7
|
+
allOf: "allOf",
|
|
8
|
+
alpha: "alpha",
|
|
9
|
+
alphaNumeric: "alphaNumeric",
|
|
10
|
+
ascii: "ascii",
|
|
11
|
+
contains: "contains",
|
|
12
|
+
creditCard: "creditCard",
|
|
13
|
+
cusip: "cusip",
|
|
14
|
+
dataUri: "dataUri",
|
|
15
|
+
date: "date",
|
|
16
|
+
different: "different",
|
|
17
|
+
digit: "digit",
|
|
18
|
+
email: "email",
|
|
19
|
+
endsWith: "endsWith",
|
|
20
|
+
even: "even",
|
|
21
|
+
extension: "extension",
|
|
22
|
+
factor: "factor",
|
|
23
|
+
file: "file",
|
|
24
|
+
fileSize: "fileSize",
|
|
25
|
+
greaterThan: "greaterThan",
|
|
26
|
+
greaterThanEqualTo: "greaterThanEqualTo",
|
|
27
|
+
grid: "grid",
|
|
28
|
+
hexColor: "hexColor",
|
|
29
|
+
iban: "iban",
|
|
30
|
+
ip: "ip",
|
|
31
|
+
json: "json",
|
|
32
|
+
latitude: "latitude",
|
|
33
|
+
latLong: "latLong",
|
|
34
|
+
leapYear: "leapYear",
|
|
35
|
+
lessThanEqualTo: "lessThanEqualTo",
|
|
36
|
+
lessThan: "lessThan",
|
|
37
|
+
longitude: "longitude",
|
|
38
|
+
lowercase: "lowercase",
|
|
39
|
+
mac: "mac",
|
|
40
|
+
mask: "mask",
|
|
41
|
+
maxDate: "maxDate",
|
|
42
|
+
maxLength: "maxLength",
|
|
43
|
+
maxNumber: "maxNumber",
|
|
44
|
+
maxTime: "maxTime",
|
|
45
|
+
minDate: "minDate",
|
|
46
|
+
minLength: "minLength",
|
|
47
|
+
minNumber: "minNumber",
|
|
48
|
+
minTime: "minTime",
|
|
49
|
+
noneOf: "noneOf",
|
|
50
|
+
notEmpty: "notEmpty",
|
|
51
|
+
numeric: "numeric",
|
|
52
|
+
odd: "odd",
|
|
53
|
+
oneOf: "oneOf",
|
|
54
|
+
password: "password",
|
|
55
|
+
pattern: "pattern",
|
|
56
|
+
port: "port",
|
|
57
|
+
primeNumber: "primeNumber",
|
|
58
|
+
range: "range",
|
|
59
|
+
requiredTrue: "requiredTrue",
|
|
60
|
+
startsWith: "startsWith",
|
|
61
|
+
time: "time",
|
|
62
|
+
uppercase: "uppercase",
|
|
63
|
+
url: "url"
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const validationForms = new class {
|
|
67
|
+
configure(config) {
|
|
68
|
+
this.formConfig = config;
|
|
69
|
+
}
|
|
70
|
+
}();
|
|
71
|
+
|
|
72
|
+
class ValidationMessage {
|
|
73
|
+
static getValidatorErrorMessage(name) {
|
|
74
|
+
let message = "";
|
|
75
|
+
if (validationForms.formConfig)
|
|
76
|
+
message = validationForms.formConfig.errorMessage.validator[name];
|
|
77
|
+
return message;
|
|
78
|
+
}
|
|
79
|
+
static toJson(key, config, values) {
|
|
80
|
+
let message = config ? config.message : null;
|
|
81
|
+
if (!message && config && config.messageKey)
|
|
82
|
+
config.messageKey;
|
|
83
|
+
let messageText = message ? message : config.messagekey ? ValidationMessage.getValidatorErrorMessage(config.messageKey) : ValidationMessage.getValidatorErrorMessage(key);
|
|
84
|
+
messageText = messageText || "";
|
|
85
|
+
values.forEach((t, index) => {
|
|
86
|
+
messageText = messageText.replace(`{{${index}}}`, t);
|
|
87
|
+
});
|
|
88
|
+
let jObject = {};
|
|
89
|
+
jObject[key] = {
|
|
90
|
+
message: messageText,
|
|
91
|
+
refValues: values
|
|
92
|
+
};
|
|
93
|
+
return jObject;
|
|
94
|
+
}
|
|
95
|
+
static null() {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function getConfigObject(config) {
|
|
101
|
+
return config || {};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const RegExRule = {
|
|
105
|
+
alpha: /^[a-zA-Z]+$/,
|
|
106
|
+
alphaExits: /[a-zA-Z]/,
|
|
107
|
+
alphaWithSpace: /^[a-zA-Z\s]+$/,
|
|
108
|
+
macId: /^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/,
|
|
109
|
+
onlyDigit: /^[0-9]+$/,
|
|
110
|
+
isDigitExits: /[0-9]/,
|
|
111
|
+
lowerCase: /[a-z]/,
|
|
112
|
+
upperCase: /[A-Z]/,
|
|
113
|
+
specialCharacter: /[!@#$%^&*(),.?":{}|<>]/,
|
|
114
|
+
advancedEmail: /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,
|
|
115
|
+
basicEmail: /^(([^<>()\[\]\\.,,:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
|
116
|
+
alphaNumeric: /^[0-9a-zA-Z]+$/,
|
|
117
|
+
alphaNumericWithSpace: /^[0-9a-zA-Z\s]+$/,
|
|
118
|
+
hexColor: /^#?([0-9A-F]{3}|[0-9A-F]{6})$/i,
|
|
119
|
+
strictHexColor: /^#?([0-9A-F]{3}|[0-9A-F]{6})$/i,
|
|
120
|
+
float: /^(?:[-+]?(?:[0-9]+))?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/,
|
|
121
|
+
decimal: /^[-+]?([0-9]+|\.[0-9]+|[0-9]+\.[0-9]+)$/,
|
|
122
|
+
hexaDecimal: /^[0-9A-F]+$/i,
|
|
123
|
+
date: /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,
|
|
124
|
+
time: /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/,
|
|
125
|
+
timeWithSeconds: /^([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/,
|
|
126
|
+
url: /^(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9]\.[^\s]{2,})$/,
|
|
127
|
+
ascii: /^[\x00-\x7F]+$/,
|
|
128
|
+
dataUri: /^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s]*?)$/i,
|
|
129
|
+
lat: /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/,
|
|
130
|
+
long: /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/,
|
|
131
|
+
ipV4: /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/,
|
|
132
|
+
ipV6: /^((?:[a-fA-F\d]{1,4}:){7}(?:[a-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|:[a-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(:[a-fA-F\d]{1,4}){1,2}|:)|(?:[a-fA-F\d]{1,4}:){4}(?:(:[a-fA-F\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(:[a-fA-F\d]{1,4}){1,3}|:)|(?:[a-fA-F\d]{1,4}:){3}(?:(:[a-fA-F\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(:[a-fA-F\d]{1,4}){1,4}|:)|(?:[a-fA-F\d]{1,4}:){2}(?:(:[a-fA-F\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(:[a-fA-F\d]{1,4}){1,5}|:)|(?:[a-fA-F\d]{1,4}:){1}(?:(:[a-fA-F\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(:[a-fA-F\d]{1,4}){1,6}|:)|(?::((?::[a-fA-F\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,7}|:)))(%[0-9a-zA-Z]{1,})?$/,
|
|
133
|
+
cidrV4: /^(3[0-2]|[12]?[0-9])$/,
|
|
134
|
+
cidrV6: /^(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
|
|
135
|
+
cusip: /^[0-9A-Z]{9}$/,
|
|
136
|
+
grid: /^[GRID:]*([0-9A-Z]{2})[-\s]*([0-9A-Z]{5})[-\s]*([0-9A-Z]{10})[-\s]*([0-9A-Z]{1})$/g
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const ALPHABET = "alphabet";
|
|
140
|
+
const DIGIT = "digit";
|
|
141
|
+
const CONTAINS = "contains";
|
|
142
|
+
const LOWERCASE = "lowerCase";
|
|
143
|
+
const UPPERCASE = "upperCase";
|
|
144
|
+
const SPECIAL_CHARACTER = "specialCharacter";
|
|
145
|
+
const MIN_LENGTH = "minLength";
|
|
146
|
+
const MAX_LENGTH = "maxLength";
|
|
147
|
+
class RegexValidator {
|
|
148
|
+
static isExits(value, regex) {
|
|
149
|
+
return value.match(regex) != null;
|
|
150
|
+
}
|
|
151
|
+
static isValid(value, regex) {
|
|
152
|
+
return regex.test(value);
|
|
153
|
+
}
|
|
154
|
+
static isNotBlank(value, isRemoveSpace = false) {
|
|
155
|
+
return !isRemoveSpace ? value === 0 || value !== void 0 && value !== null && value !== "" : value === 0 || value !== void 0 && value !== null && String(value).trim() !== "";
|
|
156
|
+
}
|
|
157
|
+
static isValidPassword(passwordValidation, value) {
|
|
158
|
+
let isValid = false;
|
|
159
|
+
let keyName = "status";
|
|
160
|
+
let objectProperties = Object.getOwnPropertyNames(passwordValidation);
|
|
161
|
+
for (let propertyName of objectProperties) {
|
|
162
|
+
switch (propertyName) {
|
|
163
|
+
case ALPHABET:
|
|
164
|
+
isValid = RegexValidator.isExits(value, RegExRule.alphaExits);
|
|
165
|
+
keyName = ALPHABET;
|
|
166
|
+
break;
|
|
167
|
+
case DIGIT:
|
|
168
|
+
isValid = RegexValidator.isValid(value, RegExRule.isDigitExits);
|
|
169
|
+
keyName = DIGIT;
|
|
170
|
+
break;
|
|
171
|
+
case CONTAINS:
|
|
172
|
+
isValid = value.indexOf(passwordValidation[CONTAINS]) != -1;
|
|
173
|
+
keyName = CONTAINS;
|
|
174
|
+
break;
|
|
175
|
+
case LOWERCASE:
|
|
176
|
+
isValid = RegexValidator.isValid(value, RegExRule.lowerCase);
|
|
177
|
+
keyName = LOWERCASE;
|
|
178
|
+
break;
|
|
179
|
+
case UPPERCASE:
|
|
180
|
+
isValid = RegexValidator.isValid(value, RegExRule.upperCase);
|
|
181
|
+
keyName = UPPERCASE;
|
|
182
|
+
break;
|
|
183
|
+
case SPECIAL_CHARACTER:
|
|
184
|
+
isValid = RegexValidator.isExits(value, RegExRule.specialCharacter);
|
|
185
|
+
keyName = SPECIAL_CHARACTER;
|
|
186
|
+
break;
|
|
187
|
+
case MIN_LENGTH:
|
|
188
|
+
isValid = value.length >= passwordValidation[propertyName];
|
|
189
|
+
keyName = MIN_LENGTH;
|
|
190
|
+
break;
|
|
191
|
+
case MAX_LENGTH:
|
|
192
|
+
isValid = value.length <= passwordValidation[propertyName];
|
|
193
|
+
keyName = MAX_LENGTH;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
if (!isValid)
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
return { isValid, keyName };
|
|
200
|
+
}
|
|
201
|
+
static isZero(value) {
|
|
202
|
+
return value == 0;
|
|
203
|
+
}
|
|
204
|
+
static commaRegex() {
|
|
205
|
+
return new RegExp(",", "g");
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
class Linq {
|
|
210
|
+
static execute(config, params) {
|
|
211
|
+
if (config.conditionalExpression) {
|
|
212
|
+
return config.conditionalExpression.bind(params.current).call(params.current, params.current, params.root);
|
|
213
|
+
}
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
class ValidatorValueChecker {
|
|
219
|
+
static pass(params, config) {
|
|
220
|
+
if (Linq.execute(config, params))
|
|
221
|
+
return RegexValidator.isNotBlank(params.value);
|
|
222
|
+
else
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
static passArrayValue(params, config) {
|
|
226
|
+
if (Linq.execute(config, params))
|
|
227
|
+
return params.value instanceof Array;
|
|
228
|
+
else
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function alphaValidation(configModel, params, regExps, key) {
|
|
234
|
+
let config = getConfigObject(configModel);
|
|
235
|
+
if (ValidatorValueChecker.pass(params, config)) {
|
|
236
|
+
var isValid = !config || !config.allowWhiteSpace ? RegexValidator.isValid(params.value, regExps[0]) : RegexValidator.isValid(params.value, regExps[1]);
|
|
237
|
+
if (!isValid)
|
|
238
|
+
return ValidationMessage.toJson(key, config, [params.value]);
|
|
239
|
+
}
|
|
240
|
+
return ValidationMessage.null();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function alphaValidator(configModel, params) {
|
|
244
|
+
return alphaValidation(configModel, params, [RegExRule.alpha, RegExRule.alphaWithSpace], ValidatorNames.alpha);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function alphaNumericValidator(configModel, control) {
|
|
248
|
+
return alphaValidation(configModel, control, [RegExRule.alphaNumeric, RegExRule.alphaNumericWithSpace], ValidatorNames.alphaNumeric);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function containsValidator(configModel, control) {
|
|
252
|
+
let config = getConfigObject(configModel);
|
|
253
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
254
|
+
if (control.value.indexOf(config.value) == -1)
|
|
255
|
+
return ValidationMessage.toJson(ValidatorNames.contains, config, [control.value, config.value]);
|
|
256
|
+
}
|
|
257
|
+
return ValidationMessage.null();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function calculate(numbers) {
|
|
261
|
+
let numberSum = 0;
|
|
262
|
+
for (var i = 0; i < numbers.length; i++)
|
|
263
|
+
numberSum += parseInt(numbers.substring(i, i + 1));
|
|
264
|
+
let deltas = new Array(0, 1, 2, 3, 4, -4, -3, -2, -1, 0);
|
|
265
|
+
for (var i = numbers.length - 1; i >= 0; i -= 2) {
|
|
266
|
+
numberSum += deltas[parseInt(numbers.substring(i, i + 1))];
|
|
267
|
+
}
|
|
268
|
+
let mod = numberSum % 10;
|
|
269
|
+
mod = 10 - mod;
|
|
270
|
+
if (mod == 10)
|
|
271
|
+
mod = 0;
|
|
272
|
+
return mod;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function checkLength(length, checks) {
|
|
276
|
+
let isPassed = false;
|
|
277
|
+
for (let check of checks) {
|
|
278
|
+
isPassed = check == length;
|
|
279
|
+
if (isPassed)
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
return isPassed;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function creditCardValidator(configModel, control) {
|
|
286
|
+
let cardDigits = {
|
|
287
|
+
AmericanExpress: [15],
|
|
288
|
+
DinersClub: [14, 16, 19],
|
|
289
|
+
Discover: [16, 19],
|
|
290
|
+
JCB: [16, 19],
|
|
291
|
+
Maestro: [12, 16, 19],
|
|
292
|
+
MasterCard: [16],
|
|
293
|
+
Visa: [13, 16, 19]
|
|
294
|
+
};
|
|
295
|
+
function validate(creditCardNumber) {
|
|
296
|
+
var digit = parseInt(creditCardNumber.substring(creditCardNumber.length - 1, creditCardNumber.length));
|
|
297
|
+
return calculate(creditCardNumber.substring(0, creditCardNumber.length - 1)) == parseInt(String(digit)) ? true : false;
|
|
298
|
+
}
|
|
299
|
+
function getCardProviderName(cardNumber) {
|
|
300
|
+
var cardProviderName = "";
|
|
301
|
+
return /^(5018|5020|5038|5612|5893|6304|6759|6761|6762|6763|0604|6390)\d+$/.test(cardNumber) ? cardProviderName = "Maestro" : /^5[1-5]/.test(cardNumber) ? cardProviderName = "MasterCard" : /^4/.test(cardNumber) ? cardProviderName = "Visa" : /^3[47]/.test(cardNumber) ? cardProviderName = "AmericanExpress" : /^(?:2131|1800|35)/.test(cardNumber) ? cardProviderName = "JCB" : /^3(?:0[0-5]|[68])/.test(cardNumber) ? cardProviderName = "DinersClub" : /^6(?:011|5)/.test(cardNumber) && (cardProviderName = "Discover"), cardProviderName;
|
|
302
|
+
}
|
|
303
|
+
const controlValue = control.value;
|
|
304
|
+
let config = getConfigObject(configModel);
|
|
305
|
+
const parentObject = control.current;
|
|
306
|
+
if (Linq.execute(config, control)) {
|
|
307
|
+
if (RegexValidator.isNotBlank(controlValue)) {
|
|
308
|
+
let isValid = false;
|
|
309
|
+
let cardTypes = config.fieldName && parentObject[config.fieldName] ? [parentObject[config.fieldName]] : config.creditCardTypes;
|
|
310
|
+
let cardType = "";
|
|
311
|
+
for (let creditCardType of cardTypes) {
|
|
312
|
+
isValid = checkLength(controlValue.length, cardDigits[creditCardType]) && getCardProviderName(controlValue) == creditCardType && validate(controlValue);
|
|
313
|
+
cardType = creditCardType;
|
|
314
|
+
if (isValid)
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
if (!isValid)
|
|
318
|
+
return ValidationMessage.toJson(ValidatorNames.creditCard, config, [controlValue, cardType]);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return ValidationMessage.null();
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function regexValidation(configModel, control, regExp, key) {
|
|
325
|
+
let config = getConfigObject(configModel);
|
|
326
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
327
|
+
if (!RegexValidator.isValid(control.value, regExp))
|
|
328
|
+
return ValidationMessage.toJson(key, config, [control.value]);
|
|
329
|
+
}
|
|
330
|
+
return ValidationMessage.null();
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function digitValidator(configModel, control) {
|
|
334
|
+
return regexValidation(configModel, control, RegExRule.onlyDigit, ValidatorNames.digit);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function emailValidator(configModel, control) {
|
|
338
|
+
return regexValidation(configModel, control, RegExRule.basicEmail, ValidatorNames.email);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function hexColorValidator(configModel, control) {
|
|
342
|
+
return regexValidation(configModel, control, RegExRule.strictHexColor, ValidatorNames.hexColor);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function lowercaseValidator(configModel, control) {
|
|
346
|
+
let config = getConfigObject(configModel);
|
|
347
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
348
|
+
if (!(control.value === control.value.toLowerCase()))
|
|
349
|
+
return ValidationMessage.toJson(ValidatorNames.lowercase, config, [control.value]);
|
|
350
|
+
}
|
|
351
|
+
return ValidationMessage.null();
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const OPERATORS = {
|
|
355
|
+
lessThan: "<",
|
|
356
|
+
greaterThan: ">",
|
|
357
|
+
lessThanEqualTo: "<=",
|
|
358
|
+
greaterThanEqualTo: ">="
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
const ISO_DATE_REGEX = /^(?:[\+-]?\d{4}(?!\d{2}\b))(?:(-?)(?:(?:0[1-9]|1[0-2])(?:\1(?:[12]\d|0[1-9]|3[01]))?|W(?:[0-4]\d|5[0-2])(?:-?[1-7])?|(?:00[1-9]|0[1-9]\d|[12]\d{2}|3(?:[0-5]\d|6[1-6])))(?:[T\s](?:(?:(?:[01]\d|2[0-3])(?:(:?)[0-5]\d)?|24\:?00)(?:[\.,]\d+(?!:))?)?(?:\2[0-5]\d(?:[\.,]\d+)?)?(?:[zZ]|(?:[\+-])(?:[01]\d|2[0-3]):?(?:[0-5]\d)?)?)?)?$/;
|
|
362
|
+
class DateProvider {
|
|
363
|
+
isDate(value) {
|
|
364
|
+
return value instanceof Date && !isNaN(value.valueOf());
|
|
365
|
+
}
|
|
366
|
+
getRegex(dateFormat) {
|
|
367
|
+
var regExp;
|
|
368
|
+
switch (dateFormat) {
|
|
369
|
+
case "ymd":
|
|
370
|
+
regExp = "^(?:[0-9]{4})-(1[0-2]|0?[1-9])-(3[01]|[12][0-9]|0?[1-9])$";
|
|
371
|
+
break;
|
|
372
|
+
case "dmy":
|
|
373
|
+
regExp = "^(3[01]|[12][0-9]|0?[1-9])-(1[0-2]|0?[1-9])-(?:[0-9]{2})?[0-9]{2}$";
|
|
374
|
+
break;
|
|
375
|
+
case "mdy":
|
|
376
|
+
regExp = "^(1[0-2]|0?[1-9])-(3[01]|[12][0-9]|0?[1-9])-(?:[0-9]{2})?[0-9]{2}$";
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
return new RegExp(regExp);
|
|
380
|
+
}
|
|
381
|
+
regex(config) {
|
|
382
|
+
const regExp = this.getRegex(config.dateFormat || validationForms.formConfig.dateConfig.format);
|
|
383
|
+
return regExp;
|
|
384
|
+
}
|
|
385
|
+
getDate(value, configDateFormat = void 0, isBaseFormat = false) {
|
|
386
|
+
let year, month, day;
|
|
387
|
+
if (!this.isDate(value)) {
|
|
388
|
+
let seperator;
|
|
389
|
+
let dateFormat;
|
|
390
|
+
if (ISO_DATE_REGEX.test(value)) {
|
|
391
|
+
return new Date(value);
|
|
392
|
+
} else {
|
|
393
|
+
seperator = validationForms.formConfig.dateConfig.seperator;
|
|
394
|
+
dateFormat = configDateFormat || validationForms.formConfig.dateConfig.format;
|
|
395
|
+
}
|
|
396
|
+
switch (dateFormat) {
|
|
397
|
+
case "ymd":
|
|
398
|
+
[year, month, day] = value.split(seperator).map((val) => +val);
|
|
399
|
+
break;
|
|
400
|
+
case "dmy":
|
|
401
|
+
[day, month, year] = value.split(seperator).map((val) => +val);
|
|
402
|
+
break;
|
|
403
|
+
case "mdy":
|
|
404
|
+
[month, day, year] = value.split(seperator).map((val) => +val);
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
return new Date(year, month - 1, day);
|
|
408
|
+
} else
|
|
409
|
+
return value;
|
|
410
|
+
}
|
|
411
|
+
isValid(value, config) {
|
|
412
|
+
if (config && config.isValid)
|
|
413
|
+
return config.isValid(value);
|
|
414
|
+
if (typeof value == "string") {
|
|
415
|
+
if (config && config.allowISODate && ISO_DATE_REGEX.test(value))
|
|
416
|
+
return true;
|
|
417
|
+
let seperator = validationForms.formConfig.dateConfig.seperator;
|
|
418
|
+
if (value.split(seperator).length !== 3)
|
|
419
|
+
return false;
|
|
420
|
+
value = value.replace(seperator, "-").replace(seperator, "-");
|
|
421
|
+
return this.regex(config).test(value);
|
|
422
|
+
} else
|
|
423
|
+
return this.isDate(value);
|
|
424
|
+
}
|
|
425
|
+
getConfigDateValue(config) {
|
|
426
|
+
let date = config.value;
|
|
427
|
+
if (config.value && typeof config.value == "string") {
|
|
428
|
+
date = this.getDate(config.value, config.dateFormat, true);
|
|
429
|
+
}
|
|
430
|
+
return date;
|
|
431
|
+
}
|
|
432
|
+
getCompareDate(config, control) {
|
|
433
|
+
let date = this.getConfigDateValue(config);
|
|
434
|
+
if (config.fieldName) {
|
|
435
|
+
let checkControlValue = control.current[config.fieldName];
|
|
436
|
+
if (checkControlValue) {
|
|
437
|
+
date = this.getDate(checkControlValue, config.dateFormat);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return date;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function runCondition$1(leftValue, rightValue, operator) {
|
|
445
|
+
let result = false;
|
|
446
|
+
switch (operator) {
|
|
447
|
+
case OPERATORS.lessThan:
|
|
448
|
+
case OPERATORS.greaterThan:
|
|
449
|
+
result = leftValue > rightValue;
|
|
450
|
+
break;
|
|
451
|
+
case OPERATORS.lessThanEqualTo:
|
|
452
|
+
case OPERATORS.greaterThanEqualTo:
|
|
453
|
+
result = leftValue >= rightValue;
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
return result;
|
|
457
|
+
}
|
|
458
|
+
function dateChecker(control, config, operationType) {
|
|
459
|
+
config = getConfigObject(config);
|
|
460
|
+
var dateProvider = new DateProvider();
|
|
461
|
+
if (Linq.execute(config, control)) {
|
|
462
|
+
if (RegexValidator.isNotBlank(control.value)) {
|
|
463
|
+
if (dateProvider.isDate(control.value) || dateProvider.isValid(control.value, config)) {
|
|
464
|
+
let checkDate = dateProvider.getCompareDate(config, control);
|
|
465
|
+
let currentControlValue = dateProvider.getDate(control.value);
|
|
466
|
+
let isValid = operationType == ValidatorNames.minDate ? runCondition$1(currentControlValue, checkDate, config.operator || OPERATORS.greaterThanEqualTo) : runCondition$1(checkDate, currentControlValue, config.operator || OPERATORS.lessThanEqualTo);
|
|
467
|
+
if (!isValid)
|
|
468
|
+
return ValidationMessage.toJson(operationType, config, [control.value]);
|
|
469
|
+
} else
|
|
470
|
+
return ValidationMessage.toJson(operationType, config, [control.value]);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return ValidationMessage.null();
|
|
474
|
+
}
|
|
475
|
+
function validateDate(control, config, operationType) {
|
|
476
|
+
config = getConfigObject(config);
|
|
477
|
+
var dateProvider = new DateProvider();
|
|
478
|
+
if (Linq.execute(config, control)) {
|
|
479
|
+
if (RegexValidator.isNotBlank(control.value)) {
|
|
480
|
+
if (!dateProvider.isDate(control.value) && !dateProvider.isValid(control.value, config)) {
|
|
481
|
+
return ValidationMessage.toJson(operationType, config, [control.value]);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return ValidationMessage.null();
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function maxDateValidator(configModel, control) {
|
|
489
|
+
return dateChecker(control, configModel, ValidatorNames.maxDate);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
function maxLengthValidator(configModel, control) {
|
|
493
|
+
let config = getConfigObject(configModel);
|
|
494
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
495
|
+
if (!(control.value.length <= config.value))
|
|
496
|
+
return ValidationMessage.toJson(ValidatorNames.maxLength, config, [control.value, config.value]);
|
|
497
|
+
}
|
|
498
|
+
return ValidationMessage.null();
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function maxNumberValidator(configModel, control) {
|
|
502
|
+
let config = getConfigObject(configModel);
|
|
503
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
504
|
+
if (!(parseFloat(control.value) <= config.value))
|
|
505
|
+
return ValidationMessage.toJson(ValidatorNames.maxNumber, config, [control.value, config.value]);
|
|
506
|
+
}
|
|
507
|
+
return ValidationMessage.null();
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function minDateValidator(configModel, control) {
|
|
511
|
+
return dateChecker(control, configModel, ValidatorNames.minDate);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function minLengthValidator(configModel, control) {
|
|
515
|
+
let config = getConfigObject(configModel);
|
|
516
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
517
|
+
if (!(String(control.value).length >= config.value))
|
|
518
|
+
return ValidationMessage.toJson(ValidatorNames.minLength, config, [control.value, config.value]);
|
|
519
|
+
}
|
|
520
|
+
return ValidationMessage.null();
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function minNumberValidator(configModel, control) {
|
|
524
|
+
let config = getConfigObject(configModel);
|
|
525
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
526
|
+
if (!(parseFloat(control.value) >= config.value))
|
|
527
|
+
return ValidationMessage.toJson(ValidatorNames.minNumber, config, [control.value, config.value]);
|
|
528
|
+
}
|
|
529
|
+
return ValidationMessage.null();
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
function passwordValidator(configModel, control) {
|
|
533
|
+
let config = getConfigObject(configModel);
|
|
534
|
+
let controlValue = control.value;
|
|
535
|
+
if (RegexValidator.isNotBlank(controlValue)) {
|
|
536
|
+
let validation = RegexValidator.isValidPassword(config.validation, controlValue);
|
|
537
|
+
if (!validation.isValid)
|
|
538
|
+
return ValidationMessage.toJson(ValidatorNames.password, config, [controlValue]);
|
|
539
|
+
}
|
|
540
|
+
return ValidationMessage.null();
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function rangeValidator(configModel, control) {
|
|
544
|
+
let config = getConfigObject(configModel);
|
|
545
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
546
|
+
if (!(String(control.value).indexOf(".") == -1 && parseInt(control.value) >= config.minimumNumber && parseInt(control.value) <= config.maximumNumber))
|
|
547
|
+
return ValidationMessage.toJson(ValidatorNames.range, config, [control.value, config.minimumNumber, config.maximumNumber]);
|
|
548
|
+
}
|
|
549
|
+
return ValidationMessage.null();
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function uppercaseValidator(configModel, control) {
|
|
553
|
+
let config = getConfigObject(configModel);
|
|
554
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
555
|
+
if (!(control.value === control.value.toUpperCase()))
|
|
556
|
+
return ValidationMessage.toJson(ValidatorNames.uppercase, config, [control.value]);
|
|
557
|
+
}
|
|
558
|
+
return ValidationMessage.null();
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
class Utils {
|
|
562
|
+
static isNotBlank(value, isRemoveSpace = false) {
|
|
563
|
+
return !isRemoveSpace ? value === 0 || value !== void 0 && value !== null && value !== "" : value === 0 || value !== void 0 && value !== null && String(value).trim() !== "";
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
function requiredValidator(config, params) {
|
|
568
|
+
if (Linq.execute(config, params)) {
|
|
569
|
+
if (!Utils.isNotBlank(params.value))
|
|
570
|
+
return ValidationMessage.toJson(ValidatorNames.required, config, []);
|
|
571
|
+
}
|
|
572
|
+
return ValidationMessage.null();
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function patternValidator(configModel, control) {
|
|
576
|
+
let config = getConfigObject(configModel);
|
|
577
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
578
|
+
for (var pattern in config.expression)
|
|
579
|
+
if (!RegexValidator.isValid(control.value, config.expression[pattern]))
|
|
580
|
+
return ValidationMessage.toJson(pattern, { ...config }, [control.value]);
|
|
581
|
+
}
|
|
582
|
+
return ValidationMessage.null();
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function urlValidator(configModel, control) {
|
|
586
|
+
return regexValidation(configModel, control, RegExRule.url, ValidatorNames.url);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
function jsonValidator(configModel, control) {
|
|
590
|
+
function process(value) {
|
|
591
|
+
var result = false;
|
|
592
|
+
try {
|
|
593
|
+
var json = JSON.parse(value);
|
|
594
|
+
result = !!json && typeof json === "object";
|
|
595
|
+
} catch (ex) {
|
|
596
|
+
result = false;
|
|
597
|
+
}
|
|
598
|
+
return result;
|
|
599
|
+
}
|
|
600
|
+
let config = getConfigObject(configModel);
|
|
601
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
602
|
+
if (process(control.value))
|
|
603
|
+
return ValidationMessage.toJson(ValidatorNames.json, config, [control.value]);
|
|
604
|
+
}
|
|
605
|
+
return ValidationMessage.null();
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
function relationalCheck(control, config, relationalOperatorName) {
|
|
609
|
+
config = getConfigObject(config);
|
|
610
|
+
const matchControlValue = config.fieldName ? control.current[config.fieldName] : config.value !== void 0 ? config.value : "";
|
|
611
|
+
if (Linq.execute(config, control)) {
|
|
612
|
+
if (isValid$1(control, matchControlValue, relationalOperatorName) === false)
|
|
613
|
+
return ValidationMessage.toJson(relationalOperatorName, config, [control.value, matchControlValue]);
|
|
614
|
+
}
|
|
615
|
+
return ValidationMessage.null();
|
|
616
|
+
}
|
|
617
|
+
function isValid$1(control, matchControlValue, relationalOperatorName) {
|
|
618
|
+
if (RegexValidator.isNotBlank(control.value) && RegexValidator.isNotBlank(matchControlValue)) {
|
|
619
|
+
let isValid2 = false;
|
|
620
|
+
switch (relationalOperatorName) {
|
|
621
|
+
case ValidatorNames.greaterThan:
|
|
622
|
+
isValid2 = parseFloat(control.value) > parseFloat(matchControlValue);
|
|
623
|
+
break;
|
|
624
|
+
case ValidatorNames.lessThan:
|
|
625
|
+
isValid2 = parseFloat(control.value) < parseFloat(matchControlValue);
|
|
626
|
+
break;
|
|
627
|
+
case ValidatorNames.greaterThanEqualTo:
|
|
628
|
+
isValid2 = parseFloat(control.value) >= parseFloat(matchControlValue);
|
|
629
|
+
break;
|
|
630
|
+
case ValidatorNames.lessThanEqualTo:
|
|
631
|
+
isValid2 = parseFloat(control.value) <= parseFloat(matchControlValue);
|
|
632
|
+
break;
|
|
633
|
+
}
|
|
634
|
+
return isValid2;
|
|
635
|
+
}
|
|
636
|
+
return null;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
function greaterThanValidator(configModel, control) {
|
|
640
|
+
return relationalCheck(control, configModel, ValidatorNames.greaterThan);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function greaterThanEqualToValidator(configModel, control) {
|
|
644
|
+
return relationalCheck(control, configModel, ValidatorNames.greaterThanEqualTo);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
function lessThanEqualToValidator(configModel, control) {
|
|
648
|
+
return relationalCheck(control, configModel, ValidatorNames.lessThanEqualTo);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
function lessThanValidator(configModel, control) {
|
|
652
|
+
return relationalCheck(control, configModel, ValidatorNames.lessThan);
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
function differentValidator(configModel, control) {
|
|
656
|
+
let config = getConfigObject(configModel);
|
|
657
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
658
|
+
const differentControlValue = control.current[config.fieldName];
|
|
659
|
+
if (!(differentControlValue != control.value))
|
|
660
|
+
return ValidationMessage.toJson(ValidatorNames.different, config, [control.value, differentControlValue]);
|
|
661
|
+
}
|
|
662
|
+
return ValidationMessage.null();
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
var NumericValueType = /* @__PURE__ */ ((NumericValueType2) => {
|
|
666
|
+
NumericValueType2[NumericValueType2["PositiveNumber"] = 1] = "PositiveNumber";
|
|
667
|
+
NumericValueType2[NumericValueType2["NegativeNumber"] = 2] = "NegativeNumber";
|
|
668
|
+
NumericValueType2[NumericValueType2["Both"] = 3] = "Both";
|
|
669
|
+
return NumericValueType2;
|
|
670
|
+
})(NumericValueType || {});
|
|
671
|
+
|
|
672
|
+
class ApplicationUtil {
|
|
673
|
+
static toLower(value) {
|
|
674
|
+
if (value)
|
|
675
|
+
return String(value).toLowerCase().trim();
|
|
676
|
+
return value;
|
|
677
|
+
}
|
|
678
|
+
static isNumeric(value) {
|
|
679
|
+
return value - parseFloat(value) + 1 >= 0;
|
|
680
|
+
}
|
|
681
|
+
static notEqualTo(primaryValue, secondaryValue) {
|
|
682
|
+
let firstValue = primaryValue === void 0 || primaryValue === null ? "" : primaryValue;
|
|
683
|
+
let secondValue = secondaryValue === void 0 || secondaryValue === null ? "" : secondaryValue;
|
|
684
|
+
if (firstValue instanceof Date && secondValue instanceof Date)
|
|
685
|
+
return +firstValue != +secondValue;
|
|
686
|
+
return firstValue != secondValue;
|
|
687
|
+
}
|
|
688
|
+
static numericValidation(allowDecimal, acceptValue) {
|
|
689
|
+
acceptValue = acceptValue == void 0 ? NumericValueType.PositiveNumber : acceptValue;
|
|
690
|
+
let regex = /^[0-9]+$/;
|
|
691
|
+
switch (acceptValue) {
|
|
692
|
+
case NumericValueType.PositiveNumber:
|
|
693
|
+
regex = !allowDecimal ? /^[0-9]+$/ : /^[0-9\.]+$/ ;
|
|
694
|
+
break;
|
|
695
|
+
case NumericValueType.NegativeNumber:
|
|
696
|
+
regex = !allowDecimal ? /^[-][0-9]+$/ : /^[-][0-9\.]+$/ ;
|
|
697
|
+
break;
|
|
698
|
+
case NumericValueType.Both:
|
|
699
|
+
regex = !allowDecimal ? /^[-|+]?[0-9]+$/ : /^[-|+]?[0-9\.]+$/ ;
|
|
700
|
+
break;
|
|
701
|
+
}
|
|
702
|
+
return regex;
|
|
703
|
+
}
|
|
704
|
+
static lowerCaseWithTrim(value) {
|
|
705
|
+
return typeof value === "string" ? value.toLowerCase().trim() : String(value).toLowerCase().trim();
|
|
706
|
+
}
|
|
707
|
+
static isObject(value) {
|
|
708
|
+
return Object.prototype.toString.call(value) === "[object Object]";
|
|
709
|
+
}
|
|
710
|
+
static isArray(value) {
|
|
711
|
+
return Array.isArray(value);
|
|
712
|
+
}
|
|
713
|
+
static cloneValue(value) {
|
|
714
|
+
return ApplicationUtil.isObject(value) ? ApplicationUtil.isArray(value) ? [...value] : { ...value } : value;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
function numericValidator(configModel, control) {
|
|
719
|
+
let config = getConfigObject(configModel);
|
|
720
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
721
|
+
if (!RegexValidator.isValid(control.value, ApplicationUtil.numericValidation(config.allowDecimal, config.acceptValue)))
|
|
722
|
+
return ValidationMessage.toJson(ValidatorNames.numeric, config, [control.value]);
|
|
723
|
+
}
|
|
724
|
+
return ValidationMessage.null();
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function evenValidator(configModel, control) {
|
|
728
|
+
let config = getConfigObject(configModel);
|
|
729
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
730
|
+
if (!(control.value % 2 == 0))
|
|
731
|
+
return ValidationMessage.toJson(ValidatorNames.even, config, [control.value]);
|
|
732
|
+
}
|
|
733
|
+
return ValidationMessage.null();
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
function oddValidator(configModel, control) {
|
|
737
|
+
let config = getConfigObject(configModel);
|
|
738
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
739
|
+
if (!!(control.value % 2 == 0) || !ApplicationUtil.isNumeric(control.value))
|
|
740
|
+
return ValidationMessage.toJson(ValidatorNames.odd, config, [control.value]);
|
|
741
|
+
}
|
|
742
|
+
return ValidationMessage.null();
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
function factorValidator(configModel, control) {
|
|
746
|
+
function positiveFactors(dividend2, value) {
|
|
747
|
+
let isPositive = false;
|
|
748
|
+
for (var index = 1; index <= Math.floor(Math.sqrt(dividend2)); index += 1) {
|
|
749
|
+
if (dividend2 % index === 0) {
|
|
750
|
+
if (index == value)
|
|
751
|
+
isPositive = true;
|
|
752
|
+
if (dividend2 / index !== index) {
|
|
753
|
+
if (dividend2 / index == value)
|
|
754
|
+
isPositive = true;
|
|
755
|
+
}
|
|
756
|
+
if (isPositive)
|
|
757
|
+
break;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
return isPositive;
|
|
761
|
+
}
|
|
762
|
+
let config = getConfigObject(configModel);
|
|
763
|
+
const dividend = config.fieldName ? control.current[config.fieldName] : config.dividend;
|
|
764
|
+
if (Linq.execute(config, control)) {
|
|
765
|
+
if (RegexValidator.isNotBlank(control.value) && dividend > 0) {
|
|
766
|
+
if (!RegexValidator.isValid(control.value, RegExRule.onlyDigit) || !positiveFactors(dividend, parseInt(control.value)))
|
|
767
|
+
return ValidationMessage.toJson(ValidatorNames.factor, config, [control.value]);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
return ValidationMessage.null();
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
function leapYearValidator(configModel, control) {
|
|
774
|
+
let config = getConfigObject(configModel);
|
|
775
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
776
|
+
var isValid = control.value % 100 === 0 ? control.value % 400 === 0 : control.value % 4 === 0;
|
|
777
|
+
if (!isValid)
|
|
778
|
+
return ValidationMessage.toJson(ValidatorNames.leapYear, config, [control.value]);
|
|
779
|
+
}
|
|
780
|
+
return ValidationMessage.null();
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
function allOfValidator(configModel, params) {
|
|
784
|
+
let config = getConfigObject(configModel);
|
|
785
|
+
if (ValidatorValueChecker.passArrayValue(params, configModel)) {
|
|
786
|
+
var testResult = false;
|
|
787
|
+
for (let value of config.matchValues) {
|
|
788
|
+
testResult = params.value.some((y) => y == value);
|
|
789
|
+
if (!testResult)
|
|
790
|
+
break;
|
|
791
|
+
}
|
|
792
|
+
if (!testResult)
|
|
793
|
+
return ValidationMessage.toJson(ValidatorNames.allOf, config, [params.value]);
|
|
794
|
+
}
|
|
795
|
+
return ValidationMessage.null();
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
function oneOfValidator(configModel, control) {
|
|
799
|
+
let config = getConfigObject(configModel);
|
|
800
|
+
if (ValidatorValueChecker.passArrayValue(control, config)) {
|
|
801
|
+
var testResult = false;
|
|
802
|
+
for (let value of config.matchValues) {
|
|
803
|
+
testResult = control.value.some((y) => y == value);
|
|
804
|
+
if (testResult)
|
|
805
|
+
break;
|
|
806
|
+
}
|
|
807
|
+
if (!testResult)
|
|
808
|
+
return ValidationMessage.toJson(ValidatorNames.oneOf, config, [control.value]);
|
|
809
|
+
}
|
|
810
|
+
return ValidationMessage.null();
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
function noneOfValidator(configModel, control) {
|
|
814
|
+
let config = getConfigObject(configModel);
|
|
815
|
+
if (Linq.execute(config, control)) {
|
|
816
|
+
var testResult = false;
|
|
817
|
+
for (let value of config.matchValues) {
|
|
818
|
+
let matchValue = ApplicationUtil.lowerCaseWithTrim(value);
|
|
819
|
+
testResult = Array.isArray(control.value) ? control.value.some((y) => ApplicationUtil.lowerCaseWithTrim(y) === matchValue) : ApplicationUtil.lowerCaseWithTrim(control.value) === matchValue;
|
|
820
|
+
if (testResult)
|
|
821
|
+
break;
|
|
822
|
+
}
|
|
823
|
+
if (testResult)
|
|
824
|
+
return ValidationMessage.toJson(ValidatorNames.noneOf, config, [control.value]);
|
|
825
|
+
}
|
|
826
|
+
return ValidationMessage.null();
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
function macValidator(configModel, control) {
|
|
830
|
+
return regexValidation(configModel, control, RegExRule.macId, ValidatorNames.mac);
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
function asciiValidator(configModel, control) {
|
|
834
|
+
return regexValidation(configModel, control, RegExRule.ascii, ValidatorNames.ascii);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
function dataUriValidator(configModel, control) {
|
|
838
|
+
return regexValidation(configModel, control, RegExRule.dataUri, ValidatorNames.dataUri);
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
function portValidator(configModel, control) {
|
|
842
|
+
let config = getConfigObject(configModel);
|
|
843
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
844
|
+
let isValid = RegexValidator.isValid(control.value, RegExRule.onlyDigit) && (control.value >= 0 && control.value <= 65535);
|
|
845
|
+
if (!isValid)
|
|
846
|
+
return ValidationMessage.toJson(ValidatorNames.port, config, [control.value]);
|
|
847
|
+
}
|
|
848
|
+
return ValidationMessage.null();
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
function latLongValidator(configModel, control) {
|
|
852
|
+
let config = getConfigObject(configModel);
|
|
853
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
854
|
+
let splitText = control.value.split(",");
|
|
855
|
+
if (!(splitText.length > 1 && RegexValidator.isValid(splitText[0], RegExRule.lat) && RegexValidator.isValid(splitText[1], RegExRule.long)))
|
|
856
|
+
return ValidationMessage.toJson(ValidatorNames.latLong, config, [control.value]);
|
|
857
|
+
}
|
|
858
|
+
return ValidationMessage.null();
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
function extensionValidator(configModel, control) {
|
|
862
|
+
let config = getConfigObject(configModel);
|
|
863
|
+
if (Linq.execute(config, control)) {
|
|
864
|
+
if (RegexValidator.isNotBlank(control.value)) {
|
|
865
|
+
let testResult = true;
|
|
866
|
+
let extension = "";
|
|
867
|
+
let splitText = control.value.split(".");
|
|
868
|
+
extension = splitText[splitText.length - 1];
|
|
869
|
+
let result = config.extensions.filter((t) => {
|
|
870
|
+
return extension.toLowerCase() == t.toLowerCase();
|
|
871
|
+
})[0];
|
|
872
|
+
if (!result)
|
|
873
|
+
testResult = false;
|
|
874
|
+
if (!testResult)
|
|
875
|
+
return ValidationMessage.toJson(ValidatorNames.extension, config, [extension, config.extensions.join(",")]);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
return ValidationMessage.null();
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
function endsWithValidator(configModel, control) {
|
|
882
|
+
let config = getConfigObject(configModel);
|
|
883
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
884
|
+
var endString = String(control.value).substr(control.value.length - config.value.length, config.value.length);
|
|
885
|
+
if (endString != config.value)
|
|
886
|
+
return ValidationMessage.toJson(ValidatorNames.endsWith, config, [control.value, config.value]);
|
|
887
|
+
}
|
|
888
|
+
return ValidationMessage.null();
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
function startsWithValidator(configModel, control) {
|
|
892
|
+
let config = getConfigObject(configModel);
|
|
893
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
894
|
+
var startString = String(control.value).substr(0, config.value.length);
|
|
895
|
+
if (startString != config.value)
|
|
896
|
+
return ValidationMessage.toJson(ValidatorNames.startsWith, config, [control.value, config.value]);
|
|
897
|
+
}
|
|
898
|
+
return ValidationMessage.null();
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
function primeNumberValidator(configModel, control) {
|
|
902
|
+
function isPrime(value) {
|
|
903
|
+
let isPrimeNumber = value != 1;
|
|
904
|
+
for (var i = 2; i < value; i++) {
|
|
905
|
+
if (value % i == 0) {
|
|
906
|
+
isPrimeNumber = false;
|
|
907
|
+
break;
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
return isPrimeNumber;
|
|
911
|
+
}
|
|
912
|
+
let config = getConfigObject(configModel);
|
|
913
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
914
|
+
if (!ApplicationUtil.isNumeric(control.value) || !isPrime(control.value))
|
|
915
|
+
return ValidationMessage.toJson(ValidatorNames.primeNumber, config, [control.value]);
|
|
916
|
+
}
|
|
917
|
+
return ValidationMessage.null();
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
function latitudeValidator(configModel, control) {
|
|
921
|
+
return regexValidation(configModel, control, RegExRule.lat, ValidatorNames.latitude);
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
function longitudeValidator(configModel, control) {
|
|
925
|
+
return regexValidation(configModel, control, RegExRule.long, ValidatorNames.longitude);
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
function notEmptyValidator(configModel, control) {
|
|
929
|
+
let config = getConfigObject(configModel);
|
|
930
|
+
if (Linq.execute(config, control)) {
|
|
931
|
+
if (!RegexValidator.isNotBlank(control.value, true)) {
|
|
932
|
+
return ValidationMessage.toJson(ValidatorNames.notEmpty, config, []);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
return ValidationMessage.null();
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
var IpVersion = /* @__PURE__ */ ((IpVersion2) => {
|
|
939
|
+
IpVersion2[IpVersion2["V4"] = 1] = "V4";
|
|
940
|
+
IpVersion2[IpVersion2["V6"] = 2] = "V6";
|
|
941
|
+
IpVersion2[IpVersion2["AnyOne"] = 3] = "AnyOne";
|
|
942
|
+
return IpVersion2;
|
|
943
|
+
})(IpVersion || {});
|
|
944
|
+
|
|
945
|
+
function checkIpV4(value) {
|
|
946
|
+
let isValid = RegexValidator.isValid(value, RegExRule.ipV4);
|
|
947
|
+
if (isValid) {
|
|
948
|
+
const splitDots = value.split(".");
|
|
949
|
+
for (let ipNum of splitDots) {
|
|
950
|
+
isValid = ipNum <= 255;
|
|
951
|
+
if (!isValid)
|
|
952
|
+
break;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
return isValid;
|
|
956
|
+
}
|
|
957
|
+
function checkIpV6(value) {
|
|
958
|
+
return RegexValidator.isValid(value, RegExRule.ipV6);
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
function ipValidator(configModel, control) {
|
|
962
|
+
let config = getConfigObject(configModel);
|
|
963
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
964
|
+
let values = config.isCidr ? control.value.split("/") : [control.value];
|
|
965
|
+
var isValid = config.version == IpVersion.V4 ? checkIpV4(values[0]) : config.version == IpVersion.V6 ? checkIpV6(values[0]) : checkIpV4(values[0]) || checkIpV6(values[0]);
|
|
966
|
+
if (config.isCidr && isValid) {
|
|
967
|
+
isValid = values.length > 1 ? config.version == IpVersion.V4 ? RegexValidator.isValid(values[1], RegExRule.cidrV4) : config.version == IpVersion.V6 ? RegexValidator.isValid(values[1], RegExRule.cidrV6) : RegexValidator.isValid(values[1], RegExRule.cidrV4) || RegexValidator.isValid(values[1], RegExRule.cidrV6) : false;
|
|
968
|
+
}
|
|
969
|
+
if (!isValid)
|
|
970
|
+
return ValidationMessage.toJson(ValidatorNames.ip, config, [control.value]);
|
|
971
|
+
}
|
|
972
|
+
return ValidationMessage.null();
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
function cusipValidator(configModel, control) {
|
|
976
|
+
let config = getConfigObject(configModel);
|
|
977
|
+
if (ValidatorValueChecker.pass(control, config)) {
|
|
978
|
+
var controlValue = control.value.toUpperCase();
|
|
979
|
+
let isValid = RegexValidator.isValid(controlValue, RegExRule.cusip);
|
|
980
|
+
if (isValid) {
|
|
981
|
+
let numericValues = controlValue.split("").map((value) => {
|
|
982
|
+
var charCode = value.charCodeAt(0);
|
|
983
|
+
return charCode >= "A".charCodeAt(0) && charCode <= "Z".charCodeAt(0) ? charCode - "A".charCodeAt(0) + 10 : value;
|
|
984
|
+
});
|
|
985
|
+
let totalCount = 0;
|
|
986
|
+
for (var i = 0; i < numericValues.length - 1; i++) {
|
|
987
|
+
var numericValue = parseInt(numericValues[i], 10);
|
|
988
|
+
if (i % 2 !== 0) {
|
|
989
|
+
numericValue *= 2;
|
|
990
|
+
}
|
|
991
|
+
if (numericValue > 9) {
|
|
992
|
+
numericValue -= 9;
|
|
993
|
+
}
|
|
994
|
+
totalCount += numericValue;
|
|
995
|
+
}
|
|
996
|
+
totalCount = (10 - totalCount % 10) % 10;
|
|
997
|
+
isValid = totalCount == numericValues[numericValues.length - 1];
|
|
998
|
+
}
|
|
999
|
+
if (!isValid)
|
|
1000
|
+
return ValidationMessage.toJson(ValidatorNames.cusip, config, [control.value]);
|
|
1001
|
+
}
|
|
1002
|
+
return ValidationMessage.null();
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
function dateValidator(configModel, control) {
|
|
1006
|
+
return validateDate(control, configModel, ValidatorNames.date);
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
function runCondition(leftValue, rightValue, operator) {
|
|
1010
|
+
let result = false;
|
|
1011
|
+
switch (operator) {
|
|
1012
|
+
case OPERATORS.lessThan:
|
|
1013
|
+
case OPERATORS.greaterThan:
|
|
1014
|
+
result = leftValue > rightValue;
|
|
1015
|
+
break;
|
|
1016
|
+
case OPERATORS.lessThanEqualTo:
|
|
1017
|
+
case OPERATORS.greaterThanEqualTo:
|
|
1018
|
+
result = leftValue >= rightValue;
|
|
1019
|
+
break;
|
|
1020
|
+
}
|
|
1021
|
+
return result;
|
|
1022
|
+
}
|
|
1023
|
+
function isValid(control, config) {
|
|
1024
|
+
return config.allowSeconds ? RegexValidator.isValid(control.value, RegExRule.timeWithSeconds) : RegexValidator.isValid(control.value, RegExRule.time);
|
|
1025
|
+
}
|
|
1026
|
+
function getTime(value) {
|
|
1027
|
+
let splitTime = value ? value.split(":") : [];
|
|
1028
|
+
return new Date(1970, 0, 1, splitTime[0] ? splitTime[0] : 0, splitTime[1] ? splitTime[1] : 0, splitTime[2] ? splitTime[2] : 0).getTime();
|
|
1029
|
+
}
|
|
1030
|
+
function timeChecker(control, config, operationType) {
|
|
1031
|
+
config = getConfigObject(config);
|
|
1032
|
+
if (Linq.execute(config, control)) {
|
|
1033
|
+
if (RegexValidator.isNotBlank(control.value)) {
|
|
1034
|
+
if (isValid(control, config)) {
|
|
1035
|
+
let crossControlValue = config.fieldName ? getTime(control.current[config.fieldName]) : getTime(config.value);
|
|
1036
|
+
let currentControlValue = getTime(control.value);
|
|
1037
|
+
let isValid2 = operationType == ValidatorNames.minTime ? runCondition(currentControlValue, crossControlValue, config.operator || OPERATORS.greaterThanEqualTo) : runCondition(crossControlValue, currentControlValue, config.operator || OPERATORS.lessThanEqualTo);
|
|
1038
|
+
if (!isValid2)
|
|
1039
|
+
return ValidationMessage.toJson(operationType, config, [control.value]);
|
|
1040
|
+
} else
|
|
1041
|
+
return ValidationMessage.toJson(operationType, config, [control.value]);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
return ValidationMessage.null();
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
function minTimeValidator(configModel, control) {
|
|
1048
|
+
return timeChecker(control, configModel, ValidatorNames.minTime);
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
function maxTimeValidator(configModel, control) {
|
|
1052
|
+
return timeChecker(control, configModel, ValidatorNames.maxTime);
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
const decoratorRegistrationCaller = new class {
|
|
1056
|
+
constructor() {
|
|
1057
|
+
this.register = void 0;
|
|
1058
|
+
}
|
|
1059
|
+
}();
|
|
1060
|
+
|
|
1061
|
+
function registerDecorator(config) {
|
|
1062
|
+
if (decoratorRegistrationCaller.register)
|
|
1063
|
+
decoratorRegistrationCaller.register(config);
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
function baseDecoratorFunction(validatorName, config, validator) {
|
|
1067
|
+
return function(target, propertyKey, parameterIndex) {
|
|
1068
|
+
registerDecorator({
|
|
1069
|
+
decoratorParams: {
|
|
1070
|
+
target,
|
|
1071
|
+
propertyKey,
|
|
1072
|
+
descriptor: parameterIndex
|
|
1073
|
+
},
|
|
1074
|
+
validatorConfig: {
|
|
1075
|
+
name: validatorName,
|
|
1076
|
+
config,
|
|
1077
|
+
validator
|
|
1078
|
+
}
|
|
1079
|
+
});
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
function allOf(config) {
|
|
1084
|
+
return baseDecoratorFunction(ValidatorNames.allOf, config || {}, allOfValidator);
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
function required(config) {
|
|
1088
|
+
return baseDecoratorFunction(ValidatorNames.required, config || {}, requiredValidator);
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
function numeric(config) {
|
|
1092
|
+
return baseDecoratorFunction(ValidatorNames.numeric, config || {}, numericValidator);
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
function alpha(config) {
|
|
1096
|
+
return baseDecoratorFunction(ValidatorNames.alpha, config || {}, alphaValidator);
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
function alphaNumeric(config) {
|
|
1100
|
+
return baseDecoratorFunction(ValidatorNames.alphaNumeric, config || {}, alphaNumericValidator);
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
function ascii(config) {
|
|
1104
|
+
return baseDecoratorFunction(ValidatorNames.ascii, config || {}, asciiValidator);
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
function contains(config) {
|
|
1108
|
+
return baseDecoratorFunction(ValidatorNames.contains, config || {}, containsValidator);
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
function creditCard(config) {
|
|
1112
|
+
return baseDecoratorFunction(ValidatorNames.creditCard, config || {}, creditCardValidator);
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
function cusip(config) {
|
|
1116
|
+
return baseDecoratorFunction(ValidatorNames.cusip, config || {}, cusipValidator);
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
function dataUri(config) {
|
|
1120
|
+
return baseDecoratorFunction(ValidatorNames.dataUri, config || {}, dataUriValidator);
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
function date(config) {
|
|
1124
|
+
return baseDecoratorFunction(ValidatorNames.date, config || {}, dateValidator);
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
function different(config) {
|
|
1128
|
+
return baseDecoratorFunction(ValidatorNames.different, config || {}, differentValidator);
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
function digit(config) {
|
|
1132
|
+
return baseDecoratorFunction(ValidatorNames.digit, config || {}, digitValidator);
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
function email(config) {
|
|
1136
|
+
return baseDecoratorFunction(ValidatorNames.email, config || {}, emailValidator);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
function endsWith(config) {
|
|
1140
|
+
return baseDecoratorFunction(ValidatorNames.endsWith, config || {}, endsWithValidator);
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
function even(config) {
|
|
1144
|
+
return baseDecoratorFunction(ValidatorNames.even, config || {}, evenValidator);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
function extension(config) {
|
|
1148
|
+
return baseDecoratorFunction(ValidatorNames.extension, config || {}, extensionValidator);
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
function factor(config) {
|
|
1152
|
+
return baseDecoratorFunction(ValidatorNames.factor, config || {}, factorValidator);
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
function greaterThanEqualTo(config) {
|
|
1156
|
+
return baseDecoratorFunction(ValidatorNames.greaterThanEqualTo, config || {}, greaterThanEqualToValidator);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
function greaterThan(config) {
|
|
1160
|
+
return baseDecoratorFunction(ValidatorNames.greaterThan, config || {}, greaterThanValidator);
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
function hexColor(config) {
|
|
1164
|
+
return baseDecoratorFunction(ValidatorNames.hexColor, config || {}, hexColorValidator);
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
function ip(config) {
|
|
1168
|
+
return baseDecoratorFunction(ValidatorNames.ip, config || {}, ipValidator);
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
function json(config) {
|
|
1172
|
+
return baseDecoratorFunction(ValidatorNames.json, config || {}, jsonValidator);
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
function latitude(config) {
|
|
1176
|
+
return baseDecoratorFunction(ValidatorNames.latitude, config || {}, latitudeValidator);
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
function latLong(config) {
|
|
1180
|
+
return baseDecoratorFunction(ValidatorNames.latLong, config || {}, latLongValidator);
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
function leapYear(config) {
|
|
1184
|
+
return baseDecoratorFunction(ValidatorNames.leapYear, config || {}, leapYearValidator);
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
function lessThanEqualTo(config) {
|
|
1188
|
+
return baseDecoratorFunction(ValidatorNames.lessThanEqualTo, config || {}, lessThanEqualToValidator);
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
function lessThan(config) {
|
|
1192
|
+
return baseDecoratorFunction(ValidatorNames.lessThan, config || {}, lessThanValidator);
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
function longitude(config) {
|
|
1196
|
+
return baseDecoratorFunction(ValidatorNames.longitude, config || {}, longitudeValidator);
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
function lowerCase(config) {
|
|
1200
|
+
return baseDecoratorFunction(ValidatorNames.lowercase, config || {}, lowercaseValidator);
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
function mac(config) {
|
|
1204
|
+
return baseDecoratorFunction(ValidatorNames.mac, config || {}, macValidator);
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
function maxDate(config) {
|
|
1208
|
+
return baseDecoratorFunction(ValidatorNames.maxDate, config || {}, maxDateValidator);
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
function maxLength(config) {
|
|
1212
|
+
return baseDecoratorFunction(ValidatorNames.maxLength, config || {}, maxLengthValidator);
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
function maxNumber(config) {
|
|
1216
|
+
return baseDecoratorFunction(ValidatorNames.maxNumber, config || {}, maxNumberValidator);
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
function maxTime(config) {
|
|
1220
|
+
return baseDecoratorFunction(ValidatorNames.maxTime, config || {}, maxTimeValidator);
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
function minDate(config) {
|
|
1224
|
+
return baseDecoratorFunction(ValidatorNames.minDate, config || {}, minDateValidator);
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
function minLength(config) {
|
|
1228
|
+
return baseDecoratorFunction(ValidatorNames.minLength, config || {}, minLengthValidator);
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
function minNumber(config) {
|
|
1232
|
+
return baseDecoratorFunction(ValidatorNames.minNumber, config || {}, minNumberValidator);
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
function minTime(config) {
|
|
1236
|
+
return baseDecoratorFunction(ValidatorNames.minTime, config || {}, minTimeValidator);
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
function noneOf(config) {
|
|
1240
|
+
return baseDecoratorFunction(ValidatorNames.noneOf, config || {}, noneOfValidator);
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
function notEmpty(config) {
|
|
1244
|
+
return baseDecoratorFunction(ValidatorNames.notEmpty, config || {}, notEmptyValidator);
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
function odd(config) {
|
|
1248
|
+
return baseDecoratorFunction(ValidatorNames.odd, config || {}, oddValidator);
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
function oneOf(config) {
|
|
1252
|
+
return baseDecoratorFunction(ValidatorNames.oneOf, config || {}, oneOfValidator);
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
function password(config) {
|
|
1256
|
+
return baseDecoratorFunction(ValidatorNames.password, config || {}, passwordValidator);
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
function pattern(config) {
|
|
1260
|
+
return baseDecoratorFunction(ValidatorNames.pattern, config || {}, patternValidator);
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
function port(config) {
|
|
1264
|
+
return baseDecoratorFunction(ValidatorNames.port, config || {}, portValidator);
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
function primeNumber(config) {
|
|
1268
|
+
return baseDecoratorFunction(ValidatorNames.primeNumber, config || {}, primeNumberValidator);
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
function range(config) {
|
|
1272
|
+
return baseDecoratorFunction(ValidatorNames.range, config || {}, rangeValidator);
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
function requiredTrueValidator(configModel, control) {
|
|
1276
|
+
let config = getConfigObject(configModel);
|
|
1277
|
+
if (Linq.execute(config, control)) {
|
|
1278
|
+
if (control.value !== true) {
|
|
1279
|
+
return ValidationMessage.toJson(ValidatorNames.requiredTrue, config, []);
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
return ValidationMessage.null();
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
function requiredTrue(config) {
|
|
1286
|
+
return baseDecoratorFunction(ValidatorNames.requiredTrue, config || {}, requiredTrueValidator);
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
function startsWith(config) {
|
|
1290
|
+
return baseDecoratorFunction(ValidatorNames.startsWith, config || {}, startsWithValidator);
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
function upperCase(config) {
|
|
1294
|
+
return baseDecoratorFunction(ValidatorNames.uppercase, config || {}, uppercaseValidator);
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
function url(config) {
|
|
1298
|
+
return baseDecoratorFunction(ValidatorNames.url, config || {}, urlValidator);
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
function baseSanitizerDecoratorFunction(sanitizerName, config, func) {
|
|
1302
|
+
return function(target, propertyKey, parameterIndex) {
|
|
1303
|
+
registerDecorator({
|
|
1304
|
+
decoratorParams: {
|
|
1305
|
+
target,
|
|
1306
|
+
propertyKey,
|
|
1307
|
+
descriptor: parameterIndex
|
|
1308
|
+
},
|
|
1309
|
+
sanitizerConfig: {
|
|
1310
|
+
name: sanitizerName,
|
|
1311
|
+
config,
|
|
1312
|
+
sanitizer: func
|
|
1313
|
+
}
|
|
1314
|
+
});
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
const SanitizerNames = {
|
|
1319
|
+
blacklist: "blacklist",
|
|
1320
|
+
escape: "escape",
|
|
1321
|
+
ltrim: "ltrim",
|
|
1322
|
+
prefix: "prefix",
|
|
1323
|
+
rtrim: "rtrim",
|
|
1324
|
+
sanitize: "sanitize",
|
|
1325
|
+
stripLow: "stripLow",
|
|
1326
|
+
suffix: "suffix",
|
|
1327
|
+
toBoolean: "toBoolean",
|
|
1328
|
+
toDate: "toDate",
|
|
1329
|
+
toInt: "toInt",
|
|
1330
|
+
toString: "toString",
|
|
1331
|
+
trim: "trim",
|
|
1332
|
+
whitelist: "whitelist"
|
|
1333
|
+
};
|
|
1334
|
+
|
|
1335
|
+
function isNumeric(value) {
|
|
1336
|
+
return value - parseFloat(value) + 1 >= 0;
|
|
1337
|
+
}
|
|
1338
|
+
function isNotBlank(value) {
|
|
1339
|
+
return value !== void 0 && value !== null && value !== "";
|
|
1340
|
+
}
|
|
1341
|
+
function trim$1(value) {
|
|
1342
|
+
if (isNotBlank(value)) {
|
|
1343
|
+
if (typeof value === "string")
|
|
1344
|
+
return value.trim();
|
|
1345
|
+
}
|
|
1346
|
+
return value;
|
|
1347
|
+
}
|
|
1348
|
+
function ltrim$1(value) {
|
|
1349
|
+
if (isNotBlank(value)) {
|
|
1350
|
+
if (typeof value === "string")
|
|
1351
|
+
return value.replace(/^\s+/g, "");
|
|
1352
|
+
}
|
|
1353
|
+
return value;
|
|
1354
|
+
}
|
|
1355
|
+
function rtrim$1(value) {
|
|
1356
|
+
if (isNotBlank(value)) {
|
|
1357
|
+
if (typeof value === "string")
|
|
1358
|
+
return value.replace(/\s+$/g, "");
|
|
1359
|
+
}
|
|
1360
|
+
return value;
|
|
1361
|
+
}
|
|
1362
|
+
function blacklist$1(value, chars) {
|
|
1363
|
+
if (isNotBlank(value)) {
|
|
1364
|
+
if (typeof value === "string")
|
|
1365
|
+
return value.replace(new RegExp("[$" + chars + "]+", "g"), "");
|
|
1366
|
+
}
|
|
1367
|
+
return value;
|
|
1368
|
+
}
|
|
1369
|
+
function stripLow$1(value, keepNewLines) {
|
|
1370
|
+
let chars = keepNewLines === true ? "\0- \v\f-\x7F" : "\0-\x7F";
|
|
1371
|
+
return blacklist$1(value, chars);
|
|
1372
|
+
}
|
|
1373
|
+
function toBoolean$1(value, strict) {
|
|
1374
|
+
if (isNotBlank(value)) {
|
|
1375
|
+
if (strict) {
|
|
1376
|
+
return value === "1" || value === "true";
|
|
1377
|
+
}
|
|
1378
|
+
return value !== "0" && value !== "false" && value !== "";
|
|
1379
|
+
}
|
|
1380
|
+
return value;
|
|
1381
|
+
}
|
|
1382
|
+
function toInt$1(value, radix) {
|
|
1383
|
+
if (isNotBlank(value)) {
|
|
1384
|
+
if (isNumeric(value))
|
|
1385
|
+
return parseInt(value, radix || 10);
|
|
1386
|
+
}
|
|
1387
|
+
return null;
|
|
1388
|
+
}
|
|
1389
|
+
function toString$1(value, radix) {
|
|
1390
|
+
if (isNotBlank(value))
|
|
1391
|
+
return String(value);
|
|
1392
|
+
return value;
|
|
1393
|
+
}
|
|
1394
|
+
function whitelist$1(value, chars) {
|
|
1395
|
+
if (isNotBlank(value)) {
|
|
1396
|
+
if (typeof value === "string")
|
|
1397
|
+
return value.replace(new RegExp(`[^${chars}]+`, "g"), "");
|
|
1398
|
+
}
|
|
1399
|
+
return value;
|
|
1400
|
+
}
|
|
1401
|
+
function toDate$1(value, config) {
|
|
1402
|
+
var dateProvider = new DateProvider();
|
|
1403
|
+
if (isNotBlank(value)) {
|
|
1404
|
+
if (typeof value === "string" && dateProvider.isValid(value, config || {})) {
|
|
1405
|
+
value = dateProvider.getDate(value);
|
|
1406
|
+
return value;
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
return null;
|
|
1410
|
+
}
|
|
1411
|
+
function escape$1(value) {
|
|
1412
|
+
if (isNotBlank(value))
|
|
1413
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/\//g, "/").replace(/\\/g, "\").replace(/`/g, "`");
|
|
1414
|
+
return value;
|
|
1415
|
+
}
|
|
1416
|
+
function prefix$1(value, text) {
|
|
1417
|
+
if (isNotBlank(value))
|
|
1418
|
+
return `${text}${value}`;
|
|
1419
|
+
return value;
|
|
1420
|
+
}
|
|
1421
|
+
function suffix$1(value, text) {
|
|
1422
|
+
if (isNotBlank(value))
|
|
1423
|
+
return `${value}${text}`;
|
|
1424
|
+
return value;
|
|
1425
|
+
}
|
|
1426
|
+
function sanitize$1(value, config) {
|
|
1427
|
+
return config.custom(value);
|
|
1428
|
+
}
|
|
1429
|
+
const SANITIZERS = {
|
|
1430
|
+
trim: trim$1,
|
|
1431
|
+
ltrim: ltrim$1,
|
|
1432
|
+
rtrim: rtrim$1,
|
|
1433
|
+
blacklist: blacklist$1,
|
|
1434
|
+
stripLow: stripLow$1,
|
|
1435
|
+
toBoolean: toBoolean$1,
|
|
1436
|
+
toInt: toInt$1,
|
|
1437
|
+
"toString": toString$1,
|
|
1438
|
+
whitelist: whitelist$1,
|
|
1439
|
+
toDate: toDate$1,
|
|
1440
|
+
escape: escape$1,
|
|
1441
|
+
prefix: prefix$1,
|
|
1442
|
+
suffix: suffix$1,
|
|
1443
|
+
sanitize: sanitize$1
|
|
1444
|
+
};
|
|
1445
|
+
|
|
1446
|
+
function blacklist(chars) {
|
|
1447
|
+
return baseSanitizerDecoratorFunction(SanitizerNames.blacklist, chars, SANITIZERS.blacklist);
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
function escape() {
|
|
1451
|
+
return baseSanitizerDecoratorFunction(SanitizerNames.blacklist, void 0, SANITIZERS.escape);
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
function ltrim() {
|
|
1455
|
+
return baseSanitizerDecoratorFunction(SanitizerNames.ltrim, void 0, SANITIZERS.ltrim);
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
function prefix(text) {
|
|
1459
|
+
return baseSanitizerDecoratorFunction(SanitizerNames.blacklist, text, SANITIZERS.escape);
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
function rtrim() {
|
|
1463
|
+
return baseSanitizerDecoratorFunction(SanitizerNames.rtrim, void 0, SANITIZERS.rtrim);
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
function stripLow(keepNewLines) {
|
|
1467
|
+
return baseSanitizerDecoratorFunction(SanitizerNames.stripLow, keepNewLines, SANITIZERS.stripLow);
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
function suffix(text) {
|
|
1471
|
+
return baseSanitizerDecoratorFunction(SanitizerNames.suffix, text, SANITIZERS.suffix);
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
function toBoolean(strict) {
|
|
1475
|
+
return baseSanitizerDecoratorFunction(SanitizerNames.blacklist, strict, SANITIZERS.toBoolean);
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
function toDate() {
|
|
1479
|
+
return baseSanitizerDecoratorFunction(SanitizerNames.toDate, void 0, SANITIZERS.toDate);
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
function toInt(radix) {
|
|
1483
|
+
return baseSanitizerDecoratorFunction(SanitizerNames.toInt, radix, SANITIZERS.toInt);
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
function toString() {
|
|
1487
|
+
return baseSanitizerDecoratorFunction(SanitizerNames.toString, void 0, SANITIZERS.toString);
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
function trim() {
|
|
1491
|
+
return baseSanitizerDecoratorFunction(SanitizerNames.trim, void 0, SANITIZERS.trim);
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
function whitelist(chars) {
|
|
1495
|
+
return baseSanitizerDecoratorFunction(SanitizerNames.blacklist, chars, SANITIZERS.whitelist);
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
function sanitize(config) {
|
|
1499
|
+
return baseSanitizerDecoratorFunction(SanitizerNames.sanitize, config, SANITIZERS.sanitize);
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
function prop(config) {
|
|
1503
|
+
return function(target, propertyKey, parameterIndex) {
|
|
1504
|
+
registerDecorator({
|
|
1505
|
+
decoratorParams: {
|
|
1506
|
+
target,
|
|
1507
|
+
propertyKey,
|
|
1508
|
+
descriptor: parameterIndex
|
|
1509
|
+
},
|
|
1510
|
+
propConfig: config || {}
|
|
1511
|
+
});
|
|
1512
|
+
};
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
const ControlValidators = {
|
|
1516
|
+
required: requiredValidator
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1519
|
+
exports.ControlValidators = ControlValidators;
|
|
1520
|
+
exports.NumericValueType = NumericValueType;
|
|
1521
|
+
exports.decoratorAllOfValidation = allOf;
|
|
1522
|
+
exports.decoratorAlphaNumericValidation = alphaNumeric;
|
|
1523
|
+
exports.decoratorAlphaValidation = alpha;
|
|
1524
|
+
exports.decoratorAsciiValidation = ascii;
|
|
1525
|
+
exports.decoratorBlacklistSanitizer = blacklist;
|
|
1526
|
+
exports.decoratorContainsValidation = contains;
|
|
1527
|
+
exports.decoratorCreditCardValidation = creditCard;
|
|
1528
|
+
exports.decoratorCusipValidation = cusip;
|
|
1529
|
+
exports.decoratorDataUriValidation = dataUri;
|
|
1530
|
+
exports.decoratorDateValidation = date;
|
|
1531
|
+
exports.decoratorDifferentValdiation = different;
|
|
1532
|
+
exports.decoratorDigitValidation = digit;
|
|
1533
|
+
exports.decoratorEmailValidation = email;
|
|
1534
|
+
exports.decoratorEndsWithValidation = endsWith;
|
|
1535
|
+
exports.decoratorEscapeSanitizer = escape;
|
|
1536
|
+
exports.decoratorEvenValidation = even;
|
|
1537
|
+
exports.decoratorExtensionValidation = extension;
|
|
1538
|
+
exports.decoratorFactorValidation = factor;
|
|
1539
|
+
exports.decoratorGreaterThanEqualToValidation = greaterThanEqualTo;
|
|
1540
|
+
exports.decoratorGreaterThanValidation = greaterThan;
|
|
1541
|
+
exports.decoratorHexColorValidation = hexColor;
|
|
1542
|
+
exports.decoratorIpValidation = ip;
|
|
1543
|
+
exports.decoratorJsonValidation = json;
|
|
1544
|
+
exports.decoratorLatLongValidation = latLong;
|
|
1545
|
+
exports.decoratorLatitudeValdiation = latitude;
|
|
1546
|
+
exports.decoratorLeapYearValidation = leapYear;
|
|
1547
|
+
exports.decoratorLessThanEqualToValidation = lessThanEqualTo;
|
|
1548
|
+
exports.decoratorLessThanValidation = lessThan;
|
|
1549
|
+
exports.decoratorLongitudeValidation = longitude;
|
|
1550
|
+
exports.decoratorLowercaseValidation = lowerCase;
|
|
1551
|
+
exports.decoratorLtrimSanitizer = ltrim;
|
|
1552
|
+
exports.decoratorMacValidation = mac;
|
|
1553
|
+
exports.decoratorMaxDateValidation = maxDate;
|
|
1554
|
+
exports.decoratorMaxLengthValidation = maxLength;
|
|
1555
|
+
exports.decoratorMaxNumberValidation = maxNumber;
|
|
1556
|
+
exports.decoratorMaxTimeValidation = maxTime;
|
|
1557
|
+
exports.decoratorMinDateValidation = minDate;
|
|
1558
|
+
exports.decoratorMinLengthValidation = minLength;
|
|
1559
|
+
exports.decoratorMinNumberValidation = minNumber;
|
|
1560
|
+
exports.decoratorMinTimeValidation = minTime;
|
|
1561
|
+
exports.decoratorNoneOfValidation = noneOf;
|
|
1562
|
+
exports.decoratorNotEmptyValidation = notEmpty;
|
|
1563
|
+
exports.decoratorNumericValidation = numeric;
|
|
1564
|
+
exports.decoratorOddValidation = odd;
|
|
1565
|
+
exports.decoratorOneOfValidation = oneOf;
|
|
1566
|
+
exports.decoratorPasswordValdiation = password;
|
|
1567
|
+
exports.decoratorPatternValidation = pattern;
|
|
1568
|
+
exports.decoratorPortValidation = port;
|
|
1569
|
+
exports.decoratorPrefixSanitizer = prefix;
|
|
1570
|
+
exports.decoratorPrimeNumberValidation = primeNumber;
|
|
1571
|
+
exports.decoratorRangeValidation = range;
|
|
1572
|
+
exports.decoratorRegistrationCaller = decoratorRegistrationCaller;
|
|
1573
|
+
exports.decoratorRequiredTrueValidation = requiredTrue;
|
|
1574
|
+
exports.decoratorRequiredValidation = required;
|
|
1575
|
+
exports.decoratorRtrimSanitizer = rtrim;
|
|
1576
|
+
exports.decoratorSanitizeSanitizer = sanitize;
|
|
1577
|
+
exports.decoratorStartsWithValidation = startsWith;
|
|
1578
|
+
exports.decoratorStripLowSanitizer = stripLow;
|
|
1579
|
+
exports.decoratorSuffixSanitizer = suffix;
|
|
1580
|
+
exports.decoratorToBooleanSanitizer = toBoolean;
|
|
1581
|
+
exports.decoratorToDateSanitizer = toDate;
|
|
1582
|
+
exports.decoratorToIntSanitizer = toInt;
|
|
1583
|
+
exports.decoratorToStringSanitizer = toString;
|
|
1584
|
+
exports.decoratorTrimSanitizer = trim;
|
|
1585
|
+
exports.decoratorUpperCaseValidation = upperCase;
|
|
1586
|
+
exports.decoratorUrlValidation = url;
|
|
1587
|
+
exports.decoratorWhitelistSanitizer = whitelist;
|
|
1588
|
+
exports.prop = prop;
|
|
1589
|
+
exports.validationForms = validationForms;
|