@astratra/core 1.1.0 → 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.
@@ -0,0 +1,313 @@
1
+ /*
2
+ * Les vérifications et nettoyages de texte dont se servent les chaînes de validation (src/validation.js), portés de
3
+ * validator.js 13.15 (licence MIT, Copyright (c) 2018 Chris O'Hara ; voir THIRD-PARTY-NOTICES.md) : mêmes réponses
4
+ * sur des vecteurs enregistrés. Chaque fonction reçoit un texte.
5
+ *
6
+ * Différences voulues, toutes là où validator.js levait une exception au lieu de répondre :
7
+ * - la longueur en octets d'un texte qui contient un demi-caractère Unicode (une moitié de paire) est refusée
8
+ * (validator.js levait une URIError dans isByteLength et isEmail, qui faisait une erreur 500) ;
9
+ * - isIn et isUUID ne lisent que les propriétés propres de l'objet donné (« constructor » n'est pas une version).
10
+ */
11
+
12
+ // eslint-disable-next-line no-control-regex
13
+ const splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)</i;
14
+ const emailUserPart = /^[a-z\d!#$%&'*+\-/=?^_`{|}~]+$/i;
15
+ const gmailUserPart = /^[a-z\d]+$/;
16
+ // eslint-disable-next-line no-control-regex
17
+ const quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i;
18
+ const emailUserUtf8Part = /^[a-z\d!#$%&'*+\-/=?^_`{|}~\u00A1-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i;
19
+ // eslint-disable-next-line no-control-regex
20
+ const quotedEmailUserUtf8 = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i;
21
+ const DEFAULT_MAX_EMAIL_LENGTH = 254;
22
+
23
+ const DECIMAL = {};
24
+ for (const [sep, locales] of Object.entries({
25
+ '.': ['en-US', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-ZA', 'ar-EG', 'ar-LB', 'ar-LY', 'bn-BD', 'bn-IN'],
26
+ '٫': ['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-MA', 'ar-QM', 'ar-QA', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'fa-IR', 'fa-AF'],
27
+ ',': ['en-ZM', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'eo', 'es-ES', 'fr-CA', 'fr-FR', 'gu-IN', 'hi-IN', 'hu-HU', 'id-ID', 'it-IT', 'kk-KZ', 'kn-IN', 'ku-IQ', 'ml-IN', 'nb-NO', 'nl-NL', 'nn-NO', 'or-IN', 'pa-IN', 'pl-PL', 'pt-PT', 'ru-RU', 'si-LK', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'ta-IN', 'te-IN', 'tr-TR', 'uk-UA', 'vi-VN', 'pt-BR', 'pl-Pl'],
28
+ })) for (const locale of locales) DECIMAL[locale] = sep;
29
+ const decimalOf = (locale) => (locale && Object.hasOwn(DECIMAL, locale) ? DECIMAL[locale] : undefined);
30
+
31
+ /** Les options données, complétées par les valeurs par défaut (comme merge de validator.js). */
32
+ function merge(options, defaults) {
33
+ const out = typeof options === 'object' && options !== null ? { ...options } : {};
34
+ for (const key of Object.keys(defaults)) if (typeof out[key] === 'undefined') out[key] = defaults[key];
35
+ return out;
36
+ }
37
+
38
+ /** Le texte d'une option (toString de validator.js). */
39
+ function optionString(input) {
40
+ if (typeof input === 'object' && input !== null) return typeof input.toString === 'function' ? String(input.toString()) : '[object Object]';
41
+ if (input === null || typeof input === 'undefined' || (Number.isNaN(Number(input)) && !input.length)) return '';
42
+ return String(input);
43
+ }
44
+
45
+ const isNullish = (value) => value === null || value === undefined;
46
+ const has = (object, key) => object !== null && typeof object === 'object' && Object.hasOwn(object, key);
47
+
48
+ /** La longueur en octets UTF-8 ; null si le texte contient un demi-caractère (encodeURI levait). */
49
+ function byteLength(str) {
50
+ if (!str.isWellFormed()) return null;
51
+ return Buffer.byteLength(str, 'utf8');
52
+ }
53
+
54
+ function isByteLength(str, options) {
55
+ const min = (options && options.min) || 0;
56
+ const max = options && options.max;
57
+ const len = byteLength(str);
58
+ if (len === null) return false;
59
+ return len >= min && (typeof max === 'undefined' || len <= max);
60
+ }
61
+
62
+ function isFQDN(str, options) {
63
+ const o = merge(options, { require_tld: true, allow_underscores: false, allow_trailing_dot: false, allow_numeric_tld: false, allow_wildcard: false, ignore_max_length: false });
64
+ if (o.allow_trailing_dot && str[str.length - 1] === '.') str = str.substring(0, str.length - 1);
65
+ if (o.allow_wildcard === true && str.indexOf('*.') === 0) str = str.substring(2);
66
+ const parts = str.split('.');
67
+ const tld = parts[parts.length - 1];
68
+ if (o.require_tld) {
69
+ if (parts.length < 2) return false;
70
+ if (!o.allow_numeric_tld && !/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) return false;
71
+ if (/\s/.test(tld)) return false;
72
+ }
73
+ if (!o.allow_numeric_tld && /^\d+$/.test(tld)) return false;
74
+ return parts.every((part) => {
75
+ if (part.length > 63 && !o.ignore_max_length) return false;
76
+ if (!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(part)) return false;
77
+ if (/[\uff01-\uff5e]/.test(part)) return false;
78
+ if (/^-|-$/.test(part)) return false;
79
+ if (!o.allow_underscores && /_/.test(part)) return false;
80
+ return true;
81
+ });
82
+ }
83
+
84
+ const IPV4_SEGMENT = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
85
+ const IPV4_ADDRESS = `(${IPV4_SEGMENT}[.]){3}${IPV4_SEGMENT}`;
86
+ const IPV4 = new RegExp(`^${IPV4_ADDRESS}$`);
87
+ const S6 = '(?:[0-9a-fA-F]{1,4})';
88
+ const IPV6 = new RegExp(
89
+ `^((?:${S6}:){7}(?:${S6}|:)|(?:${S6}:){6}(?:${IPV4_ADDRESS}|:${S6}|:)|(?:${S6}:){5}(?::${IPV4_ADDRESS}|(:${S6}){1,2}|:)|(?:${S6}:){4}(?:(:${S6}){0,1}:${IPV4_ADDRESS}|(:${S6}){1,3}|:)|(?:${S6}:){3}(?:(:${S6}){0,2}:${IPV4_ADDRESS}|(:${S6}){1,4}|:)|(?:${S6}:){2}(?:(:${S6}){0,3}:${IPV4_ADDRESS}|(:${S6}){1,5}|:)|(?:${S6}:){1}(?:(:${S6}){0,4}:${IPV4_ADDRESS}|(:${S6}){1,6}|:)|(?::((?::${S6}){0,5}:${IPV4_ADDRESS}|(?::${S6}){1,7}|:)))(%[0-9a-zA-Z.]{1,})?$`
90
+ );
91
+
92
+ function isIP(str, options) {
93
+ const version = String((typeof options === 'object' && options !== null ? options.version : options) || '');
94
+ if (!version) return IPV4.test(str) || IPV6.test(str);
95
+ if (version === '4') return IPV4.test(str);
96
+ if (version === '6') return IPV6.test(str);
97
+ return false;
98
+ }
99
+
100
+ const checkHost = (host, list) => list.some((match) => host === match || (match instanceof RegExp && match.test(host)));
101
+
102
+ function validateDisplayName(displayName) {
103
+ const withoutQuotes = displayName.replace(/^"(.+)"$/, '$1');
104
+ if (!withoutQuotes.trim()) return false;
105
+ if (/[.";<>]/.test(withoutQuotes)) {
106
+ if (withoutQuotes === displayName) return false;
107
+ if (withoutQuotes.split('"').length !== withoutQuotes.split('\\"').length) return false;
108
+ }
109
+ return true;
110
+ }
111
+
112
+ function isEmail(str, options) {
113
+ const o = merge(options, { allow_display_name: false, allow_underscores: false, require_display_name: false, allow_utf8_local_part: true, require_tld: true, blacklisted_chars: '', ignore_max_length: false, host_blacklist: [], host_whitelist: [] });
114
+ if (o.require_display_name || o.allow_display_name) {
115
+ const display = str.match(splitNameAddress);
116
+ if (display) {
117
+ let displayName = display[1];
118
+ str = str.replace(displayName, '').replace(/(^<|>$)/g, '');
119
+ if (displayName.endsWith(' ')) displayName = displayName.slice(0, -1);
120
+ if (!validateDisplayName(displayName)) return false;
121
+ } else if (o.require_display_name) return false;
122
+ }
123
+ if (!o.ignore_max_length && str.length > DEFAULT_MAX_EMAIL_LENGTH) return false;
124
+ const parts = str.split('@');
125
+ const domain = parts.pop();
126
+ const lowerDomain = domain.toLowerCase();
127
+ if (o.host_blacklist.length > 0 && checkHost(lowerDomain, o.host_blacklist)) return false;
128
+ if (o.host_whitelist.length > 0 && !checkHost(lowerDomain, o.host_whitelist)) return false;
129
+ let user = parts.join('@');
130
+ if (o.domain_specific_validation && (lowerDomain === 'gmail.com' || lowerDomain === 'googlemail.com')) {
131
+ user = user.toLowerCase();
132
+ const username = user.split('+')[0];
133
+ if (!isByteLength(username.replace(/\./g, ''), { min: 6, max: 30 })) return false;
134
+ if (!username.split('.').every((part) => gmailUserPart.test(part))) return false;
135
+ }
136
+ if (o.ignore_max_length === false && (!isByteLength(user, { max: 64 }) || !isByteLength(domain, { max: 254 }))) return false;
137
+ if (!isFQDN(domain, { require_tld: o.require_tld, ignore_max_length: o.ignore_max_length, allow_underscores: o.allow_underscores })) {
138
+ if (!o.allow_ip_domain) return false;
139
+ if (!isIP(domain)) {
140
+ if (!domain.startsWith('[') || !domain.endsWith(']')) return false;
141
+ const bare = domain.slice(1, -1);
142
+ if (bare.length === 0 || !isIP(bare)) return false;
143
+ }
144
+ }
145
+ if (o.blacklisted_chars && user.search(new RegExp(`[${o.blacklisted_chars}]+`, 'g')) !== -1) return false;
146
+ if (user[0] === '"' && user[user.length - 1] === '"') {
147
+ user = user.slice(1, user.length - 1);
148
+ return o.allow_utf8_local_part ? quotedEmailUserUtf8.test(user) : quotedEmailUser.test(user);
149
+ }
150
+ const pattern = o.allow_utf8_local_part ? emailUserUtf8Part : emailUserPart;
151
+ return user.split('.').every((part) => pattern.test(part));
152
+ }
153
+
154
+ function isEmpty(str, options) {
155
+ const o = merge(options, { ignore_whitespace: false });
156
+ return (o.ignore_whitespace ? str.trim().length : str.length) === 0;
157
+ }
158
+
159
+ function isLength(str, options) {
160
+ const min = (options && typeof options === 'object' && options.min) || 0;
161
+ const max = options && typeof options === 'object' ? options.max : undefined;
162
+ const presentation = str.match(/[^\uFE0F\uFE0E][\uFE0F\uFE0E]/g) || [];
163
+ const surrogates = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || [];
164
+ const len = str.length - presentation.length - surrogates.length;
165
+ const inside = len >= min && (typeof max === 'undefined' || len <= max);
166
+ if (inside && options && Array.isArray(options.discreteLengths)) return options.discreteLengths.some((d) => d === len);
167
+ return inside;
168
+ }
169
+
170
+ const isHexadecimal = (str) => /^(0x|0h)?[0-9A-F]+$/i.test(str);
171
+ const isMongoId = (str) => isHexadecimal(str) && str.length === 24;
172
+
173
+ function isIn(str, options) {
174
+ if (Array.isArray(options)) return options.map(optionString).indexOf(str) >= 0;
175
+ if (typeof options === 'object' && options !== null) return Object.hasOwn(options, str);
176
+ if (options && typeof options.indexOf === 'function') return options.indexOf(str) >= 0;
177
+ return false;
178
+ }
179
+
180
+ function isNumeric(str, options) {
181
+ if (options && options.no_symbols) return /^[0-9]+$/.test(str);
182
+ const sep = (options || {}).locale ? decimalOf(options.locale) : '.';
183
+ return new RegExp(`^[+-]?([0-9]*[${sep}])?[0-9]+$`).test(str);
184
+ }
185
+
186
+ function isInt(str, options) {
187
+ const o = options || {};
188
+ const regex = o.allow_leading_zeroes === false ? /^(?:[-+]?(?:0|[1-9][0-9]*))$/ : /^[-+]?[0-9]+$/;
189
+ const ok = (key, test) => !has(o, key) || isNullish(o[key]) || test(o[key]);
190
+ return regex.test(str) && ok('min', (v) => str >= v) && ok('max', (v) => str <= v) && ok('lt', (v) => str < v) && ok('gt', (v) => str > v);
191
+ }
192
+
193
+ function isFloat(str, options) {
194
+ const o = options || {};
195
+ const sep = o.locale ? decimalOf(o.locale) : '.';
196
+ const float = new RegExp(`^(?:[-+])?(?:[0-9]+)?(?:\\${sep}[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$`);
197
+ if (str === '' || str === '.' || str === ',' || str === '-' || str === '+') return false;
198
+ const value = parseFloat(str.replace(',', '.'));
199
+ const ok = (key, test) => !has(o, key) || isNullish(o[key]) || test(o[key]);
200
+ return float.test(str) && ok('min', (v) => value >= v) && ok('max', (v) => value <= v) && ok('lt', (v) => value < v) && ok('gt', (v) => value > v);
201
+ }
202
+
203
+ function isBoolean(str, options = { loose: false }) {
204
+ if (options && options.loose) return ['true', 'false', '1', '0', 'yes', 'no'].includes(str.toLowerCase());
205
+ return ['true', 'false', '1', '0'].includes(str);
206
+ }
207
+
208
+ function matches(str, pattern, modifiers) {
209
+ const regex = pattern instanceof RegExp ? pattern : new RegExp(pattern, modifiers);
210
+ return !!str.match(regex);
211
+ }
212
+
213
+ const equals = (str, comparison) => str === comparison;
214
+
215
+ function contains(str, elem, options) {
216
+ const o = merge(options, { ignoreCase: false, minOccurrences: 1 });
217
+ if (o.ignoreCase) return str.toLowerCase().split(optionString(elem).toLowerCase()).length > o.minOccurrences;
218
+ return str.split(optionString(elem)).length > o.minOccurrences;
219
+ }
220
+
221
+ const UUID = {
222
+ 1: /^[0-9A-F]{8}-[0-9A-F]{4}-1[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
223
+ 2: /^[0-9A-F]{8}-[0-9A-F]{4}-2[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
224
+ 3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
225
+ 4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
226
+ 5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
227
+ 6: /^[0-9A-F]{8}-[0-9A-F]{4}-6[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
228
+ 7: /^[0-9A-F]{8}-[0-9A-F]{4}-7[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
229
+ 8: /^[0-9A-F]{8}-[0-9A-F]{4}-8[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
230
+ nil: /^00000000-0000-0000-0000-000000000000$/i,
231
+ max: /^ffffffff-ffff-ffff-ffff-ffffffffffff$/i,
232
+ loose: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
233
+ all: /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i,
234
+ };
235
+ function isUUID(str, version) {
236
+ const v = version === undefined || version === null ? 'all' : version;
237
+ return Object.hasOwn(UUID, v) ? UUID[v].test(str) : false;
238
+ }
239
+
240
+ // Les nettoyages.
241
+ const escapeClass = (chars) => chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
242
+ const ltrim = (str, chars) => str.replace(chars ? new RegExp(`^[${escapeClass(chars)}]+`, 'g') : /^\s+/g, '');
243
+ function rtrim(str, chars) {
244
+ if (chars) return str.replace(new RegExp(`[${escapeClass(chars)}]+$`, 'g'), '');
245
+ let end = str.length - 1;
246
+ while (/\s/.test(str.charAt(end))) end -= 1;
247
+ return str.slice(0, end + 1);
248
+ }
249
+ const trim = (str, chars) => rtrim(ltrim(str, chars), chars);
250
+ const escape = (str) => str.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\//g, '&#x2F;').replace(/\\/g, '&#x5C;').replace(/`/g, '&#96;');
251
+ const unescape = (str) => str.replace(/&quot;/g, '"').replace(/&#x27;/g, "'").replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&#x2F;/g, '/').replace(/&#x5C;/g, '\\').replace(/&#96;/g, '`').replace(/&amp;/g, '&');
252
+ const blacklist = (str, chars) => str.replace(new RegExp(`[${chars}]+`, 'g'), '');
253
+ const whitelist = (str, chars) => str.replace(new RegExp(`[^${chars}]+`, 'g'), '');
254
+ const stripLow = (str, keepNewLines) => blacklist(str, keepNewLines ? '\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F' : '\\x00-\\x1F\\x7F');
255
+ const toInt = (str, radix) => parseInt(str, radix || 10);
256
+ const toFloat = (str) => (isFloat(str) ? parseFloat(str) : NaN);
257
+ function toBoolean(str, strict) {
258
+ if (strict) return str === '1' || /^true$/i.test(str);
259
+ return str !== '0' && !/^false$/i.test(str) && str !== '';
260
+ }
261
+ function toDate(str) {
262
+ const time = Date.parse(str);
263
+ return Number.isNaN(time) ? null : new Date(time);
264
+ }
265
+
266
+ const ICLOUD = ['icloud.com', 'me.com'];
267
+ const OUTLOOK = ['hotmail.at', 'hotmail.be', 'hotmail.ca', 'hotmail.cl', 'hotmail.co.il', 'hotmail.co.nz', 'hotmail.co.th', 'hotmail.co.uk', 'hotmail.com', 'hotmail.com.ar', 'hotmail.com.au', 'hotmail.com.br', 'hotmail.com.gr', 'hotmail.com.mx', 'hotmail.com.pe', 'hotmail.com.tr', 'hotmail.com.vn', 'hotmail.cz', 'hotmail.de', 'hotmail.dk', 'hotmail.es', 'hotmail.fr', 'hotmail.hu', 'hotmail.id', 'hotmail.ie', 'hotmail.in', 'hotmail.it', 'hotmail.jp', 'hotmail.kr', 'hotmail.lv', 'hotmail.my', 'hotmail.ph', 'hotmail.pt', 'hotmail.sa', 'hotmail.sg', 'hotmail.sk', 'live.be', 'live.co.uk', 'live.com', 'live.com.ar', 'live.com.mx', 'live.de', 'live.es', 'live.eu', 'live.fr', 'live.it', 'live.nl', 'msn.com', 'outlook.at', 'outlook.be', 'outlook.cl', 'outlook.co.il', 'outlook.co.nz', 'outlook.co.th', 'outlook.com', 'outlook.com.ar', 'outlook.com.au', 'outlook.com.br', 'outlook.com.gr', 'outlook.com.pe', 'outlook.com.tr', 'outlook.com.vn', 'outlook.cz', 'outlook.de', 'outlook.dk', 'outlook.es', 'outlook.fr', 'outlook.hu', 'outlook.id', 'outlook.ie', 'outlook.in', 'outlook.it', 'outlook.jp', 'outlook.kr', 'outlook.lv', 'outlook.my', 'outlook.ph', 'outlook.pt', 'outlook.sa', 'outlook.sg', 'outlook.sk', 'passport.com'];
268
+ const YAHOO = ['rocketmail.com', 'yahoo.ca', 'yahoo.co.uk', 'yahoo.com', 'yahoo.de', 'yahoo.fr', 'yahoo.in', 'yahoo.it', 'ymail.com'];
269
+ const YANDEX = ['yandex.ru', 'yandex.ua', 'yandex.kz', 'yandex.com', 'yandex.by', 'ya.ru'];
270
+
271
+ /** L'adresse ramenée à sa forme canonique (minuscules ; points et « +sous-adresse » retirés chez Gmail…). */
272
+ function normalizeEmail(email, options) {
273
+ const o = merge(options, { all_lowercase: true, gmail_lowercase: true, gmail_remove_dots: true, gmail_remove_subaddress: true, gmail_convert_googlemaildotcom: true, outlookdotcom_lowercase: true, outlookdotcom_remove_subaddress: true, yahoo_lowercase: true, yahoo_remove_subaddress: true, yandex_lowercase: true, yandex_convert_yandexru: true, icloud_lowercase: true, icloud_remove_subaddress: true });
274
+ const raw = email.split('@');
275
+ const parts = [null, raw.pop().toLowerCase()];
276
+ parts[0] = raw.join('@');
277
+ const lower = (flag) => {
278
+ if (o.all_lowercase || flag) parts[0] = parts[0].toLowerCase();
279
+ };
280
+ if (parts[1] === 'gmail.com' || parts[1] === 'googlemail.com') {
281
+ if (o.gmail_remove_subaddress) parts[0] = parts[0].split('+')[0];
282
+ if (o.gmail_remove_dots) parts[0] = parts[0].replace(/\.+/g, (m) => (m.length > 1 ? m : ''));
283
+ if (!parts[0].length) return false;
284
+ lower(o.gmail_lowercase);
285
+ parts[1] = o.gmail_convert_googlemaildotcom ? 'gmail.com' : parts[1];
286
+ } else if (ICLOUD.includes(parts[1])) {
287
+ if (o.icloud_remove_subaddress) parts[0] = parts[0].split('+')[0];
288
+ if (!parts[0].length) return false;
289
+ lower(o.icloud_lowercase);
290
+ } else if (OUTLOOK.includes(parts[1])) {
291
+ if (o.outlookdotcom_remove_subaddress) parts[0] = parts[0].split('+')[0];
292
+ if (!parts[0].length) return false;
293
+ lower(o.outlookdotcom_lowercase);
294
+ } else if (YAHOO.includes(parts[1])) {
295
+ if (o.yahoo_remove_subaddress) {
296
+ const components = parts[0].split('-');
297
+ parts[0] = components.length > 1 ? components.slice(0, -1).join('-') : components[0];
298
+ }
299
+ if (!parts[0].length) return false;
300
+ lower(o.yahoo_lowercase);
301
+ } else if (YANDEX.includes(parts[1])) {
302
+ lower(o.yandex_lowercase);
303
+ parts[1] = o.yandex_convert_yandexru ? 'yandex.ru' : parts[1];
304
+ } else if (o.all_lowercase) {
305
+ parts[0] = parts[0].toLowerCase();
306
+ }
307
+ return parts.join('@');
308
+ }
309
+
310
+ module.exports = {
311
+ validators: { contains, equals, isBoolean, isByteLength, isEmail, isEmpty, isFQDN, isFloat, isHexadecimal, isIP, isIn, isInt, isLength, isMongoId, isNumeric, isUUID, matches },
312
+ sanitizers: { blacklist, escape, ltrim, normalizeEmail, rtrim, stripLow, toBoolean, toDate, toFloat, toInt, trim, unescape, whitelist },
313
+ };