@pedidopago/ui 1.5.18 → 1.5.20
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/dist/components/Icon/data/dash.js +1 -1
- package/dist/components/MultipleSelect/components/SelectArea/index.js +2 -2
- package/dist/components/MultipleSelect/components/SelectArea/types.d.ts +1 -1
- package/dist/components/MultipleSelect/components/SelectArea/types.d.ts.map +1 -1
- package/dist/components/MultipleSelect/index.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -0
- package/dist/shared/types/credit-card.d.ts +6 -0
- package/dist/shared/types/credit-card.d.ts.map +1 -0
- package/dist/shared/types/credit-card.js +1 -0
- package/dist/shared/types/file.d.ts +12 -0
- package/dist/shared/types/file.d.ts.map +1 -0
- package/dist/shared/types/file.js +1 -0
- package/dist/shared/types/name.d.ts +4 -0
- package/dist/shared/types/name.d.ts.map +1 -0
- package/dist/shared/types/name.js +1 -0
- package/dist/utils/file.d.ts +27 -0
- package/dist/utils/file.d.ts.map +1 -0
- package/dist/utils/file.js +160 -0
- package/dist/utils/formatters/bytes.d.ts +8 -0
- package/dist/utils/formatters/bytes.d.ts.map +1 -0
- package/dist/utils/formatters/bytes.js +22 -0
- package/dist/utils/formatters/capitalize.d.ts +7 -0
- package/dist/utils/formatters/capitalize.d.ts.map +1 -0
- package/dist/utils/formatters/capitalize.js +15 -0
- package/dist/utils/formatters/cep.d.ts +13 -0
- package/dist/utils/formatters/cep.d.ts.map +1 -0
- package/dist/utils/formatters/cep.js +26 -0
- package/dist/utils/formatters/cnpj.d.ts +19 -0
- package/dist/utils/formatters/cnpj.d.ts.map +1 -0
- package/dist/utils/formatters/cnpj.js +54 -0
- package/dist/utils/formatters/color.d.ts +16 -0
- package/dist/utils/formatters/color.d.ts.map +1 -0
- package/dist/utils/formatters/color.js +111 -0
- package/dist/utils/formatters/cpf.d.ts +19 -0
- package/dist/utils/formatters/cpf.d.ts.map +1 -0
- package/dist/utils/formatters/cpf.js +101 -0
- package/dist/utils/formatters/credit-card.d.ts +27 -0
- package/dist/utils/formatters/credit-card.d.ts.map +1 -0
- package/dist/utils/formatters/credit-card.js +80 -0
- package/dist/utils/formatters/email.d.ts +2 -0
- package/dist/utils/formatters/email.d.ts.map +1 -0
- package/dist/utils/formatters/email.js +8 -0
- package/dist/utils/formatters/index.d.ts +16 -0
- package/dist/utils/formatters/index.d.ts.map +1 -0
- package/dist/utils/formatters/index.js +200 -0
- package/dist/utils/formatters/name.d.ts +21 -0
- package/dist/utils/formatters/name.d.ts.map +1 -0
- package/dist/utils/formatters/name.js +46 -0
- package/dist/utils/formatters/number.d.ts +7 -0
- package/dist/utils/formatters/number.d.ts.map +1 -0
- package/dist/utils/formatters/number.js +18 -0
- package/dist/utils/formatters/passport.d.ts +25 -0
- package/dist/utils/formatters/passport.d.ts.map +1 -0
- package/dist/utils/formatters/passport.js +49 -0
- package/dist/utils/formatters/phone.d.ts +60 -0
- package/dist/utils/formatters/phone.d.ts.map +1 -0
- package/dist/utils/formatters/phone.js +209 -0
- package/dist/utils/formatters/price.d.ts +12 -0
- package/dist/utils/formatters/price.d.ts.map +1 -0
- package/dist/utils/formatters/price.js +28 -0
- package/dist/utils/formatters/rg.d.ts +13 -0
- package/dist/utils/formatters/rg.d.ts.map +1 -0
- package/dist/utils/formatters/rg.js +26 -0
- package/dist/utils/formatters/strings.d.ts +20 -0
- package/dist/utils/formatters/strings.d.ts.map +1 -0
- package/dist/utils/formatters/strings.js +42 -0
- package/package.json +4 -3
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats phone numbers with a default ddi of +55.
|
|
3
|
+
* @param {string} phone - The phone number to be formatted.
|
|
4
|
+
* @param {string} [ddi='+55'] - The default ddi to use.
|
|
5
|
+
* @returns {string} The formatted phone number.
|
|
6
|
+
*/
|
|
7
|
+
export declare function formatPhone(phone: string, ddi?: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Formats phone numbers with a default ddi of +55 and adds a country prefix if needed.
|
|
10
|
+
* @param {string} phone - The phone number to be formatted.
|
|
11
|
+
* @param {string} [ddi='+55'] - The default ddi to use.
|
|
12
|
+
* @returns {string} The formatted phone number with prefix.
|
|
13
|
+
*/
|
|
14
|
+
export declare function formatPhoneWithPrefix(phone?: string, ddi?: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Sanitizes phone numbers by removing all non-digit characters and leading zeroes.
|
|
17
|
+
* @param {string} phone - The phone number to be sanitized.
|
|
18
|
+
* @returns {string} The sanitized phone number.
|
|
19
|
+
*/
|
|
20
|
+
export declare function sanitizePhone(phone: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Validates if a phone number is valid according to Brazilian phone number rules.
|
|
23
|
+
* @param {string} phone - The phone number to be validated.
|
|
24
|
+
* @returns {boolean} - Returns true if the phone number is valid or false otherwise.
|
|
25
|
+
*/
|
|
26
|
+
export declare function phoneValidator(phone: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Parses a Brazilian phone number to add the ninth digit if needed or removes it if specified.
|
|
29
|
+
* @param {string} phone - The phone number to be parsed.
|
|
30
|
+
* @param {boolean} [remove] - If true, removes the ninth digit from the phone number. Defaults to false.
|
|
31
|
+
* @returns {string} - Returns the parsed phone number.
|
|
32
|
+
*/
|
|
33
|
+
export declare function phoneNineDigitParser(phone: string, remove?: boolean): string;
|
|
34
|
+
/**
|
|
35
|
+
* Verifies if a Brazilian phone number has the ninth digit added.
|
|
36
|
+
* @param {string} phone - The phone number to be verified.
|
|
37
|
+
* @param {object} [options] - The options to customize the error message. Default values: { errorMessage: 'Please include the digit "9" at the beginning of the number' }.
|
|
38
|
+
* @returns {boolean|string} - Returns true if first digit is nine, or an error message if the phone number is invalid.
|
|
39
|
+
*/
|
|
40
|
+
export declare function verifyNineDigit(phone: string, { errorMessage, }: {
|
|
41
|
+
errorMessage?: string;
|
|
42
|
+
}): boolean | string;
|
|
43
|
+
/**
|
|
44
|
+
* Returns a formatted phone number based on provided options.
|
|
45
|
+
* @param {string} phone - The phone number to be formatted.
|
|
46
|
+
* @param {object} options - The options to customize the format. Default values: { ddi: undefined, withDDI: false, keepDDI: false }.
|
|
47
|
+
* @returns {string} The formatted phone number.
|
|
48
|
+
*/
|
|
49
|
+
export declare function formatedPhone(phone: string, options?: {
|
|
50
|
+
ddi?: string;
|
|
51
|
+
withDDI?: boolean;
|
|
52
|
+
keepDDI?: boolean;
|
|
53
|
+
}): string;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the DDI (international dialing code) of a phone number.
|
|
56
|
+
* @param {string} number - The phone number to get the DDI from.
|
|
57
|
+
* @returns {string|null} The DDI.
|
|
58
|
+
*/
|
|
59
|
+
export declare function getDDI(number?: string): string | null;
|
|
60
|
+
//# sourceMappingURL=phone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone.d.ts","sourceRoot":"","sources":["../../../src/utils/formatters/phone.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,MAAc,GAAG,MAAM,CAetE;AACD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,GAAE,MAAc,GAAG,MAAM,CAkCjF;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAerD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,MAAM,CAmB1E;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,EACb,EACE,YAA4E,GAC7E,EAAE;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3B,OAAO,GAAG,MAAM,CAQlB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;IACP,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;CACd,GACL,MAAM,CA4BR;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQrD"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.formatPhone = formatPhone;
|
|
7
|
+
exports.formatPhoneWithPrefix = formatPhoneWithPrefix;
|
|
8
|
+
exports.formatedPhone = formatedPhone;
|
|
9
|
+
exports.getDDI = getDDI;
|
|
10
|
+
exports.phoneNineDigitParser = phoneNineDigitParser;
|
|
11
|
+
exports.phoneValidator = phoneValidator;
|
|
12
|
+
exports.sanitizePhone = sanitizePhone;
|
|
13
|
+
exports.verifyNineDigit = verifyNineDigit;
|
|
14
|
+
|
|
15
|
+
var _phone = _interopRequireDefault(require("phone"));
|
|
16
|
+
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Formats phone numbers with a default ddi of +55.
|
|
21
|
+
* @param {string} phone - The phone number to be formatted.
|
|
22
|
+
* @param {string} [ddi='+55'] - The default ddi to use.
|
|
23
|
+
* @returns {string} The formatted phone number.
|
|
24
|
+
*/
|
|
25
|
+
function formatPhone(phone) {
|
|
26
|
+
var ddi = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '+55';
|
|
27
|
+
|
|
28
|
+
if (phone) {
|
|
29
|
+
var sanitizedPhone = phone.replace(/[^\d]/g, '').replace(/^0/, '');
|
|
30
|
+
|
|
31
|
+
switch (ddi) {
|
|
32
|
+
case '+55':
|
|
33
|
+
return sanitizedPhone.replace(/^(\d{2}|\d{2})\B/, '($1) ').replace(/(\d{1}|\d{1})?(\d{4}|\d{4})(\d{4}|\d{4})/, '$1$2-$3');
|
|
34
|
+
|
|
35
|
+
default:
|
|
36
|
+
return sanitizedPhone;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Formats phone numbers with a default ddi of +55 and adds a country prefix if needed.
|
|
44
|
+
* @param {string} phone - The phone number to be formatted.
|
|
45
|
+
* @param {string} [ddi='+55'] - The default ddi to use.
|
|
46
|
+
* @returns {string} The formatted phone number with prefix.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
function formatPhoneWithPrefix(phone) {
|
|
51
|
+
var ddi = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '+55';
|
|
52
|
+
|
|
53
|
+
if (phone) {
|
|
54
|
+
var sanitizedPhone = phone.replace(/[^\d]/g, '').replace(/^0/, '');
|
|
55
|
+
|
|
56
|
+
switch (ddi) {
|
|
57
|
+
case '+55':
|
|
58
|
+
switch (sanitizedPhone.length) {
|
|
59
|
+
case 13:
|
|
60
|
+
{
|
|
61
|
+
return sanitizedPhone.replace(/^(\d{2}|\d{2})\B/, '+$1 ').replace(/(\d{2}|\d{2})?(\d{2}|\d{2})(\d{1}|\d{1})(\d{4}|\d{4})(\d{4}|\d{4})/, '$1 $2 $3 $4-$5');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
case 12:
|
|
65
|
+
{
|
|
66
|
+
return sanitizedPhone.replace(/^(\d{2}|\d{2})\B/, '+$1 ').replace(/(\d{2}|\d{2})?(\d{2}|\d{2})(\d{4}|\d{4})(\d{4}|\d{4})/, '$1 $2 $3-$4');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
case 11:
|
|
70
|
+
{
|
|
71
|
+
return sanitizedPhone.replace(/^(\d{2}|\d{2})\B/, '+$1 ').replace(/(\d{2}|\d{2})?(\d{1}|\d{1})(\d{4}|\d{4})(\d{4}|\d{4})/, '$1 $2 $3-$4');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
default:
|
|
75
|
+
return sanitizedPhone;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
default:
|
|
79
|
+
return sanitizedPhone;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return '';
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Sanitizes phone numbers by removing all non-digit characters and leading zeroes.
|
|
87
|
+
* @param {string} phone - The phone number to be sanitized.
|
|
88
|
+
* @returns {string} The sanitized phone number.
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
function sanitizePhone(phone) {
|
|
93
|
+
return phone ? phone.replace(/\D/g, '').replace(/^0/, '') : '';
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Validates if a phone number is valid according to Brazilian phone number rules.
|
|
97
|
+
* @param {string} phone - The phone number to be validated.
|
|
98
|
+
* @returns {boolean} - Returns true if the phone number is valid or false otherwise.
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
function phoneValidator(phone) {
|
|
103
|
+
var ddi = Number(phone.slice(0, 2));
|
|
104
|
+
var ddd = Number(phone.slice(2, 4));
|
|
105
|
+
var firstDigit = Number(phone.slice(4, 5));
|
|
106
|
+
var digits = phone.slice(4);
|
|
107
|
+
var allowed = [9, 8, 7, 6];
|
|
108
|
+
|
|
109
|
+
if (ddi === 55) {
|
|
110
|
+
return digits.length <= 9 ? allowed.includes(firstDigit) : ddd >= 30 ? allowed.includes(Number(phone.slice(5, 6))) : true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Parses a Brazilian phone number to add the ninth digit if needed or removes it if specified.
|
|
117
|
+
* @param {string} phone - The phone number to be parsed.
|
|
118
|
+
* @param {boolean} [remove] - If true, removes the ninth digit from the phone number. Defaults to false.
|
|
119
|
+
* @returns {string} - Returns the parsed phone number.
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
function phoneNineDigitParser(phone) {
|
|
124
|
+
var remove = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
125
|
+
|
|
126
|
+
if (phone) {
|
|
127
|
+
var replacedPhone = phone.replace(/[^0-9]/g, '');
|
|
128
|
+
var phoneWith9Number = replacedPhone.split('');
|
|
129
|
+
var phoneDdi = Number(phoneWith9Number.slice(0, 2).join(''));
|
|
130
|
+
var phoneDdd = Number(phoneWith9Number.slice(2, 4).join(''));
|
|
131
|
+
var phoneDigits = phoneWith9Number.slice(4).join('');
|
|
132
|
+
|
|
133
|
+
if (remove) {
|
|
134
|
+
return phoneDigits.length >= 9 && phoneDdi === 55 && phoneDdd > 30 ? phoneWith9Number.slice(0, 4).join('') + phoneWith9Number.slice(5).join('') : replacedPhone;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return phoneDigits.length === 8 && phoneDdi === 55 ? phoneWith9Number.slice(0, 4).join('') + '9' + phoneWith9Number.slice(4).join('') : replacedPhone;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return '';
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Verifies if a Brazilian phone number has the ninth digit added.
|
|
144
|
+
* @param {string} phone - The phone number to be verified.
|
|
145
|
+
* @param {object} [options] - The options to customize the error message. Default values: { errorMessage: 'Please include the digit "9" at the beginning of the number' }.
|
|
146
|
+
* @returns {boolean|string} - Returns true if first digit is nine, or an error message if the phone number is invalid.
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
function verifyNineDigit(phone, _ref) {
|
|
151
|
+
var _ref$errorMessage = _ref.errorMessage,
|
|
152
|
+
errorMessage = _ref$errorMessage === void 0 ? 'Please include the digit "9" at the beginning of the number' : _ref$errorMessage;
|
|
153
|
+
|
|
154
|
+
if (phone.length < 10) {
|
|
155
|
+
return 'Please enter a valid phone number';
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
var phoneWithoutDDD = phone.substring(2);
|
|
159
|
+
var firstDigitIsNineNumber = phoneWithoutDDD[0] === '9';
|
|
160
|
+
return firstDigitIsNineNumber || errorMessage;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Returns a formatted phone number based on provided options.
|
|
164
|
+
* @param {string} phone - The phone number to be formatted.
|
|
165
|
+
* @param {object} options - The options to customize the format. Default values: { ddi: undefined, withDDI: false, keepDDI: false }.
|
|
166
|
+
* @returns {string} The formatted phone number.
|
|
167
|
+
*/
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
function formatedPhone(phone) {
|
|
171
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
172
|
+
var result = ''; // If phone is provided.
|
|
173
|
+
|
|
174
|
+
if (phone) {
|
|
175
|
+
// If withDDI option is enabled, gets the DDI from the phone number.
|
|
176
|
+
if (options.withDDI) {
|
|
177
|
+
options.ddi = getDDI(phone.replaceAll('*', '0'));
|
|
178
|
+
} // Removes everything except digits and asterisks from the phone number and removes leading zeroes.
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
result = phone.replace(/[^\d*]/g, '').replace(/^0*/, ''); // Formats the phone number based on the DDI.
|
|
182
|
+
|
|
183
|
+
switch (options.ddi) {
|
|
184
|
+
case '55':
|
|
185
|
+
result = result.substring(0, 11).replace(/^(\d{2}|\*{2})\B/, '($1) ').replace(/(\d{1}|\*{1})?(\d{4}|\*{4})(\d{4}|\*{4})/, '$1$2-$3');
|
|
186
|
+
break;
|
|
187
|
+
|
|
188
|
+
default:
|
|
189
|
+
result = result.replace(/[^\d*-]/g, '');
|
|
190
|
+
}
|
|
191
|
+
} // If keepDDI option is enabled, returns the formatted phone number with the DDI.
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
return options !== null && options !== void 0 && options.keepDDI ? "".concat(options.ddi, " ").concat(result) : result;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Returns the DDI (international dialing code) of a phone number.
|
|
198
|
+
* @param {string} number - The phone number to get the DDI from.
|
|
199
|
+
* @returns {string|null} The DDI.
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
function getDDI(number) {
|
|
204
|
+
// Removes everything except digits from the phone number.
|
|
205
|
+
var phone = number === null || number === void 0 ? void 0 : number.replace(/\D/g, ''); // Gets the DDI using the phoneLib library.
|
|
206
|
+
|
|
207
|
+
var ddi = (0, _phone.default)('+' + phone);
|
|
208
|
+
return ddi.countryCode;
|
|
209
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a number or string into Brazilian Real currency format.
|
|
3
|
+
* @param {number | string} value - The value to format.
|
|
4
|
+
* @returns {string} The formatted value in BRL currency format.
|
|
5
|
+
*/
|
|
6
|
+
export declare function formatPrice(value: number | string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Converts a number of cents to a string representation of a price with the Brazilian Real currency symbol and format.
|
|
9
|
+
* @param {number} cents - The amount of cents to format.
|
|
10
|
+
*/
|
|
11
|
+
export declare function localeCents(cents: number): string;
|
|
12
|
+
//# sourceMappingURL=price.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"price.d.ts","sourceRoot":"","sources":["../../../src/utils/formatters/price.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAK1D;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEjD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.formatPrice = formatPrice;
|
|
7
|
+
exports.localeCents = localeCents;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Formats a number or string into Brazilian Real currency format.
|
|
11
|
+
* @param {number | string} value - The value to format.
|
|
12
|
+
* @returns {string} The formatted value in BRL currency format.
|
|
13
|
+
*/
|
|
14
|
+
function formatPrice(value) {
|
|
15
|
+
return value.toLocaleString('pt-BR', {
|
|
16
|
+
style: 'currency',
|
|
17
|
+
currency: 'BRL'
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Converts a number of cents to a string representation of a price with the Brazilian Real currency symbol and format.
|
|
22
|
+
* @param {number} cents - The amount of cents to format.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function localeCents(cents) {
|
|
27
|
+
return formatPrice(cents / 100);
|
|
28
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats the given RG string by removing any character that is not a number, comma, dot or space.
|
|
3
|
+
* @param {string} rg - The RG string to be formatted.
|
|
4
|
+
* @returns {string} - The formatted RG string.
|
|
5
|
+
*/
|
|
6
|
+
export declare function formatRG(rg: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Sanitizes the given RG string by removing dots and dashes and converting all characters to uppercase.
|
|
9
|
+
* @param {string} rg - The RG string to be sanitized.
|
|
10
|
+
* @returns {string} - The sanitized RG string.
|
|
11
|
+
*/
|
|
12
|
+
export declare function sanitizeRG(rg: string): string;
|
|
13
|
+
//# sourceMappingURL=rg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rg.d.ts","sourceRoot":"","sources":["../../../src/utils/formatters/rg.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE7C"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.formatRG = formatRG;
|
|
7
|
+
exports.sanitizeRG = sanitizeRG;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Formats the given RG string by removing any character that is not a number, comma, dot or space.
|
|
11
|
+
* @param {string} rg - The RG string to be formatted.
|
|
12
|
+
* @returns {string} - The formatted RG string.
|
|
13
|
+
*/
|
|
14
|
+
function formatRG(rg) {
|
|
15
|
+
return rg.replace(/[^\dA-z.-]/g, '');
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Sanitizes the given RG string by removing dots and dashes and converting all characters to uppercase.
|
|
19
|
+
* @param {string} rg - The RG string to be sanitized.
|
|
20
|
+
* @returns {string} - The sanitized RG string.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
function sanitizeRG(rg) {
|
|
25
|
+
return rg.replaceAll('.', '').replaceAll('-', '').toUpperCase();
|
|
26
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Truncates a string to a given character limit and adds ellipses at the end if necessary.
|
|
3
|
+
* @param {string} data - The string to truncate.
|
|
4
|
+
* @param {number} limit - The maximum number of characters the string can have.
|
|
5
|
+
* @returns {string} The truncated string.
|
|
6
|
+
*/
|
|
7
|
+
export declare function truncateString(data: string, limit: number): string;
|
|
8
|
+
/**
|
|
9
|
+
* Removes line breaks from a given string.
|
|
10
|
+
* @param {string} lineBreaks - The string to remove line breaks from.
|
|
11
|
+
* @returns {string} The string without line breaks.
|
|
12
|
+
*/
|
|
13
|
+
export declare function removeLineBreaks(lineBreaks: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Replaces multiple consecutive spaces in a string with a single space and trims the string.
|
|
16
|
+
* @param {string} string - The string to replace unnecessary spaces in.
|
|
17
|
+
* @returns {string} The string without unnecessary spaces.
|
|
18
|
+
*/
|
|
19
|
+
export declare function replaceUnecessarySpaces(string: string): string;
|
|
20
|
+
//# sourceMappingURL=strings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../../src/utils/formatters/strings.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAMlE;AACD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAE3D;AACD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE9D"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.removeLineBreaks = removeLineBreaks;
|
|
7
|
+
exports.replaceUnecessarySpaces = replaceUnecessarySpaces;
|
|
8
|
+
exports.truncateString = truncateString;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Truncates a string to a given character limit and adds ellipses at the end if necessary.
|
|
12
|
+
* @param {string} data - The string to truncate.
|
|
13
|
+
* @param {number} limit - The maximum number of characters the string can have.
|
|
14
|
+
* @returns {string} The truncated string.
|
|
15
|
+
*/
|
|
16
|
+
function truncateString(data, limit) {
|
|
17
|
+
if (data.length > limit) {
|
|
18
|
+
return data.substring(0, limit) + '...';
|
|
19
|
+
} else {
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Removes line breaks from a given string.
|
|
25
|
+
* @param {string} lineBreaks - The string to remove line breaks from.
|
|
26
|
+
* @returns {string} The string without line breaks.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
function removeLineBreaks(lineBreaks) {
|
|
31
|
+
return lineBreaks.replace(/\r?\n|\r|\n/g, ' ');
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Replaces multiple consecutive spaces in a string with a single space and trims the string.
|
|
35
|
+
* @param {string} string - The string to replace unnecessary spaces in.
|
|
36
|
+
* @returns {string} The string without unnecessary spaces.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
function replaceUnecessarySpaces(string) {
|
|
41
|
+
return string.replace(/ +/g, ' ').trim();
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pedidopago/ui",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.20",
|
|
4
4
|
"description": "Quick build beatiful Pedido Pago apps",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -24,8 +24,9 @@
|
|
|
24
24
|
"@emotion/react": "^11.4.0",
|
|
25
25
|
"@emotion/styled": "^11.3.0",
|
|
26
26
|
"framer-motion": "^4.1.17",
|
|
27
|
-
"
|
|
28
|
-
"react
|
|
27
|
+
"phone": "^3.1.33",
|
|
28
|
+
"react": "^18.2.0",
|
|
29
|
+
"react-dom": "^18.2.0"
|
|
29
30
|
},
|
|
30
31
|
"scripts": {
|
|
31
32
|
"start": "react-scripts start",
|