@ourtrip/ui 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +0,0 @@
1
- export var cn = function () {
2
- var args = [];
3
- for (var _i = 0; _i < arguments.length; _i++) {
4
- args[_i] = arguments[_i];
5
- }
6
- return args.filter(Boolean).join(' ');
7
- };
@@ -1,128 +0,0 @@
1
- import { isBefore, isValid, parse, subYears } from 'date-fns';
2
- export var isValidCpf = function (formatedCpf) {
3
- var cpf = formatedCpf.replace(/\D/g, '');
4
- if (cpf.length !== 11 || /^(\d)\1+$/.test(cpf)) {
5
- return false;
6
- }
7
- // Calcular el primer dígito verificador
8
- var soma = 0;
9
- for (var i = 0; i < 9; i++) {
10
- soma += parseInt(cpf.charAt(i), 10) * (10 - i);
11
- }
12
- var digito1 = 11 - (soma % 11);
13
- if (digito1 > 9) {
14
- digito1 = 0;
15
- }
16
- // Calcular el segundo dígito verificador
17
- soma = 0;
18
- for (var i = 0; i < 10; i++) {
19
- soma += parseInt(cpf.charAt(i), 10) * (11 - i);
20
- }
21
- var digito2 = 11 - (soma % 11);
22
- if (digito2 > 9) {
23
- digito2 = 0;
24
- }
25
- // Verificar si los dígitos verificadores son iguales a los últimos dos dígitos del CPF
26
- if (parseInt(cpf.charAt(9), 10) === digito1 &&
27
- parseInt(cpf.charAt(10), 10) === digito2) {
28
- return true;
29
- }
30
- return false;
31
- };
32
- export var isValidCNPJ = function (formatedCnpj) {
33
- var cnpj = formatedCnpj.replace(/[^\d]+/g, '');
34
- if (cnpj.length !== 14) {
35
- return false;
36
- }
37
- if (/^(\d)\1+$/.test(cnpj)) {
38
- return false;
39
- }
40
- var length = cnpj.length - 2;
41
- var numbers = cnpj.substring(0, length);
42
- var digitosVerificadores = cnpj.substring(length);
43
- var soma = 0;
44
- var pos = length - 7;
45
- for (var i = length; i >= 1; i--) {
46
- soma += parseInt(numbers.charAt(length - i), 10) * pos--;
47
- if (pos < 2) {
48
- pos = 9;
49
- }
50
- }
51
- var resultado = soma % 11 < 2 ? 0 : 11 - (soma % 11);
52
- if (resultado !== parseInt(digitosVerificadores.charAt(0), 10)) {
53
- return false;
54
- }
55
- length += 1;
56
- numbers = cnpj.substring(0, length);
57
- soma = 0;
58
- pos = length - 7;
59
- for (var i = length; i >= 1; i--) {
60
- soma += parseInt(numbers.charAt(length - i), 10) * pos--;
61
- if (pos < 2) {
62
- pos = 9;
63
- }
64
- }
65
- var segundoDigito = soma % 11 < 2 ? 0 : 11 - (soma % 11);
66
- return segundoDigito === parseInt(digitosVerificadores.charAt(1), 10);
67
- };
68
- export var isCPF = function (document) {
69
- var onlyNumbers = document === null || document === void 0 ? void 0 : document.replace(/\D/g, '');
70
- if ((onlyNumbers === null || onlyNumbers === void 0 ? void 0 : onlyNumbers.length) === 11 && isValidCpf(onlyNumbers))
71
- return true;
72
- return false;
73
- };
74
- export var isCNPJ = function (document) {
75
- var onlyNumbers = document === null || document === void 0 ? void 0 : document.replace(/\D/g, '');
76
- if ((onlyNumbers === null || onlyNumbers === void 0 ? void 0 : onlyNumbers.length) === 14 && isValidCNPJ(onlyNumbers))
77
- return true;
78
- return false;
79
- };
80
- export var isFullName = function (name) {
81
- return /^(?:[A-Za-zÀ-ÿ]{2,}(?: [A-Za-zÀ-ÿ]{2,})+)$/.test(name.trim());
82
- };
83
- export var isValidName = function (name) {
84
- return /^[A-Za-zÀ-ÿ\s.'-]+(?: [A-Za-zÀ-ÿ\s.'-]+)*$/.test(name.trim());
85
- };
86
- export var isValidEmail = function (email) {
87
- return /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/.test(email.trim());
88
- };
89
- export var isValidPhoneNumber = function (number) {
90
- var phoneNumber = number.replace('-', '');
91
- return /^\d{8}$/.test(phoneNumber) || /^\d{9}$/.test(phoneNumber);
92
- };
93
- export var isValidNumberCode = function (numberCode) {
94
- return /^\d{2}$/.test(numberCode.replace(/[()]/g, ''));
95
- };
96
- export var isValidDDD = function (areaCode) {
97
- var dddList = [
98
- 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 24, 27, 28, 31, 32, 33, 34, 35,
99
- 37, 38, 41, 42, 43, 44, 45, 46, 47, 48, 49, 51, 53, 54, 55, 61, 62, 64, 63,
100
- 65, 66, 67, 68, 69, 71, 73, 74, 75, 77, 79, 81, 82, 83, 84, 85, 86, 87, 88,
101
- 89, 91, 92, 93, 94, 95, 96, 97, 98, 99
102
- ];
103
- return dddList.includes(parseFloat(areaCode === null || areaCode === void 0 ? void 0 : areaCode.replace(/\D/g, '')));
104
- };
105
- export var isValidChildDate = function (date) {
106
- if (!date)
107
- return 'Data inválida';
108
- var birthDate = parse(date, 'yyyy-MM-dd', new Date());
109
- if (!isValid(birthDate)) {
110
- return 'Data inválida';
111
- }
112
- var currentDate = new Date();
113
- var adultAge = subYears(currentDate, 18);
114
- if (isBefore(adultAge, birthDate) && isBefore(birthDate, currentDate)) {
115
- return true;
116
- }
117
- return 'Idade deve ser entre 1 a 17 anos';
118
- };
119
- export var isValidAdult = function (date) {
120
- if (!date)
121
- return 'Data inválida';
122
- var birthDate = parse(date, 'yyyy-MM-dd', new Date());
123
- if (!isValid(birthDate)) {
124
- return 'Data inválida';
125
- }
126
- var adultAge = subYears(new Date(), 18);
127
- return isBefore(birthDate, adultAge) || 'Adulto deve ter mais de 18 anos';
128
- };