@gudhub/ssg-web-components-library 1.0.124 → 1.0.126
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/package.json
CHANGED
|
@@ -20,11 +20,15 @@ export const checkInputsValidations = (inputs) => {
|
|
|
20
20
|
return result;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
const isEmptyAndOptional = (input) => {
|
|
24
|
+
const value = input.value.trim();
|
|
25
|
+
return value === '' && !input.hasAttribute('required');
|
|
26
|
+
};
|
|
23
27
|
|
|
24
28
|
const emailValidation = (input) => {
|
|
25
29
|
const regex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
|
|
26
30
|
|
|
27
|
-
let isValid = regex.test(input.value);
|
|
31
|
+
let isValid = isEmptyAndOptional(input) || regex.test(input.value);
|
|
28
32
|
|
|
29
33
|
if (!isValid) {
|
|
30
34
|
input.classList.add('error');
|
|
@@ -38,11 +42,9 @@ const emailValidation = (input) => {
|
|
|
38
42
|
};
|
|
39
43
|
|
|
40
44
|
const phoneValidation = (input) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const regex = /^\+?\d+$/; // We can write only numbers without special symbols besides "+" sign
|
|
45
|
+
const regex = /^\+?\d+$/;
|
|
44
46
|
|
|
45
|
-
let isValid = regex.test(input.value);
|
|
47
|
+
let isValid = isEmptyAndOptional(input) || regex.test(input.value);
|
|
46
48
|
|
|
47
49
|
if (!isValid) {
|
|
48
50
|
input.classList.add('error');
|
|
@@ -257,13 +257,14 @@ class ImageComponent extends GHComponent {
|
|
|
257
257
|
if (!value) return value;
|
|
258
258
|
|
|
259
259
|
return value
|
|
260
|
-
.normalize('NFD')
|
|
261
|
-
.replace(/[\u0300-\u036f]/g, '')
|
|
262
|
-
.
|
|
263
|
-
.replace(/[
|
|
264
|
-
.replace(
|
|
265
|
-
.replace(
|
|
266
|
-
.replace(
|
|
260
|
+
.normalize('NFD') // separate diacritics
|
|
261
|
+
.replace(/[\u0300-\u036f]/g, '') // remove diacritics
|
|
262
|
+
.normalize('NFC') // recompose unicode letters (важливо для кирилиці)
|
|
263
|
+
.replace(/[()]/g, '') // remove brackets
|
|
264
|
+
.replace(/[^\p{L}\p{N}/._-]+/gu, '-') // replace anything that's not a letter/number (будь-якого алфавіту) with -
|
|
265
|
+
.replace(/-+/g, '-') // collapse multiple -
|
|
266
|
+
.replace(/\/-+/g, '/') // avoid "/-"
|
|
267
|
+
.replace(/^-|-$/g, '') // trim -
|
|
267
268
|
.toLowerCase();
|
|
268
269
|
};
|
|
269
270
|
}
|