eai-frontend-components 2.0.63 → 2.0.65
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/ui/accordion.d.ts +8 -0
- package/dist/components/ui/accordion.d.ts.map +1 -0
- package/dist/components/ui/accordion.js +13 -0
- package/dist/components/ui/alert-dialog.d.ts +25 -0
- package/dist/components/ui/alert-dialog.d.ts.map +1 -0
- package/dist/components/ui/alert-dialog.js +26 -0
- package/dist/components/ui/alert.d.ts +9 -0
- package/dist/components/ui/alert.d.ts.map +1 -0
- package/dist/components/ui/alert.js +22 -0
- package/dist/components/ui/avatar.d.ts +7 -0
- package/dist/components/ui/avatar.d.ts.map +1 -0
- package/dist/components/ui/avatar.js +11 -0
- package/dist/components/ui/badge.d.ts +10 -0
- package/dist/components/ui/badge.d.ts.map +1 -0
- package/dist/components/ui/badge.js +26 -0
- package/dist/components/ui/breadcrumb.d.ts +20 -0
- package/dist/components/ui/breadcrumb.d.ts.map +1 -0
- package/dist/components/ui/breadcrumb.js +23 -0
- package/dist/components/ui/button.d.ts +12 -0
- package/dist/components/ui/button.d.ts.map +1 -0
- package/dist/components/ui/button.js +34 -0
- package/dist/components/ui/calendar.d.ts +9 -0
- package/dist/components/ui/calendar.d.ts.map +1 -0
- package/dist/components/ui/calendar.js +70 -0
- package/dist/components/ui/card.d.ts +9 -0
- package/dist/components/ui/card.d.ts.map +1 -0
- package/dist/components/ui/card.js +16 -0
- package/dist/components/ui/carousel.d.ts +19 -0
- package/dist/components/ui/carousel.d.ts.map +1 -0
- package/dist/components/ui/carousel.js +94 -0
- package/dist/components/ui/chart.d.ts +63 -0
- package/dist/components/ui/chart.d.ts.map +1 -0
- package/dist/components/ui/chart.js +111 -0
- package/dist/components/ui/checkbox.d.ts +5 -0
- package/dist/components/ui/checkbox.d.ts.map +1 -0
- package/dist/components/ui/checkbox.js +8 -0
- package/dist/components/ui/collapsible.d.ts +6 -0
- package/dist/components/ui/collapsible.d.ts.map +1 -0
- package/dist/components/ui/collapsible.js +5 -0
- package/dist/components/ui/command.d.ts +81 -0
- package/dist/components/ui/command.d.ts.map +1 -0
- package/dist/components/ui/command.js +28 -0
- package/dist/components/ui/context-menu.d.ts +28 -0
- package/dist/components/ui/context-menu.d.ts.map +1 -0
- package/dist/components/ui/context-menu.js +32 -0
- package/dist/components/ui/custom/date-picker.d.ts +12 -0
- package/dist/components/ui/custom/date-picker.d.ts.map +1 -0
- package/dist/components/ui/custom/date-picker.js +35 -0
- package/dist/components/ui/custom/form/checkbox.d.ts +13 -0
- package/dist/components/ui/custom/form/checkbox.d.ts.map +1 -0
- package/dist/components/ui/custom/form/checkbox.js +16 -0
- package/dist/components/ui/custom/form/color.d.ts +15 -0
- package/dist/components/ui/custom/form/color.d.ts.map +1 -0
- package/dist/components/ui/custom/form/color.js +41 -0
- package/dist/components/ui/custom/form/combobox.d.ts +39 -0
- package/dist/components/ui/custom/form/combobox.d.ts.map +1 -0
- package/dist/components/ui/custom/form/combobox.js +88 -0
- package/dist/components/ui/custom/form/cpf-cnpj.d.ts +16 -0
- package/dist/components/ui/custom/form/cpf-cnpj.d.ts.map +1 -0
- package/dist/components/ui/custom/form/cpf-cnpj.js +32 -0
- package/dist/components/ui/custom/form/currency.d.ts +14 -0
- package/dist/components/ui/custom/form/currency.d.ts.map +1 -0
- package/dist/components/ui/custom/form/currency.js +15 -0
- package/dist/components/ui/custom/form/date-range.d.ts +16 -0
- package/dist/components/ui/custom/form/date-range.d.ts.map +1 -0
- package/dist/components/ui/custom/form/date-range.js +24 -0
- package/dist/components/ui/custom/form/date.d.ts +16 -0
- package/dist/components/ui/custom/form/date.d.ts.map +1 -0
- package/dist/components/ui/custom/form/date.js +34 -0
- package/dist/components/ui/custom/form/decimal.d.ts +14 -0
- package/dist/components/ui/custom/form/decimal.d.ts.map +1 -0
- package/dist/components/ui/custom/form/decimal.js +15 -0
- package/dist/components/ui/custom/form/file.d.ts +15 -0
- package/dist/components/ui/custom/form/file.d.ts.map +1 -0
- package/dist/components/ui/custom/form/file.js +18 -0
- package/dist/components/ui/custom/form/form-help-text.d.ts +3 -0
- package/dist/components/ui/custom/form/form-help-text.d.ts.map +1 -0
- package/dist/components/ui/custom/form/form-help-text.js +7 -0
- package/dist/components/ui/custom/form/form-label.d.ts +7 -0
- package/dist/components/ui/custom/form/form-label.d.ts.map +1 -0
- package/dist/components/ui/custom/form/form-label.js +9 -0
- package/dist/components/ui/custom/form/form-message.d.ts +5 -0
- package/dist/components/ui/custom/form/form-message.d.ts.map +1 -0
- package/dist/components/ui/custom/form/form-message.js +5 -0
- package/dist/components/ui/custom/form/ghost.d.ts +8 -0
- package/dist/components/ui/custom/form/ghost.d.ts.map +1 -0
- package/dist/components/ui/custom/form/ghost.js +8 -0
- package/dist/components/ui/custom/form/input.d.ts +18 -0
- package/dist/components/ui/custom/form/input.d.ts.map +1 -0
- package/dist/components/ui/custom/form/input.js +14 -0
- package/dist/components/ui/custom/form/mask.d.ts +19 -0
- package/dist/components/ui/custom/form/mask.d.ts.map +1 -0
- package/dist/components/ui/custom/form/mask.js +19 -0
- package/dist/components/ui/custom/form/multi-select.d.ts +26 -0
- package/dist/components/ui/custom/form/multi-select.d.ts.map +1 -0
- package/dist/components/ui/custom/form/multi-select.js +66 -0
- package/dist/components/ui/custom/form/password.d.ts +16 -0
- package/dist/components/ui/custom/form/password.d.ts.map +1 -0
- package/dist/components/ui/custom/form/password.js +14 -0
- package/dist/components/ui/custom/form/percent.d.ts +14 -0
- package/dist/components/ui/custom/form/percent.d.ts.map +1 -0
- package/dist/components/ui/custom/form/percent.js +15 -0
- package/dist/components/ui/custom/form/phone.d.ts +16 -0
- package/dist/components/ui/custom/form/phone.d.ts.map +1 -0
- package/dist/components/ui/custom/form/phone.js +17 -0
- package/dist/components/ui/custom/form/radio-group.d.ts +23 -0
- package/dist/components/ui/custom/form/radio-group.d.ts.map +1 -0
- package/dist/components/ui/custom/form/radio-group.js +14 -0
- package/dist/components/ui/custom/form/select.d.ts +20 -0
- package/dist/components/ui/custom/form/select.d.ts.map +1 -0
- package/dist/components/ui/custom/form/select.js +12 -0
- package/dist/components/ui/custom/form/step-new-form.d.ts +10 -0
- package/dist/components/ui/custom/form/step-new-form.d.ts.map +1 -0
- package/dist/components/ui/custom/form/step-new-form.js +13 -0
- package/dist/components/ui/custom/form/switch.d.ts +14 -0
- package/dist/components/ui/custom/form/switch.d.ts.map +1 -0
- package/dist/components/ui/custom/form/switch.js +16 -0
- package/dist/components/ui/custom/form/text.d.ts +18 -0
- package/dist/components/ui/custom/form/text.d.ts.map +1 -0
- package/dist/components/ui/custom/form/text.js +14 -0
- package/dist/components/ui/custom/form/textarea.d.ts +16 -0
- package/dist/components/ui/custom/form/textarea.d.ts.map +1 -0
- package/dist/components/ui/custom/form/textarea.js +19 -0
- package/dist/components/ui/custom/form/utils.d.ts +18 -0
- package/dist/components/ui/custom/form/utils.d.ts.map +1 -0
- package/dist/components/ui/custom/form/utils.js +88 -0
- package/dist/components/ui/custom/header.d.ts +11 -0
- package/dist/components/ui/custom/header.d.ts.map +1 -0
- package/dist/components/ui/custom/header.js +74 -0
- package/dist/components/ui/custom/label.d.ts +18 -0
- package/dist/components/ui/custom/label.d.ts.map +1 -0
- package/dist/components/ui/custom/label.js +20 -0
- package/dist/components/ui/custom/not-found.d.ts +3 -0
- package/dist/components/ui/custom/not-found.d.ts.map +1 -0
- package/dist/components/ui/custom/not-found.js +9 -0
- package/dist/components/ui/custom/responsive-dialog.d.ts +24 -0
- package/dist/components/ui/custom/responsive-dialog.d.ts.map +1 -0
- package/dist/components/ui/custom/responsive-dialog.js +32 -0
- package/dist/components/ui/custom/sidebar/module-switcher.d.ts +9 -0
- package/dist/components/ui/custom/sidebar/module-switcher.d.ts.map +1 -0
- package/dist/components/ui/custom/sidebar/module-switcher.js +24 -0
- package/dist/components/ui/custom/sidebar/nav-footer.d.ts +7 -0
- package/dist/components/ui/custom/sidebar/nav-footer.d.ts.map +1 -0
- package/dist/components/ui/custom/sidebar/nav-footer.js +13 -0
- package/dist/components/ui/custom/sidebar/nav-main.d.ts +7 -0
- package/dist/components/ui/custom/sidebar/nav-main.d.ts.map +1 -0
- package/dist/components/ui/custom/sidebar/nav-main.js +26 -0
- package/dist/components/ui/custom/sidebar/nav-submenu-collapsible.d.ts +9 -0
- package/dist/components/ui/custom/sidebar/nav-submenu-collapsible.d.ts.map +1 -0
- package/dist/components/ui/custom/sidebar/nav-submenu-collapsible.js +17 -0
- package/dist/components/ui/custom/sidebar/nav-submenu-dropdown.d.ts +10 -0
- package/dist/components/ui/custom/sidebar/nav-submenu-dropdown.d.ts.map +1 -0
- package/dist/components/ui/custom/sidebar/nav-submenu-dropdown.js +9 -0
- package/dist/components/ui/custom/sidebar/nav-user.d.ts +9 -0
- package/dist/components/ui/custom/sidebar/nav-user.d.ts.map +1 -0
- package/dist/components/ui/custom/sidebar/nav-user.js +24 -0
- package/dist/components/ui/custom/sidebar/sidebar-button.d.ts +9 -0
- package/dist/components/ui/custom/sidebar/sidebar-button.d.ts.map +1 -0
- package/dist/components/ui/custom/sidebar/sidebar-button.js +7 -0
- package/dist/components/ui/custom/sidebar/sidebar-item-two-lines.d.ts +12 -0
- package/dist/components/ui/custom/sidebar/sidebar-item-two-lines.d.ts.map +1 -0
- package/dist/components/ui/custom/sidebar/sidebar-item-two-lines.js +5 -0
- package/dist/components/ui/custom/sidebar/sidebar-item.d.ts +9 -0
- package/dist/components/ui/custom/sidebar/sidebar-item.d.ts.map +1 -0
- package/dist/components/ui/custom/sidebar/sidebar-item.js +7 -0
- package/dist/components/ui/custom/sidebar/types/sidebar.d.ts +29 -0
- package/dist/components/ui/custom/sidebar/types/sidebar.d.ts.map +1 -0
- package/dist/components/ui/custom/sidebar/types/sidebar.js +5 -0
- package/dist/components/ui/custom/table/data-table-export.d.ts +8 -0
- package/dist/components/ui/custom/table/data-table-export.d.ts.map +1 -0
- package/dist/components/ui/custom/table/data-table-export.js +66 -0
- package/dist/components/ui/custom/table/data-table-footer.d.ts +25 -0
- package/dist/components/ui/custom/table/data-table-footer.d.ts.map +1 -0
- package/dist/components/ui/custom/table/data-table-footer.js +39 -0
- package/dist/components/ui/custom/table/data-table-header.d.ts +9 -0
- package/dist/components/ui/custom/table/data-table-header.d.ts.map +1 -0
- package/dist/components/ui/custom/table/data-table-header.js +11 -0
- package/dist/components/ui/custom/table/data-table-rows.d.ts +13 -0
- package/dist/components/ui/custom/table/data-table-rows.d.ts.map +1 -0
- package/dist/components/ui/custom/table/data-table-rows.js +25 -0
- package/dist/components/ui/custom/table/data-table.d.ts +35 -0
- package/dist/components/ui/custom/table/data-table.d.ts.map +1 -0
- package/dist/components/ui/custom/table/data-table.js +99 -0
- package/dist/components/ui/custom/table/types/data-table.d.ts +29 -0
- package/dist/components/ui/custom/table/types/data-table.d.ts.map +1 -0
- package/dist/components/ui/custom/table/types/data-table.js +1 -0
- package/dist/components/ui/custom/theme-provider.d.ts +24 -0
- package/dist/components/ui/custom/theme-provider.d.ts.map +1 -0
- package/dist/components/ui/custom/theme-provider.js +79 -0
- package/dist/components/ui/dateRangePicker.d.ts +3 -0
- package/dist/components/ui/dateRangePicker.d.ts.map +1 -0
- package/dist/components/ui/dateRangePicker.js +15 -0
- package/dist/components/ui/dialog.d.ts +23 -0
- package/dist/components/ui/dialog.d.ts.map +1 -0
- package/dist/components/ui/dialog.js +22 -0
- package/dist/components/ui/drawer.d.ts +23 -0
- package/dist/components/ui/drawer.d.ts.map +1 -0
- package/dist/components/ui/drawer.js +22 -0
- package/dist/components/ui/dropdown-menu.d.ts +28 -0
- package/dist/components/ui/dropdown-menu.d.ts.map +1 -0
- package/dist/components/ui/dropdown-menu.js +32 -0
- package/dist/components/ui/form.d.ts +24 -0
- package/dist/components/ui/form.d.ts.map +1 -0
- package/dist/components/ui/form.js +60 -0
- package/dist/components/ui/hover-card.d.ts +7 -0
- package/dist/components/ui/hover-card.d.ts.map +1 -0
- package/dist/components/ui/hover-card.js +9 -0
- package/dist/components/ui/input.d.ts +24 -0
- package/dist/components/ui/input.d.ts.map +1 -0
- package/dist/components/ui/input.js +51 -0
- package/dist/components/ui/label.d.ts +6 -0
- package/dist/components/ui/label.d.ts.map +1 -0
- package/dist/components/ui/label.js +9 -0
- package/dist/components/ui/masks.d.ts +89 -0
- package/dist/components/ui/masks.d.ts.map +1 -0
- package/dist/components/ui/masks.js +92 -0
- package/dist/components/ui/pagination.d.ts +30 -0
- package/dist/components/ui/pagination.d.ts.map +1 -0
- package/dist/components/ui/pagination.js +23 -0
- package/dist/components/ui/popover.d.ts +7 -0
- package/dist/components/ui/popover.d.ts.map +1 -0
- package/dist/components/ui/popover.js +11 -0
- package/dist/components/ui/progress.d.ts +5 -0
- package/dist/components/ui/progress.d.ts.map +1 -0
- package/dist/components/ui/progress.js +7 -0
- package/dist/components/ui/radio-group.d.ts +6 -0
- package/dist/components/ui/radio-group.d.ts.map +1 -0
- package/dist/components/ui/radio-group.js +14 -0
- package/dist/components/ui/scroll-area.d.ts +6 -0
- package/dist/components/ui/scroll-area.d.ts.map +1 -0
- package/dist/components/ui/scroll-area.js +9 -0
- package/dist/components/ui/select.d.ts +14 -0
- package/dist/components/ui/select.d.ts.map +1 -0
- package/dist/components/ui/select.js +24 -0
- package/dist/components/ui/separator.d.ts +5 -0
- package/dist/components/ui/separator.d.ts.map +1 -0
- package/dist/components/ui/separator.js +7 -0
- package/dist/components/ui/sheet.d.ts +26 -0
- package/dist/components/ui/sheet.d.ts.map +1 -0
- package/dist/components/ui/sheet.js +36 -0
- package/dist/components/ui/sidebar.d.ts +67 -0
- package/dist/components/ui/sidebar.d.ts.map +1 -0
- package/dist/components/ui/sidebar.js +221 -0
- package/dist/components/ui/skeleton.d.ts +3 -0
- package/dist/components/ui/skeleton.d.ts.map +1 -0
- package/dist/components/ui/skeleton.js +6 -0
- package/dist/components/ui/slider.d.ts +5 -0
- package/dist/components/ui/slider.d.ts.map +1 -0
- package/dist/components/ui/slider.js +7 -0
- package/dist/components/ui/switch.d.ts +5 -0
- package/dist/components/ui/switch.d.ts.map +1 -0
- package/dist/components/ui/switch.js +7 -0
- package/dist/components/ui/table.d.ts +11 -0
- package/dist/components/ui/table.d.ts.map +1 -0
- package/dist/components/ui/table.js +20 -0
- package/dist/components/ui/tabs.d.ts +8 -0
- package/dist/components/ui/tabs.d.ts.map +1 -0
- package/dist/components/ui/tabs.js +12 -0
- package/dist/components/ui/textarea.d.ts +4 -0
- package/dist/components/ui/textarea.d.ts.map +1 -0
- package/dist/components/ui/textarea.js +14 -0
- package/dist/components/ui/toast.d.ts +16 -0
- package/dist/components/ui/toast.d.ts.map +1 -0
- package/dist/components/ui/toast.js +34 -0
- package/dist/components/ui/toaster.d.ts +2 -0
- package/dist/components/ui/toaster.d.ts.map +1 -0
- package/dist/components/ui/toaster.js +21 -0
- package/dist/components/ui/tooltip.d.ts +8 -0
- package/dist/components/ui/tooltip.d.ts.map +1 -0
- package/dist/components/ui/tooltip.js +10 -0
- package/dist/components/ui/use-calendar.d.ts +7 -0
- package/dist/components/ui/use-calendar.d.ts.map +1 -0
- package/dist/components/ui/use-calendar.js +23 -0
- package/dist/components/ui/use-toast.d.ts +46 -0
- package/dist/components/ui/use-toast.d.ts.map +1 -0
- package/dist/components/ui/use-toast.js +124 -0
- package/dist/hooks/use-mobile.d.ts +2 -0
- package/dist/hooks/use-mobile.d.ts.map +1 -0
- package/dist/hooks/use-mobile.js +4 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/help/date-utils.d.ts +9 -0
- package/dist/lib/help/date-utils.d.ts.map +1 -0
- package/dist/lib/help/date-utils.js +65 -0
- package/dist/lib/help/download.d.ts +2 -0
- package/dist/lib/help/download.d.ts.map +1 -0
- package/dist/lib/help/download.js +26 -0
- package/dist/lib/help/format.d.ts +133 -0
- package/dist/lib/help/format.d.ts.map +1 -0
- package/dist/lib/help/format.js +268 -0
- package/dist/lib/help/theme.d.ts +291 -0
- package/dist/lib/help/theme.d.ts.map +1 -0
- package/dist/lib/help/theme.js +340 -0
- package/dist/lib/help/uuid.d.ts +2 -0
- package/dist/lib/help/uuid.d.ts.map +1 -0
- package/dist/lib/help/uuid.js +4 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const getFirstDayOfCurrentMonth: () => Date;
|
|
2
|
+
export declare const getFirstDayOf90DaysAgo: () => Date;
|
|
3
|
+
export declare const stringToDate: (dateString: string, separator?: string) => Date | undefined;
|
|
4
|
+
export declare const aYearAgo: () => Date;
|
|
5
|
+
export declare const invertDate: (date: string, separator?: string) => string;
|
|
6
|
+
export declare const addDaysToToday: (days: number) => Date;
|
|
7
|
+
export declare const isValidDate: (date: Date | undefined) => date is Date;
|
|
8
|
+
export declare const isDateRangeValid: (startDate: Date, endDate: Date, maxDays?: number) => boolean;
|
|
9
|
+
//# sourceMappingURL=date-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/help/date-utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,QAAO,IAG5C,CAAC;AAEF,eAAO,MAAM,sBAAsB,QAAO,IAGzC,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,YAAY,MAAM,EAAE,YAAW,MAAY,KAAG,IAAI,GAAG,SAwCjF,CAAC;AAEF,eAAO,MAAM,QAAQ,QAAO,IAK3B,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,EAAE,YAAW,MAAY,KAAG,MAIlE,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,IAI7C,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,GAAG,SAAS,KAAG,IAAI,IAAI,IAE5D,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,WAAW,IAAI,EAAE,SAAS,IAAI,EAAE,UAAS,MAAW,KAAG,OAIvF,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export const getFirstDayOfCurrentMonth = () => {
|
|
2
|
+
const now = new Date();
|
|
3
|
+
return new Date(now.getFullYear(), now.getMonth(), 1);
|
|
4
|
+
};
|
|
5
|
+
export const getFirstDayOf90DaysAgo = () => {
|
|
6
|
+
const now = new Date();
|
|
7
|
+
return new Date(now.getFullYear(), now.getMonth() - 3, 1);
|
|
8
|
+
};
|
|
9
|
+
export const stringToDate = (dateString, separator = '/') => {
|
|
10
|
+
if (!dateString)
|
|
11
|
+
return undefined;
|
|
12
|
+
const dateParts = dateString.split(separator);
|
|
13
|
+
if (dateParts.length !== 3)
|
|
14
|
+
return undefined;
|
|
15
|
+
const day = parseInt(dateParts[0], 10);
|
|
16
|
+
const month = parseInt(dateParts[1], 10);
|
|
17
|
+
const year = parseInt(dateParts[2], 10);
|
|
18
|
+
// Validar se os valores são números válidos
|
|
19
|
+
if (Number.isNaN(day) || Number.isNaN(month) || Number.isNaN(year)) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
// Validar mês (1-12)
|
|
23
|
+
if (month < 1 || month > 12) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
// Validar ano
|
|
27
|
+
if (year < 1900 || year > 2100) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
// Validar dia dentro do mês
|
|
31
|
+
const daysInMonth = new Date(year, month, 0).getDate();
|
|
32
|
+
if (day < 1 || day > daysInMonth) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
// JavaScript usa meses zero-based (0-11)
|
|
36
|
+
const date = new Date(year, month - 1, day);
|
|
37
|
+
// Verificação adicional: garantir que a data criada corresponde aos valores fornecidos
|
|
38
|
+
if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
return date;
|
|
42
|
+
};
|
|
43
|
+
export const aYearAgo = () => {
|
|
44
|
+
const aYearAgo = new Date();
|
|
45
|
+
aYearAgo.setFullYear(aYearAgo.getFullYear() - 1);
|
|
46
|
+
return aYearAgo;
|
|
47
|
+
};
|
|
48
|
+
export const invertDate = (date, separator = '/') => {
|
|
49
|
+
if (!date)
|
|
50
|
+
return '';
|
|
51
|
+
return date.split(separator).reverse().join('-');
|
|
52
|
+
};
|
|
53
|
+
export const addDaysToToday = (days) => {
|
|
54
|
+
const date = new Date();
|
|
55
|
+
date.setDate(date.getDate() + days);
|
|
56
|
+
return date;
|
|
57
|
+
};
|
|
58
|
+
export const isValidDate = (date) => {
|
|
59
|
+
return date instanceof Date && !Number.isNaN(date.getTime());
|
|
60
|
+
};
|
|
61
|
+
export const isDateRangeValid = (startDate, endDate, maxDays = 90) => {
|
|
62
|
+
const diffInMs = endDate.getTime() - startDate.getTime();
|
|
63
|
+
const diffInDays = diffInMs / (1000 * 60 * 60 * 24);
|
|
64
|
+
return diffInDays <= maxDays;
|
|
65
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../../src/lib/help/download.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,yBAAyB,GAAU,aAAa,MAAM,EAAE,UAAU,MAAM,kBAyBpF,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { toast } from '@/components/ui/use-toast';
|
|
2
|
+
export const downloadWithServiceWorker = async (urlDownload, fileName) => {
|
|
3
|
+
try {
|
|
4
|
+
const response = await fetch(urlDownload);
|
|
5
|
+
if (!response.ok) {
|
|
6
|
+
throw new Error('Erro ao fazer o download');
|
|
7
|
+
}
|
|
8
|
+
const blob = await response.blob();
|
|
9
|
+
const url = window.URL.createObjectURL(blob);
|
|
10
|
+
const a = document.createElement('a');
|
|
11
|
+
a.href = url;
|
|
12
|
+
a.download = fileName;
|
|
13
|
+
document.body.appendChild(a);
|
|
14
|
+
a.click();
|
|
15
|
+
document.body.removeChild(a);
|
|
16
|
+
window.URL.revokeObjectURL(url);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
toast({
|
|
20
|
+
title: 'Erro ao fazer o download',
|
|
21
|
+
description: error instanceof Error ? error.message : 'Tente novamente mais tarde.',
|
|
22
|
+
variant: 'destructive',
|
|
23
|
+
});
|
|
24
|
+
console.error(error);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a phone number string with proper mask.
|
|
3
|
+
* Automatically detects landline vs mobile format.
|
|
4
|
+
*
|
|
5
|
+
* @param telefone - Raw phone number string
|
|
6
|
+
* @param removeDDD - Whether to remove DDD (area code) from the formatted output
|
|
7
|
+
* @param removeCountryCode - Whether to remove country code (55) if present
|
|
8
|
+
* @returns Formatted phone number string
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* formatPhone('11987654321') // '(11) 9 8765-4321'
|
|
13
|
+
* formatPhone('1134567890') // '(11) 3456-7890'
|
|
14
|
+
* formatPhone('11987654321', true) // '9 8765-4321'
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatPhone(telefone: string, removeDDD?: boolean, removeCountryCode?: boolean): string;
|
|
18
|
+
/**
|
|
19
|
+
* Formats a CPF or CNPJ string with proper mask.
|
|
20
|
+
* Automatically detects CPF vs CNPJ format based on length.
|
|
21
|
+
*
|
|
22
|
+
* @param cpfCnpj - Raw CPF/CNPJ string
|
|
23
|
+
* @returns Formatted CPF/CNPJ string
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* formatCpfCnpj('12345678901') // '123.456.789-01'
|
|
28
|
+
* formatCpfCnpj('12345678000195') // '12.345.678/0001-95'
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function formatCpfCnpj(cpfCnpj?: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Formats a date to Brazilian format (DD/MM/YYYY).
|
|
34
|
+
*
|
|
35
|
+
* @param date - Date string, Date object, or undefined
|
|
36
|
+
* @param separator - Date separator (default: '/')
|
|
37
|
+
* @returns Formatted date string in Brazilian format
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* formatDate('2023-12-25') // '25/12/2023'
|
|
42
|
+
* formatDate(new Date()) // '13/10/2025'
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const formatDate: (date: string | Date | undefined, _separator?: string) => string;
|
|
46
|
+
export declare const formatDateTime: (date: Date | undefined, returnSeconds?: boolean) => string;
|
|
47
|
+
export declare function formatDateCalendar(date: Date | undefined): string;
|
|
48
|
+
export declare function stringDateToDate(date: string | undefined, separator?: string): Date | undefined;
|
|
49
|
+
export declare const roundNumber: (value: number, fractionDigits?: number) => number;
|
|
50
|
+
export declare const stringToNumber: (value: string | undefined) => number;
|
|
51
|
+
declare enum InternetAmountUnity {
|
|
52
|
+
iauMegabyte = 0,
|
|
53
|
+
iauGigabyte = 1,
|
|
54
|
+
UNRECOGNIZED = -1
|
|
55
|
+
}
|
|
56
|
+
export declare const convertInternetToDisplay: (internet: number, unit: InternetAmountUnity) => string;
|
|
57
|
+
export declare const convertMbToGb: (value: number) => number;
|
|
58
|
+
export declare const convertGbToMb: (value: number) => number;
|
|
59
|
+
export declare const convertSecondsToMinutes: (value: number) => number;
|
|
60
|
+
export declare const convertBytesToMB: (bytes: number) => number;
|
|
61
|
+
export declare const convertMonthToDays: (months: number) => number;
|
|
62
|
+
export declare const convertDaysToMonth: (days: number) => number;
|
|
63
|
+
export declare const formatNumber: (value: number) => string;
|
|
64
|
+
/**
|
|
65
|
+
* Formats a number with Brazilian decimal format.
|
|
66
|
+
*
|
|
67
|
+
* @param value - Numeric value to format
|
|
68
|
+
* @param decimalPlaces - Number of decimal places (default: 2)
|
|
69
|
+
* @returns Formatted decimal string
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```tsx
|
|
73
|
+
* formatDecimal(1234.56) // '1.234,56'
|
|
74
|
+
* formatDecimal(1000.1, 1) // '1.000,1'
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare const formatDecimal: (value: number, decimalPlaces?: number) => string;
|
|
78
|
+
/**
|
|
79
|
+
* Formats a number as percentage with Brazilian decimal format.
|
|
80
|
+
*
|
|
81
|
+
* @param value - Numeric value to format
|
|
82
|
+
* @param decimalPlaces - Number of decimal places (default: 2)
|
|
83
|
+
* @returns Formatted percentage string
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```tsx
|
|
87
|
+
* formatPercent(15.5) // '% 15,50'
|
|
88
|
+
* formatPercent(100, 0) // '% 100'
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare const formatPercent: (value: number, decimalPlaces?: number) => string;
|
|
92
|
+
/**
|
|
93
|
+
* Formats a number as Brazilian currency (BRL).
|
|
94
|
+
*
|
|
95
|
+
* @param value - Numeric value to format
|
|
96
|
+
* @param decimalPlaces - Number of decimal places (default: 2)
|
|
97
|
+
* @returns Formatted currency string
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```tsx
|
|
101
|
+
* formatCurrency(1234.56) // 'R$ 1.234,56'
|
|
102
|
+
* formatCurrency(1000, 0) // 'R$ 1.000'
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare const formatCurrency: (value: number, decimalPlaces?: number) => string;
|
|
106
|
+
export declare const isInvalidCurrencyValue: (rawValue: string | undefined) => boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Formats an MSISDN (mobile phone number) to display format.
|
|
109
|
+
*
|
|
110
|
+
* @param value - Raw MSISDN string
|
|
111
|
+
* @returns Formatted MSISDN string
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```tsx
|
|
115
|
+
* formatMsisdn('5511987654321') // '(11) 98765-4321'
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function formatMsisdn(value?: string): string;
|
|
119
|
+
/**
|
|
120
|
+
* Formats a CEP (Brazilian postal code) with proper mask.
|
|
121
|
+
*
|
|
122
|
+
* @param cep - Raw CEP string
|
|
123
|
+
* @returns Formatted CEP string (XXXXX-XXX)
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```tsx
|
|
127
|
+
* formatCEP('01234567') // '01234-567'
|
|
128
|
+
* formatCEP('12345') // '12345'
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export declare function formatCEP(cep?: string): string;
|
|
132
|
+
export {};
|
|
133
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/lib/help/format.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,UAAQ,EAAE,iBAAiB,UAAO,UAoBxF;AAGD;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAMtD;AAeD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,aAAY,MAAY,WAMnF,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,MAAM,IAAI,GAAG,SAAS,EAAE,gBAAe,OAAe,KAAG,MAQvF,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,GAAG,MAAM,CAQjE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,SAAS,GAAE,MAAY,GAAG,IAAI,GAAG,SAAS,CAOpG;AAGD,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,EAAE,iBAAgB,MAAU,KAAG,MAEvE,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,GAAG,SAAS,KAAG,MAQ1D,CAAC;AAEF,aAAK,mBAAmB;IACvB,WAAW,IAAI;IACf,WAAW,IAAI;IACf,YAAY,KAAK;CACjB;AAED,eAAO,MAAM,wBAAwB,GAAI,UAAU,MAAM,EAAE,MAAM,mBAAmB,KAAG,MAUtF,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,WAE1C,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,WAE1C,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,OAAO,MAAM,KAAG,MAEvD,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,KAAG,MAGhD,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,QAAQ,MAAM,KAAG,MAEnD,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,MAEjD,CAAC;AAGF,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,WAMzC,CAAC;AAGF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,EAAE,gBAAe,MAAU,WAMrE,CAAC;AAGF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,EAAE,gBAAe,MAAU,WAErE,CAAC;AAGF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,EAAE,gBAAe,MAAU,WAOtE,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,UAAU,MAAM,GAAG,SAAS,KAAG,OAMrE,CAAC;AAGF;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,KAAK,GAAE,MAAW,GAAG,MAAM,CAGvD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,UAOrC"}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { format } from '@react-input/mask';
|
|
2
|
+
import { maskCpfCnpj, maskPhone } from '../../components/ui/masks';
|
|
3
|
+
// PHONE
|
|
4
|
+
/**
|
|
5
|
+
* Formats a phone number string with proper mask.
|
|
6
|
+
* Automatically detects landline vs mobile format.
|
|
7
|
+
*
|
|
8
|
+
* @param telefone - Raw phone number string
|
|
9
|
+
* @param removeDDD - Whether to remove DDD (area code) from the formatted output
|
|
10
|
+
* @param removeCountryCode - Whether to remove country code (55) if present
|
|
11
|
+
* @returns Formatted phone number string
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* formatPhone('11987654321') // '(11) 9 8765-4321'
|
|
16
|
+
* formatPhone('1134567890') // '(11) 3456-7890'
|
|
17
|
+
* formatPhone('11987654321', true) // '9 8765-4321'
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function formatPhone(telefone, removeDDD = false, removeCountryCode = true) {
|
|
21
|
+
if (!telefone)
|
|
22
|
+
return '';
|
|
23
|
+
let numberPhone = telefone.replace(/\D/g, '');
|
|
24
|
+
// Remover código do país apenas se ele começar com '55'
|
|
25
|
+
if (removeCountryCode && numberPhone.startsWith('55')) {
|
|
26
|
+
numberPhone = numberPhone.substring(2);
|
|
27
|
+
}
|
|
28
|
+
// Se removeDDD for true, remover os dois primeiros dígitos (DDD)
|
|
29
|
+
if (removeDDD && numberPhone.length >= 10) {
|
|
30
|
+
const phoneWithoutDDD = numberPhone.substring(2);
|
|
31
|
+
// Aplicar máscara sem DDD
|
|
32
|
+
const isMobile = phoneWithoutDDD.length === 9;
|
|
33
|
+
const mask = isMobile ? { mask: '_ ____-____', replacement: { _: /\d/ } } : { mask: '____-_____', replacement: { _: /\d/ } };
|
|
34
|
+
return format(phoneWithoutDDD, mask);
|
|
35
|
+
}
|
|
36
|
+
return format(numberPhone, maskPhone(numberPhone));
|
|
37
|
+
}
|
|
38
|
+
// CPF/CNPJ
|
|
39
|
+
/**
|
|
40
|
+
* Formats a CPF or CNPJ string with proper mask.
|
|
41
|
+
* Automatically detects CPF vs CNPJ format based on length.
|
|
42
|
+
*
|
|
43
|
+
* @param cpfCnpj - Raw CPF/CNPJ string
|
|
44
|
+
* @returns Formatted CPF/CNPJ string
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```tsx
|
|
48
|
+
* formatCpfCnpj('12345678901') // '123.456.789-01'
|
|
49
|
+
* formatCpfCnpj('12345678000195') // '12.345.678/0001-95'
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export function formatCpfCnpj(cpfCnpj) {
|
|
53
|
+
if (!cpfCnpj)
|
|
54
|
+
return '';
|
|
55
|
+
const numberCpfCnpj = cpfCnpj.replace(/\D/g, '');
|
|
56
|
+
return format(numberCpfCnpj, maskCpfCnpj(numberCpfCnpj));
|
|
57
|
+
}
|
|
58
|
+
// DATE
|
|
59
|
+
function getDay(date) {
|
|
60
|
+
return date.getDate().toString().padStart(2, '0');
|
|
61
|
+
}
|
|
62
|
+
function getMonth(date) {
|
|
63
|
+
return (date.getMonth() + 1).toString().padStart(2, '0');
|
|
64
|
+
}
|
|
65
|
+
function getYear(date) {
|
|
66
|
+
return date.getFullYear().toString();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Formats a date to Brazilian format (DD/MM/YYYY).
|
|
70
|
+
*
|
|
71
|
+
* @param date - Date string, Date object, or undefined
|
|
72
|
+
* @param separator - Date separator (default: '/')
|
|
73
|
+
* @returns Formatted date string in Brazilian format
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```tsx
|
|
77
|
+
* formatDate('2023-12-25') // '25/12/2023'
|
|
78
|
+
* formatDate(new Date()) // '13/10/2025'
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export const formatDate = (date, _separator = '/') => {
|
|
82
|
+
if (!date)
|
|
83
|
+
return '';
|
|
84
|
+
const d = new Date(date);
|
|
85
|
+
return d.toLocaleDateString('pt-BR');
|
|
86
|
+
};
|
|
87
|
+
export const formatDateTime = (date, returnSeconds = false) => {
|
|
88
|
+
if (!date)
|
|
89
|
+
return '';
|
|
90
|
+
const hours = date.getHours().toString().padStart(2, '0');
|
|
91
|
+
const minutes = date.getMinutes().toString().padStart(2, '0');
|
|
92
|
+
const seconds = returnSeconds ? `:${date.getSeconds().toString().padStart(2, '0')}` : '';
|
|
93
|
+
return `${formatDate(date)} ${hours}:${minutes}${seconds}`;
|
|
94
|
+
};
|
|
95
|
+
export function formatDateCalendar(date) {
|
|
96
|
+
if (!date)
|
|
97
|
+
return '';
|
|
98
|
+
const day = getDay(date);
|
|
99
|
+
const month = getMonth(date);
|
|
100
|
+
const year = getYear(date);
|
|
101
|
+
return `${year}-${month}-${day}`;
|
|
102
|
+
}
|
|
103
|
+
export function stringDateToDate(date, separator = '/') {
|
|
104
|
+
if (!date)
|
|
105
|
+
return undefined;
|
|
106
|
+
const [day, month, year] = date.split(separator).map(Number);
|
|
107
|
+
// new Date(ano, mês-1, dia) interpreta a data no fuso horário local
|
|
108
|
+
return new Date(year, month - 1, day);
|
|
109
|
+
}
|
|
110
|
+
// NUMBER
|
|
111
|
+
export const roundNumber = (value, fractionDigits = 2) => {
|
|
112
|
+
return Number(value.toFixed(fractionDigits));
|
|
113
|
+
};
|
|
114
|
+
export const stringToNumber = (value) => {
|
|
115
|
+
if (!value)
|
|
116
|
+
return 0;
|
|
117
|
+
const numericValue = value
|
|
118
|
+
.replace(/[^\d,-]/g, '')
|
|
119
|
+
.replace(/\./g, '')
|
|
120
|
+
.replace(',', '.');
|
|
121
|
+
return Number.parseFloat(numericValue);
|
|
122
|
+
};
|
|
123
|
+
var InternetAmountUnity;
|
|
124
|
+
(function (InternetAmountUnity) {
|
|
125
|
+
InternetAmountUnity[InternetAmountUnity["iauMegabyte"] = 0] = "iauMegabyte";
|
|
126
|
+
InternetAmountUnity[InternetAmountUnity["iauGigabyte"] = 1] = "iauGigabyte";
|
|
127
|
+
InternetAmountUnity[InternetAmountUnity["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
|
|
128
|
+
})(InternetAmountUnity || (InternetAmountUnity = {}));
|
|
129
|
+
export const convertInternetToDisplay = (internet, unit) => {
|
|
130
|
+
if (internet === 0) {
|
|
131
|
+
return '';
|
|
132
|
+
}
|
|
133
|
+
const internetInMB = unit === InternetAmountUnity.iauGigabyte ? convertGbToMb(internet) : internet;
|
|
134
|
+
if (internetInMB > 1023) {
|
|
135
|
+
return `${convertMbToGb(roundNumber(internetInMB))} GB`;
|
|
136
|
+
}
|
|
137
|
+
return `${roundNumber(internetInMB)} MB`;
|
|
138
|
+
};
|
|
139
|
+
export const convertMbToGb = (value) => {
|
|
140
|
+
return value > 0 ? roundNumber(value / 1024) : 0;
|
|
141
|
+
};
|
|
142
|
+
export const convertGbToMb = (value) => {
|
|
143
|
+
return value > 0 ? roundNumber(value * 1024) : 0;
|
|
144
|
+
};
|
|
145
|
+
export const convertSecondsToMinutes = (value) => {
|
|
146
|
+
return value > 0 ? roundNumber(value / 60) : 0;
|
|
147
|
+
};
|
|
148
|
+
export const convertBytesToMB = (bytes) => {
|
|
149
|
+
if (!bytes || Number.isNaN(bytes))
|
|
150
|
+
return 0;
|
|
151
|
+
return roundNumber(bytes / (1024 * 1024));
|
|
152
|
+
};
|
|
153
|
+
export const convertMonthToDays = (months) => {
|
|
154
|
+
return months > 0 ? months * 30 : 0;
|
|
155
|
+
};
|
|
156
|
+
export const convertDaysToMonth = (days) => {
|
|
157
|
+
return days > 0 ? roundNumber(days / 30) : 0;
|
|
158
|
+
};
|
|
159
|
+
// NUMBER
|
|
160
|
+
export const formatNumber = (value) => {
|
|
161
|
+
return value.toLocaleString('pt-BR', {
|
|
162
|
+
style: 'decimal',
|
|
163
|
+
minimumFractionDigits: 0,
|
|
164
|
+
maximumFractionDigits: 0,
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
// DECIMAL
|
|
168
|
+
/**
|
|
169
|
+
* Formats a number with Brazilian decimal format.
|
|
170
|
+
*
|
|
171
|
+
* @param value - Numeric value to format
|
|
172
|
+
* @param decimalPlaces - Number of decimal places (default: 2)
|
|
173
|
+
* @returns Formatted decimal string
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```tsx
|
|
177
|
+
* formatDecimal(1234.56) // '1.234,56'
|
|
178
|
+
* formatDecimal(1000.1, 1) // '1.000,1'
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
export const formatDecimal = (value, decimalPlaces = 2) => {
|
|
182
|
+
return value.toLocaleString('pt-BR', {
|
|
183
|
+
style: 'decimal',
|
|
184
|
+
minimumFractionDigits: decimalPlaces,
|
|
185
|
+
maximumFractionDigits: decimalPlaces,
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
// PERCENT
|
|
189
|
+
/**
|
|
190
|
+
* Formats a number as percentage with Brazilian decimal format.
|
|
191
|
+
*
|
|
192
|
+
* @param value - Numeric value to format
|
|
193
|
+
* @param decimalPlaces - Number of decimal places (default: 2)
|
|
194
|
+
* @returns Formatted percentage string
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```tsx
|
|
198
|
+
* formatPercent(15.5) // '% 15,50'
|
|
199
|
+
* formatPercent(100, 0) // '% 100'
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
export const formatPercent = (value, decimalPlaces = 2) => {
|
|
203
|
+
return `% ${formatDecimal(value, decimalPlaces)}`;
|
|
204
|
+
};
|
|
205
|
+
// CURRENCY
|
|
206
|
+
/**
|
|
207
|
+
* Formats a number as Brazilian currency (BRL).
|
|
208
|
+
*
|
|
209
|
+
* @param value - Numeric value to format
|
|
210
|
+
* @param decimalPlaces - Number of decimal places (default: 2)
|
|
211
|
+
* @returns Formatted currency string
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```tsx
|
|
215
|
+
* formatCurrency(1234.56) // 'R$ 1.234,56'
|
|
216
|
+
* formatCurrency(1000, 0) // 'R$ 1.000'
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
export const formatCurrency = (value, decimalPlaces = 2) => {
|
|
220
|
+
return value.toLocaleString('pt-BR', {
|
|
221
|
+
style: 'currency',
|
|
222
|
+
currency: 'BRL',
|
|
223
|
+
minimumFractionDigits: decimalPlaces,
|
|
224
|
+
maximumFractionDigits: decimalPlaces,
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
export const isInvalidCurrencyValue = (rawValue) => {
|
|
228
|
+
if (!rawValue || rawValue.trim() === '')
|
|
229
|
+
return true;
|
|
230
|
+
const numericValue = stringToNumber(rawValue);
|
|
231
|
+
return Number.isNaN(numericValue) || numericValue <= 0;
|
|
232
|
+
};
|
|
233
|
+
// OTHERS
|
|
234
|
+
/**
|
|
235
|
+
* Formats an MSISDN (mobile phone number) to display format.
|
|
236
|
+
*
|
|
237
|
+
* @param value - Raw MSISDN string
|
|
238
|
+
* @returns Formatted MSISDN string
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```tsx
|
|
242
|
+
* formatMsisdn('5511987654321') // '(11) 98765-4321'
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
export function formatMsisdn(value = '') {
|
|
246
|
+
const msisdn = value.replace(/\D/g, '');
|
|
247
|
+
return `(${msisdn.slice(2, 4)}) ${msisdn.slice(4, 9)}-${msisdn.slice(9)}`;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Formats a CEP (Brazilian postal code) with proper mask.
|
|
251
|
+
*
|
|
252
|
+
* @param cep - Raw CEP string
|
|
253
|
+
* @returns Formatted CEP string (XXXXX-XXX)
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```tsx
|
|
257
|
+
* formatCEP('01234567') // '01234-567'
|
|
258
|
+
* formatCEP('12345') // '12345'
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
export function formatCEP(cep) {
|
|
262
|
+
if (!cep)
|
|
263
|
+
return '';
|
|
264
|
+
return cep
|
|
265
|
+
.replace(/\D/g, '')
|
|
266
|
+
.replace(/(\d{5})(\d)/, '$1-$2')
|
|
267
|
+
.replace(/(-\d{3})\d+?$/, '$1');
|
|
268
|
+
}
|