@zydon/common 2.2.43 → 2.2.44
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/ActionButton/index.js +32 -4
- package/dist/components/ActionButton/index.js.map +1 -0
- package/dist/components/Autocomplete/index.js +137 -7
- package/dist/components/Autocomplete/index.js.map +1 -0
- package/dist/components/AutocompleteDetailed/index.js +134 -8
- package/dist/components/AutocompleteDetailed/index.js.map +1 -0
- package/dist/components/BuilderLayout/index.js +23 -4
- package/dist/components/BuilderLayout/index.js.map +1 -0
- package/dist/components/BuilderSidebar/index.js +17 -4
- package/dist/components/BuilderSidebar/index.js.map +1 -0
- package/dist/components/ColorPickerInput/index.js +98 -8
- package/dist/components/ColorPickerInput/index.js.map +1 -0
- package/dist/components/ColoredLabel/index.js +40 -3
- package/dist/components/ColoredLabel/index.js.map +1 -0
- package/dist/components/Common/index.js +27 -4
- package/dist/components/Common/index.js.map +1 -0
- package/dist/components/Confirm/index.js +49 -8
- package/dist/components/Confirm/index.js.map +1 -0
- package/dist/components/CustomAvatar/index.js +58 -4
- package/dist/components/CustomAvatar/index.js.map +1 -0
- package/dist/components/CustomAvatarGroup/index.js +73 -3
- package/dist/components/CustomAvatarGroup/index.js.map +1 -0
- package/dist/components/DashedDivider/index.js +7 -2
- package/dist/components/DashedDivider/index.js.map +1 -0
- package/dist/components/DataCards/index.js +54 -8
- package/dist/components/DataCards/index.js.map +1 -0
- package/dist/components/DataGrid/index.js +74 -6
- package/dist/components/DataGrid/index.js.map +1 -0
- package/dist/components/DatePicker/index.js +40 -4
- package/dist/components/DatePicker/index.js.map +1 -0
- package/dist/components/DateRangePicker/index.js +48 -4
- package/dist/components/DateRangePicker/index.js.map +1 -0
- package/dist/components/DateTimePicker/index.js +38 -4
- package/dist/components/DateTimePicker/index.js.map +1 -0
- package/dist/components/Delayed/index.js +15 -2
- package/dist/components/Delayed/index.js.map +1 -0
- package/dist/components/Drawer/index.js +36 -7
- package/dist/components/Drawer/index.js.map +1 -0
- package/dist/components/EmptyContent/index.js +77 -6
- package/dist/components/EmptyContent/index.js.map +1 -0
- package/dist/components/EmptyView/index.js +32 -5
- package/dist/components/EmptyView/index.js.map +1 -0
- package/dist/components/Error/index.js +44 -7
- package/dist/components/Error/index.js.map +1 -0
- package/dist/components/ExpandableGroup/index.js +30 -7
- package/dist/components/ExpandableGroup/index.js.map +1 -0
- package/dist/components/FixedProgressBar/index.js +20 -3
- package/dist/components/FixedProgressBar/index.js.map +1 -0
- package/dist/components/FrameSkeleton/index.js +95 -9
- package/dist/components/FrameSkeleton/index.js.map +1 -0
- package/dist/components/HelpButton/index.js +20 -4
- package/dist/components/HelpButton/index.js.map +1 -0
- package/dist/components/Icon/index.js +399 -53
- package/dist/components/Icon/index.js.map +1 -0
- package/dist/components/ImageCrop/index.js +48 -3
- package/dist/components/ImageCrop/index.js.map +1 -0
- package/dist/components/ImageCropModal/index.js +127 -10
- package/dist/components/ImageCropModal/index.js.map +1 -0
- package/dist/components/Incrementer/index.js +153 -6
- package/dist/components/Incrementer/index.js.map +1 -0
- package/dist/components/Label/index.js +68 -3
- package/dist/components/Label/index.js.map +1 -0
- package/dist/components/LoadingScreen/index.js +8 -3
- package/dist/components/LoadingScreen/index.js.map +1 -0
- package/dist/components/MaskedInput/index.js +51 -3
- package/dist/components/MaskedInput/index.js.map +1 -0
- package/dist/components/MenuItem/index.js +21 -6
- package/dist/components/MenuItem/index.js.map +1 -0
- package/dist/components/MenuPopover/index.js +45 -4
- package/dist/components/MenuPopover/index.js.map +1 -0
- package/dist/components/Modal/index.js +30 -7
- package/dist/components/Modal/index.js.map +1 -0
- package/dist/components/ModalActions/index.js +9 -3
- package/dist/components/ModalActions/index.js.map +1 -0
- package/dist/components/MoreMenu/index.js +16 -7
- package/dist/components/MoreMenu/index.js.map +1 -0
- package/dist/components/NumberInput/index.js +103 -3
- package/dist/components/NumberInput/index.js.map +1 -0
- package/dist/components/PasswordRules/index.js +74 -4
- package/dist/components/PasswordRules/index.js.map +1 -0
- package/dist/components/PopoverSelect/index.js +43 -5
- package/dist/components/PopoverSelect/index.js.map +1 -0
- package/dist/components/Portal/index.js +25 -2
- package/dist/components/Portal/index.js.map +1 -0
- package/dist/components/Result/index.js +26 -2
- package/dist/components/Result/index.js.map +1 -0
- package/dist/components/SavedChanges/index.js +39 -3
- package/dist/components/SavedChanges/index.js.map +1 -0
- package/dist/components/Scrollbar/index.js +41 -4
- package/dist/components/Scrollbar/index.js.map +1 -0
- package/dist/components/SearchInput/index.js +70 -6
- package/dist/components/SearchInput/index.js.map +1 -0
- package/dist/components/SelectableCards/index.js +140 -12
- package/dist/components/SelectableCards/index.js.map +1 -0
- package/dist/components/SeoPreview/index.js +157 -7
- package/dist/components/SeoPreview/index.js.map +1 -0
- package/dist/components/SplashScreen/index.js +103 -3
- package/dist/components/SplashScreen/index.js.map +1 -0
- package/dist/components/Steps/index.js +68 -8
- package/dist/components/Steps/index.js.map +1 -0
- package/dist/components/StyledTab/index.js +87 -5
- package/dist/components/StyledTab/index.js.map +1 -0
- package/dist/components/StyledTabs/index.js +24 -3
- package/dist/components/StyledTabs/index.js.map +1 -0
- package/dist/components/Summary/index.js +12 -2
- package/dist/components/Summary/index.js.map +1 -0
- package/dist/components/SwapList/index.js +244 -12
- package/dist/components/SwapList/index.js.map +1 -0
- package/dist/components/TabPanel/index.js +32 -3
- package/dist/components/TabPanel/index.js.map +1 -0
- package/dist/components/TextMaxLine/index.js +46 -5
- package/dist/components/TextMaxLine/index.js.map +1 -0
- package/dist/components/TimePicker/index.js +40 -4
- package/dist/components/TimePicker/index.js.map +1 -0
- package/dist/components/ToggleButtonGroup/index.js +7 -2
- package/dist/components/ToggleButtonGroup/index.js.map +1 -0
- package/dist/components/Tooltip/index.js +6 -3
- package/dist/components/Tooltip/index.js.map +1 -0
- package/dist/components/WhiteBox/index.js +5 -2
- package/dist/components/WhiteBox/index.js.map +1 -0
- package/dist/components/animate/index.js +2 -0
- package/dist/components/animate/index.js.map +1 -0
- package/dist/components/carousel/index.js +2 -0
- package/dist/components/carousel/index.js.map +1 -0
- package/dist/components/form/Address/index.js +197 -8
- package/dist/components/form/Address/index.js.map +1 -0
- package/dist/components/form/Autocomplete/index.js +39 -3
- package/dist/components/form/Autocomplete/index.js.map +1 -0
- package/dist/components/form/AutocompleteDetailed/index.js +39 -3
- package/dist/components/form/AutocompleteDetailed/index.js.map +1 -0
- package/dist/components/form/Checkbox/index.js +48 -5
- package/dist/components/form/Checkbox/index.js.map +1 -0
- package/dist/components/form/Codes/index.js +83 -6
- package/dist/components/form/Codes/index.js.map +1 -0
- package/dist/components/form/ColorPicker/index.js +49 -3
- package/dist/components/form/ColorPicker/index.js.map +1 -0
- package/dist/components/form/DatePicker/index.js +60 -4
- package/dist/components/form/DatePicker/index.js.map +1 -0
- package/dist/components/form/DateRangePicker/index.js +74 -6
- package/dist/components/form/DateRangePicker/index.js.map +1 -0
- package/dist/components/form/DateTimePicker/index.js +58 -4
- package/dist/components/form/DateTimePicker/index.js.map +1 -0
- package/dist/components/form/Field/index.js +46 -3
- package/dist/components/form/Field/index.js.map +1 -0
- package/dist/components/form/Form/index.js +26 -3
- package/dist/components/form/Form/index.js.map +1 -0
- package/dist/components/form/Incrementer/index.js +35 -3
- package/dist/components/form/Incrementer/index.js.map +1 -0
- package/dist/components/form/InputTags/index.js +66 -5
- package/dist/components/form/InputTags/index.js.map +1 -0
- package/dist/components/form/MaskedInput/index.js +42 -3
- package/dist/components/form/MaskedInput/index.js.map +1 -0
- package/dist/components/form/MultiCheckbox/index.js +90 -8
- package/dist/components/form/MultiCheckbox/index.js.map +1 -0
- package/dist/components/form/MultiChipField/index.js +46 -4
- package/dist/components/form/MultiChipField/index.js.map +1 -0
- package/dist/components/form/NumberInput/index.js +40 -3
- package/dist/components/form/NumberInput/index.js.map +1 -0
- package/dist/components/form/Password/index.js +86 -6
- package/dist/components/form/Password/index.js.map +1 -0
- package/dist/components/form/RadioGroup/index.js +123 -8
- package/dist/components/form/RadioGroup/index.js.map +1 -0
- package/dist/components/form/SelectableCards/index.js +19 -3
- package/dist/components/form/SelectableCards/index.js.map +1 -0
- package/dist/components/form/Switch/index.js +65 -5
- package/dist/components/form/Switch/index.js.map +1 -0
- package/dist/components/form/TimePicker/index.js +61 -4
- package/dist/components/form/TimePicker/index.js.map +1 -0
- package/dist/components/form/UploadAvatarWithCrop/index.js +56 -5
- package/dist/components/form/UploadAvatarWithCrop/index.js.map +1 -0
- package/dist/components/form/UploadWithCrop/index.js +56 -5
- package/dist/components/form/UploadWithCrop/index.js.map +1 -0
- package/dist/components/form/Webhook/index.js +141 -12
- package/dist/components/form/Webhook/index.js.map +1 -0
- package/dist/components/lightbox/index.js +2 -0
- package/dist/components/lightbox/index.js.map +1 -0
- package/dist/components/table/index.js +2 -0
- package/dist/components/table/index.js.map +1 -0
- package/dist/components/upload/index.js +2 -0
- package/dist/components/upload/index.js.map +1 -0
- package/dist/hooks/useActiveElement.js +25 -2
- package/dist/hooks/useActiveElement.js.map +1 -0
- package/dist/hooks/useApiMessage.js +31 -2
- package/dist/hooks/useApiMessage.js.map +1 -0
- package/dist/hooks/useAutocomplete.js +58 -2
- package/dist/hooks/useAutocomplete.js.map +1 -0
- package/dist/hooks/useCopyToClipboard.js +20 -2
- package/dist/hooks/useCopyToClipboard.js.map +1 -0
- package/dist/hooks/useDatagrid.js +41 -2
- package/dist/hooks/useDatagrid.js.map +1 -0
- package/dist/hooks/useDebounceValue.js +16 -2
- package/dist/hooks/useDebounceValue.js.map +1 -0
- package/dist/hooks/useDeepCompareEffect.js +13 -2
- package/dist/hooks/useDeepCompareEffect.js.map +1 -0
- package/dist/hooks/useEventCallback.js +14 -3
- package/dist/hooks/useEventCallback.js.map +1 -0
- package/dist/hooks/useEventListener.js +22 -2
- package/dist/hooks/useEventListener.js.map +1 -0
- package/dist/hooks/useIsMounting.js +11 -2
- package/dist/hooks/useIsMounting.js.map +1 -0
- package/dist/hooks/useIsomorphicLayoutEffect.js +4 -2
- package/dist/hooks/useIsomorphicLayoutEffect.js.map +1 -0
- package/dist/hooks/useLocalStorage.js +85 -3
- package/dist/hooks/useLocalStorage.js.map +1 -0
- package/dist/hooks/useMount.js +7 -2
- package/dist/hooks/useMount.js.map +1 -0
- package/dist/hooks/useOnClickOutside.js +14 -3
- package/dist/hooks/useOnClickOutside.js.map +1 -0
- package/dist/hooks/usePagination.js +38 -2
- package/dist/hooks/usePagination.js.map +1 -0
- package/dist/hooks/usePopover.js +19 -2
- package/dist/hooks/usePopover.js.map +1 -0
- package/dist/hooks/useResponsive.js +32 -3
- package/dist/hooks/useResponsive.js.map +1 -0
- package/dist/hooks/useScrollOffSetTop.js +29 -2
- package/dist/hooks/useScrollOffSetTop.js.map +1 -0
- package/dist/hooks/useSnackbar.js +11 -2
- package/dist/hooks/useSnackbar.js.map +1 -0
- package/dist/hooks/useTabs.js +14 -2
- package/dist/hooks/useTabs.js.map +1 -0
- package/dist/hooks/useToggle.js +9 -2
- package/dist/hooks/useToggle.js.map +1 -0
- package/dist/hooks/useUpload.js +54 -2
- package/dist/hooks/useUpload.js.map +1 -0
- package/dist/hooks/useUploadImage.js +77 -4
- package/dist/hooks/useUploadImage.js.map +1 -0
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -0
- package/dist/locales/all-langs.js +29 -2
- package/dist/locales/all-langs.js.map +1 -0
- package/dist/theme/core/index.js +2 -0
- package/dist/theme/core/index.js.map +1 -0
- package/dist/theme/styles/index.js +2 -0
- package/dist/theme/styles/index.js.map +1 -0
- package/dist/theme/theme-provider.js +39 -3
- package/dist/theme/theme-provider.js.map +1 -0
- package/dist/theme/with-settings/index.js +2 -0
- package/dist/theme/with-settings/index.js.map +1 -0
- package/dist/types/addressProps.js +2 -0
- package/dist/types/addressProps.js.map +1 -0
- package/dist/types/api.js +2 -0
- package/dist/types/api.js.map +1 -0
- package/dist/types/autoComplete.js +2 -0
- package/dist/types/autoComplete.js.map +1 -0
- package/dist/types/autoCompleteProps.js +2 -0
- package/dist/types/autoCompleteProps.js.map +1 -0
- package/dist/types/baseField.js +2 -0
- package/dist/types/baseField.js.map +1 -0
- package/dist/types/dataGridProps.js +2 -0
- package/dist/types/dataGridProps.js.map +1 -0
- package/dist/types/datagrid.js +2 -0
- package/dist/types/datagrid.js.map +1 -0
- package/dist/types/datePickerProps.js +2 -0
- package/dist/types/datePickerProps.js.map +1 -0
- package/dist/types/dateRangePickerProps.js +2 -0
- package/dist/types/dateRangePickerProps.js.map +1 -0
- package/dist/types/dateTimePickerProps.js +2 -0
- package/dist/types/dateTimePickerProps.js.map +1 -0
- package/dist/types/fieldProps.js +2 -0
- package/dist/types/fieldProps.js.map +1 -0
- package/dist/types/icon.js +330 -2
- package/dist/types/icon.js.map +1 -0
- package/dist/types/iconProps.js +2 -0
- package/dist/types/iconProps.js.map +1 -0
- package/dist/types/incrementerProps.js +2 -0
- package/dist/types/incrementerProps.js.map +1 -0
- package/dist/types/item.js +2 -0
- package/dist/types/item.js.map +1 -0
- package/dist/types/multiCheckboxProps.js +2 -0
- package/dist/types/multiCheckboxProps.js.map +1 -0
- package/dist/types/numberInputProps.js +2 -0
- package/dist/types/numberInputProps.js.map +1 -0
- package/dist/types/option.js +2 -0
- package/dist/types/option.js.map +1 -0
- package/dist/types/radioGroupProps.js +2 -0
- package/dist/types/radioGroupProps.js.map +1 -0
- package/dist/types/searchInputProps.js +2 -0
- package/dist/types/searchInputProps.js.map +1 -0
- package/dist/types/sectionProps.js +2 -0
- package/dist/types/sectionProps.js.map +1 -0
- package/dist/types/switchProps.js +2 -0
- package/dist/types/switchProps.js.map +1 -0
- package/dist/types/timePickerProps.js +2 -0
- package/dist/types/timePickerProps.js.map +1 -0
- package/dist/types/upload.js +2 -0
- package/dist/types/upload.js.map +1 -0
- package/dist/types/webhook.js +35 -2
- package/dist/types/webhook.js.map +1 -0
- package/dist/utils/color.js +5 -3
- package/dist/utils/color.js.map +1 -0
- package/dist/utils/compare.js +5 -3
- package/dist/utils/compare.js.map +1 -0
- package/dist/utils/date.js +20 -4
- package/dist/utils/date.js.map +1 -0
- package/dist/utils/formatNumber.js +86 -2
- package/dist/utils/formatNumber.js.map +1 -0
- package/dist/utils/formatTime.js +155 -5
- package/dist/utils/formatTime.js.map +1 -0
- package/dist/utils/loadable.js +11 -3
- package/dist/utils/loadable.js.map +1 -0
- package/dist/utils/mask.js +38 -2
- package/dist/utils/mask.js.map +1 -0
- package/dist/utils/number.js +12 -2
- package/dist/utils/number.js.map +1 -0
- package/dist/utils/sort.js +22 -2
- package/dist/utils/sort.js.map +1 -0
- package/dist/utils/uuidv4.js +9 -2
- package/dist/utils/uuidv4.js.map +1 -0
- package/dist/utils/validators.js +82 -2
- package/dist/utils/validators.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,3 +1,87 @@
|
|
|
1
|
-
const
|
|
1
|
+
const DEFAULT_LOCALE = { code: "pt-BR", currency: "BRL" };
|
|
2
|
+
function processInput(inputValue) {
|
|
3
|
+
if (inputValue == null || Number.isNaN(inputValue))
|
|
4
|
+
return null;
|
|
5
|
+
return Number(inputValue);
|
|
6
|
+
}
|
|
7
|
+
function fNumber(inputValue, options) {
|
|
8
|
+
const locale = DEFAULT_LOCALE;
|
|
9
|
+
const number = processInput(inputValue);
|
|
10
|
+
if (number === null)
|
|
11
|
+
return "";
|
|
12
|
+
const fm = new Intl.NumberFormat(locale.code, {
|
|
13
|
+
minimumFractionDigits: 0,
|
|
14
|
+
maximumFractionDigits: 2,
|
|
15
|
+
...options
|
|
16
|
+
}).format(number);
|
|
17
|
+
return fm;
|
|
18
|
+
}
|
|
19
|
+
function fCurrency(inputValue, options) {
|
|
20
|
+
const locale = DEFAULT_LOCALE;
|
|
21
|
+
const number = processInput(inputValue);
|
|
22
|
+
if (number === null)
|
|
23
|
+
return "";
|
|
24
|
+
const fm = new Intl.NumberFormat(locale.code, {
|
|
25
|
+
style: "currency",
|
|
26
|
+
currency: locale.currency,
|
|
27
|
+
minimumFractionDigits: 0,
|
|
28
|
+
maximumFractionDigits: 2,
|
|
29
|
+
...options
|
|
30
|
+
}).format(number);
|
|
31
|
+
return fm;
|
|
32
|
+
}
|
|
33
|
+
function fPercent(inputValue, options) {
|
|
34
|
+
const locale = DEFAULT_LOCALE;
|
|
35
|
+
const number = processInput(inputValue);
|
|
36
|
+
if (number === null)
|
|
37
|
+
return "";
|
|
38
|
+
const fm = new Intl.NumberFormat(locale.code, {
|
|
39
|
+
style: "percent",
|
|
40
|
+
minimumFractionDigits: 0,
|
|
41
|
+
maximumFractionDigits: 1,
|
|
42
|
+
...options
|
|
43
|
+
}).format(number / 100);
|
|
44
|
+
return fm;
|
|
45
|
+
}
|
|
46
|
+
function fShortenNumber(inputValue, options) {
|
|
47
|
+
const locale = DEFAULT_LOCALE;
|
|
48
|
+
const number = processInput(inputValue);
|
|
49
|
+
if (number === null)
|
|
50
|
+
return "";
|
|
51
|
+
const fm = new Intl.NumberFormat(locale.code, {
|
|
52
|
+
notation: "compact",
|
|
53
|
+
maximumFractionDigits: 2,
|
|
54
|
+
...options
|
|
55
|
+
}).format(number);
|
|
56
|
+
return fm.replace(/[A-Z]/g, (match) => match.toLowerCase());
|
|
57
|
+
}
|
|
58
|
+
function fData(inputValue) {
|
|
59
|
+
const number = processInput(inputValue);
|
|
60
|
+
if (number === null || number === 0)
|
|
61
|
+
return "0 bytes";
|
|
62
|
+
const units = ["bytes", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"];
|
|
63
|
+
const decimal = 2;
|
|
64
|
+
const baseValue = 1024;
|
|
65
|
+
const index = Math.floor(Math.log(number) / Math.log(baseValue));
|
|
66
|
+
const fm = `${parseFloat((number / baseValue ** index).toFixed(decimal))} ${units[index]}`;
|
|
67
|
+
return fm;
|
|
68
|
+
}
|
|
69
|
+
const fWithDecimalPlacesOrNot = (value, decimalPlaces = 12) => {
|
|
70
|
+
return +Number(value).toFixed(decimalPlaces);
|
|
71
|
+
};
|
|
72
|
+
function fTwoDigits(value) {
|
|
73
|
+
if (value === 0 || value === "0")
|
|
74
|
+
return "0";
|
|
75
|
+
if (typeof value === "string") {
|
|
76
|
+
return value.padStart(2, "0");
|
|
77
|
+
} else {
|
|
78
|
+
return value.toString().padStart(2, "0");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const fCurrencyBRL = (value) => new Intl.NumberFormat("pt-BR", { style: "currency", currency: "BRL" }).format(
|
|
82
|
+
value || 0
|
|
83
|
+
);
|
|
2
84
|
|
|
3
|
-
export {
|
|
85
|
+
export { fCurrency, fCurrencyBRL, fData, fNumber, fPercent, fShortenNumber, fTwoDigits, fWithDecimalPlacesOrNot };
|
|
86
|
+
//# sourceMappingURL=out.js.map
|
|
87
|
+
//# sourceMappingURL=formatNumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/formatNumber.ts"],"names":[],"mappings":"AAIA,MAAM,iBAAiB,EAAE,MAAM,SAAS,UAAU,MAAM;AAExD,SAAS,aAAa,YAA6C;AACjE,MAAI,cAAc,QAAQ,OAAO,MAAM,UAAU;AAAG,WAAO;AAC3D,SAAO,OAAO,UAAU;AAC1B;AAEO,SAAS,QAAQ,YAA8B,SAAmB;AACvE,QAAM,SAAS;AAEf,QAAM,SAAS,aAAa,UAAU;AACtC,MAAI,WAAW;AAAM,WAAO;AAE5B,QAAM,KAAK,IAAI,KAAK,aAAa,OAAO,MAAM;AAAA,IAC5C,uBAAuB;AAAA,IACvB,uBAAuB;AAAA,IACvB,GAAG;AAAA,EACL,CAAC,EAAE,OAAO,MAAM;AAEhB,SAAO;AACT;AAEO,SAAS,UAAU,YAA8B,SAAmB;AACzE,QAAM,SAAS;AAEf,QAAM,SAAS,aAAa,UAAU;AACtC,MAAI,WAAW;AAAM,WAAO;AAE5B,QAAM,KAAK,IAAI,KAAK,aAAa,OAAO,MAAM;AAAA,IAC5C,OAAO;AAAA,IACP,UAAU,OAAO;AAAA,IACjB,uBAAuB;AAAA,IACvB,uBAAuB;AAA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,WAAO;AAEzC,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,MAAM,SAAS,GAAG,GAAG;AAAA,EAC9B,OAAO;AACL,WAAO,MAAM,SAAS,EAAE,SAAS,GAAG,GAAG;AAAA,EACzC;AACF;AAEO,MAAM,eAAe,CAAC,UAC3B,IAAI,KAAK,aAAa,SAAS,EAAE,OAAO,YAAY,UAAU,MAAM,CAAC,EAAE;AAAA,EACrE,SAAS;AACX","sourcesContent":["export type InputNumberValue = string | number | null | undefined;\n\ntype Options = Intl.NumberFormatOptions | undefined;\n\nconst DEFAULT_LOCALE = { code: 'pt-BR', currency: 'BRL' };\n\nfunction processInput(inputValue: InputNumberValue): number | null {\n if (inputValue == null || Number.isNaN(inputValue)) return null;\n return Number(inputValue);\n}\n\nexport function fNumber(inputValue: InputNumberValue, options?: Options) {\n const locale = DEFAULT_LOCALE;\n\n const number = processInput(inputValue);\n if (number === null) return '';\n\n const fm = new Intl.NumberFormat(locale.code, {\n minimumFractionDigits: 0,\n maximumFractionDigits: 2,\n ...options,\n }).format(number);\n\n return fm;\n}\n\nexport function fCurrency(inputValue: InputNumberValue, options?: Options) {\n const locale = DEFAULT_LOCALE;\n\n const number = processInput(inputValue);\n if (number === null) return '';\n\n const fm = new Intl.NumberFormat(locale.code, {\n style: 'currency',\n currency: locale.currency,\n minimumFractionDigits: 0,\n maximumFractionDigits: 2,\n ...options,\n }).format(number);\n\n return fm;\n}\n\nexport function fPercent(inputValue: InputNumberValue, options?: Options) {\n const locale = DEFAULT_LOCALE;\n\n const number = processInput(inputValue);\n if (number === null) return '';\n\n const fm = new Intl.NumberFormat(locale.code, {\n style: 'percent',\n minimumFractionDigits: 0,\n maximumFractionDigits: 1,\n ...options,\n }).format(number / 100);\n\n return fm;\n}\n\nexport function fShortenNumber(\n inputValue: InputNumberValue,\n options?: Options,\n) {\n const locale = DEFAULT_LOCALE;\n\n const number = processInput(inputValue);\n if (number === null) return '';\n\n const fm = new Intl.NumberFormat(locale.code, {\n notation: 'compact',\n maximumFractionDigits: 2,\n ...options,\n }).format(number);\n\n return fm.replace(/[A-Z]/g, match => match.toLowerCase());\n}\n\nexport function fData(inputValue: InputNumberValue) {\n const number = processInput(inputValue);\n if (number === null || number === 0) return '0 bytes';\n\n const units = ['bytes', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb'];\n const decimal = 2;\n const baseValue = 1024;\n\n const index = Math.floor(Math.log(number) / Math.log(baseValue));\n const fm = `${parseFloat((number / baseValue ** index).toFixed(decimal))} ${units[index]}`;\n\n return fm;\n}\n\nexport const fWithDecimalPlacesOrNot = (\n value: string | number,\n decimalPlaces: number = 12,\n) => {\n return +Number(value).toFixed(decimalPlaces);\n};\n\nexport function fTwoDigits(value: number | string) {\n if (value === 0 || value === '0') return '0';\n\n if (typeof value === 'string') {\n return value.padStart(2, '0');\n } else {\n return value.toString().padStart(2, '0');\n }\n}\n\nexport const fCurrencyBRL = (value?: number | null): string =>\n new Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(\n value || 0,\n );\n"]}
|
package/dist/utils/formatTime.js
CHANGED
|
@@ -1,7 +1,157 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import duration from 'dayjs/plugin/duration';
|
|
3
|
+
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
dayjs.extend(duration);
|
|
6
|
+
dayjs.extend(relativeTime);
|
|
7
|
+
const formatStr = {
|
|
8
|
+
dateTime: "DD/MM/YYYY HH:mm",
|
|
9
|
+
date: "DD/MM/YYYY",
|
|
10
|
+
time: "HH:mm",
|
|
11
|
+
split: {
|
|
12
|
+
dateTime: "DD/MM/YYYY HH:mm",
|
|
13
|
+
date: "DD/MM/YYYY"
|
|
14
|
+
},
|
|
15
|
+
paramCase: {
|
|
16
|
+
dateTime: "DD/MM/YYYY HH:mm",
|
|
17
|
+
date: "DD/MM/YYYY"
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
function today(format) {
|
|
21
|
+
return dayjs(/* @__PURE__ */ new Date()).startOf("day").format(format);
|
|
22
|
+
}
|
|
23
|
+
function fDateTime(date, format) {
|
|
24
|
+
if (!date) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const isValid = dayjs(date).isValid();
|
|
28
|
+
return isValid ? dayjs(date).format(format ?? formatStr.dateTime) : "Invalid time value";
|
|
29
|
+
}
|
|
30
|
+
function fDate(date, format) {
|
|
31
|
+
if (!date) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const isValid = dayjs(date).isValid();
|
|
35
|
+
return isValid ? dayjs(date).format(format ?? formatStr.date) : "Invalid time value";
|
|
36
|
+
}
|
|
37
|
+
function fTime(date, format) {
|
|
38
|
+
if (!date) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const isValid = dayjs(date).isValid();
|
|
42
|
+
return isValid ? dayjs(date).format(format ?? formatStr.time) : "Invalid time value";
|
|
43
|
+
}
|
|
44
|
+
function fTimestamp(date) {
|
|
45
|
+
if (!date) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const isValid = dayjs(date).isValid();
|
|
49
|
+
return isValid ? dayjs(date).valueOf() : "Invalid time value";
|
|
50
|
+
}
|
|
51
|
+
function fToNow(date) {
|
|
52
|
+
if (!date) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const isValid = dayjs(date).isValid();
|
|
56
|
+
return isValid ? dayjs(date).toNow(true) : "Invalid time value";
|
|
57
|
+
}
|
|
58
|
+
function fIsBetween(inputDate, startDate, endDate) {
|
|
59
|
+
if (!inputDate || !startDate || !endDate) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const formattedInputDate = fTimestamp(inputDate);
|
|
63
|
+
const formattedStartDate = fTimestamp(startDate);
|
|
64
|
+
const formattedEndDate = fTimestamp(endDate);
|
|
65
|
+
if (formattedInputDate && formattedStartDate && formattedEndDate) {
|
|
66
|
+
return formattedInputDate >= formattedStartDate && formattedInputDate <= formattedEndDate;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
function fIsAfter(startDate, endDate) {
|
|
71
|
+
return dayjs(startDate).isAfter(endDate);
|
|
72
|
+
}
|
|
73
|
+
function fIsSame(startDate, endDate, units) {
|
|
74
|
+
if (!startDate || !endDate) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
const isValid = dayjs(startDate).isValid() && dayjs(endDate).isValid();
|
|
78
|
+
if (!isValid) {
|
|
79
|
+
return "Invalid time value";
|
|
80
|
+
}
|
|
81
|
+
return dayjs(startDate).isSame(endDate, units ?? "year");
|
|
82
|
+
}
|
|
83
|
+
function fDateRangeShortLabel(startDate, endDate, initial) {
|
|
84
|
+
const isValid = dayjs(startDate).isValid() && dayjs(endDate).isValid();
|
|
85
|
+
const isAfter = fIsAfter(startDate, endDate);
|
|
86
|
+
if (!isValid || isAfter) {
|
|
87
|
+
return "Invalid time value";
|
|
88
|
+
}
|
|
89
|
+
let label = `${fDate(startDate)} - ${fDate(endDate)}`;
|
|
90
|
+
if (initial) {
|
|
91
|
+
return label;
|
|
92
|
+
}
|
|
93
|
+
const isSameYear = fIsSame(startDate, endDate, "year");
|
|
94
|
+
const isSameMonth = fIsSame(startDate, endDate, "month");
|
|
95
|
+
const isSameDay = fIsSame(startDate, endDate, "day");
|
|
96
|
+
if (isSameYear && !isSameMonth) {
|
|
97
|
+
label = `${fDate(startDate, "DD MMM")} - ${fDate(endDate)}`;
|
|
98
|
+
} else if (isSameYear && isSameMonth && !isSameDay) {
|
|
99
|
+
label = `${fDate(startDate, "DD")} - ${fDate(endDate)}`;
|
|
100
|
+
} else if (isSameYear && isSameMonth && isSameDay) {
|
|
101
|
+
label = `${fDate(endDate)}`;
|
|
102
|
+
}
|
|
103
|
+
return label;
|
|
104
|
+
}
|
|
105
|
+
function fAdd({
|
|
106
|
+
years = 0,
|
|
107
|
+
months = 0,
|
|
108
|
+
days = 0,
|
|
109
|
+
hours = 0,
|
|
110
|
+
minutes = 0,
|
|
111
|
+
seconds = 0,
|
|
112
|
+
milliseconds = 0
|
|
113
|
+
}) {
|
|
114
|
+
const result = dayjs().add(
|
|
115
|
+
dayjs.duration({
|
|
116
|
+
years,
|
|
117
|
+
months,
|
|
118
|
+
days,
|
|
119
|
+
hours,
|
|
120
|
+
minutes,
|
|
121
|
+
seconds,
|
|
122
|
+
milliseconds
|
|
123
|
+
})
|
|
124
|
+
).format();
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
function fSub({
|
|
128
|
+
years = 0,
|
|
129
|
+
months = 0,
|
|
130
|
+
days = 0,
|
|
131
|
+
hours = 0,
|
|
132
|
+
minutes = 0,
|
|
133
|
+
seconds = 0,
|
|
134
|
+
milliseconds = 0
|
|
135
|
+
}) {
|
|
136
|
+
const result = dayjs().subtract(
|
|
137
|
+
dayjs.duration({
|
|
138
|
+
years,
|
|
139
|
+
months,
|
|
140
|
+
days,
|
|
141
|
+
hours,
|
|
142
|
+
minutes,
|
|
143
|
+
seconds,
|
|
144
|
+
milliseconds
|
|
145
|
+
})
|
|
146
|
+
).format();
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
const getDifferenceInDays = (startDate, endDate) => {
|
|
150
|
+
if (!startDate || !endDate)
|
|
151
|
+
return null;
|
|
152
|
+
return dayjs(endDate).diff(dayjs(startDate), "day");
|
|
153
|
+
};
|
|
6
154
|
|
|
7
|
-
export {
|
|
155
|
+
export { fAdd, fDate, fDateRangeShortLabel, fDateTime, fIsAfter, fIsBetween, fIsSame, fSub, fTime, fTimestamp, fToNow, formatStr, getDifferenceInDays, today };
|
|
156
|
+
//# sourceMappingURL=out.js.map
|
|
157
|
+
//# sourceMappingURL=formatTime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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MAAI,cAAc,CAAC,aAAa;AAC9B,YAAQ,GAAG,MAAM,WAAW,QAAQ,OAAO,MAAM,OAAO;AAAA,EAC1D,WAAW,cAAc,eAAe,CAAC,WAAW;AAClD,YAAQ,GAAG,MAAM,WAAW,IAAI,OAAO,MAAM,OAAO;AAAA,EACtD,WAAW,cAAc,eAAe,WAAW;AACjD,YAAQ,GAAG,MAAM,OAAO;AAAA,EAC1B;AAEA,SAAO;AACT;AAYO,SAAS,KAAK;AAAA,EACnB,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,UAAU;AAAA,EACV,eAAe;AACjB,GAAkB;AAChB,QAAM,SAAS,MAAM,EAClB;AAAA,IACC,MAAM,SAAS;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,EACC,OAAO;AAEV,SAAO;AACT;AAEO,SAAS,KAAK;AAAA,EACnB,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,UAAU;AAAA,EACV,eAAe;AACjB,GAAkB;AAChB,QAAM,SAAS,MAAM,EAClB;AAAA,IACC,MAAM,SAAS;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,EACC,OAAO;AAEV,SAAO;AACT;AAEO,MAAM,sBAAsB,CAAC,WAAkB,YAAmB;AACvE,MAAI,CAAC,aAAa,CAAC;AAAS,WAAO;AAEnC,SAAO,MAAM,OAAO,EAAE,KAAK,MAAM,SAAS,GAAG,KAAK;AACpD","sourcesContent":["import type { Dayjs, OpUnitType } from 'dayjs';\nimport dayjs from 'dayjs';\nimport duration from 'dayjs/plugin/duration';\nimport relativeTime from 'dayjs/plugin/relativeTime';\n\n// ----------------------------------------------------------------------\n\ndayjs.extend(duration);\ndayjs.extend(relativeTime);\n\n// ----------------------------------------------------------------------\n\nexport type DatePickerFormat =\n | Dayjs\n | Date\n | string\n | number\n | null\n | undefined;\n\nexport const formatStr = {\n dateTime: 'DD/MM/YYYY HH:mm',\n date: 'DD/MM/YYYY',\n time: 'HH:mm',\n split: {\n dateTime: 'DD/MM/YYYY HH:mm',\n date: 'DD/MM/YYYY',\n },\n paramCase: {\n dateTime: 'DD/MM/YYYY HH:mm',\n date: 'DD/MM/YYYY',\n },\n};\n\nexport function today(format?: string) {\n return dayjs(new Date()).startOf('day').format(format);\n}\n\nexport function fDateTime(date: DatePickerFormat, format?: string) {\n if (!date) {\n return null;\n }\n\n const isValid = dayjs(date).isValid();\n\n return isValid\n ? dayjs(date).format(format ?? formatStr.dateTime)\n : 'Invalid time value';\n}\n\nexport function fDate(date: DatePickerFormat, format?: string) {\n if (!date) {\n return null;\n }\n\n const isValid = dayjs(date).isValid();\n\n return isValid\n ? dayjs(date).format(format ?? formatStr.date)\n : 'Invalid time value';\n}\n\nexport function fTime(date: DatePickerFormat, format?: string) {\n if (!date) {\n return null;\n }\n\n const isValid = dayjs(date).isValid();\n\n return isValid\n ? dayjs(date).format(format ?? formatStr.time)\n : 'Invalid time value';\n}\n\nexport function fTimestamp(date: DatePickerFormat) {\n if (!date) {\n return null;\n }\n\n const isValid = dayjs(date).isValid();\n\n return isValid ? dayjs(date).valueOf() : 'Invalid time value';\n}\n\nexport function fToNow(date: DatePickerFormat) {\n if (!date) {\n return null;\n }\n\n const isValid = dayjs(date).isValid();\n\n return isValid ? dayjs(date).toNow(true) : 'Invalid time value';\n}\n\nexport function fIsBetween(\n inputDate: DatePickerFormat,\n startDate: DatePickerFormat,\n endDate: DatePickerFormat,\n) {\n if (!inputDate || !startDate || !endDate) {\n return false;\n }\n\n const formattedInputDate = fTimestamp(inputDate);\n const formattedStartDate = fTimestamp(startDate);\n const formattedEndDate = fTimestamp(endDate);\n\n if (formattedInputDate && formattedStartDate && formattedEndDate) {\n return (\n formattedInputDate >= formattedStartDate &&\n formattedInputDate <= formattedEndDate\n );\n }\n\n return false;\n}\n\nexport function fIsAfter(\n startDate: DatePickerFormat,\n endDate: DatePickerFormat,\n) {\n return dayjs(startDate).isAfter(endDate);\n}\n\nexport function fIsSame(\n startDate: DatePickerFormat,\n endDate: DatePickerFormat,\n units?: OpUnitType,\n) {\n if (!startDate || !endDate) {\n return false;\n }\n\n const isValid = dayjs(startDate).isValid() && dayjs(endDate).isValid();\n\n if (!isValid) {\n return 'Invalid time value';\n }\n\n return dayjs(startDate).isSame(endDate, units ?? 'year');\n}\n\nexport function fDateRangeShortLabel(\n startDate: DatePickerFormat,\n endDate: DatePickerFormat,\n initial?: boolean,\n) {\n const isValid = dayjs(startDate).isValid() && dayjs(endDate).isValid();\n\n const isAfter = fIsAfter(startDate, endDate);\n\n if (!isValid || isAfter) {\n return 'Invalid time value';\n }\n\n let label = `${fDate(startDate)} - ${fDate(endDate)}`;\n\n if (initial) {\n return label;\n }\n\n const isSameYear = fIsSame(startDate, endDate, 'year');\n const isSameMonth = fIsSame(startDate, endDate, 'month');\n const isSameDay = fIsSame(startDate, endDate, 'day');\n\n if (isSameYear && !isSameMonth) {\n label = `${fDate(startDate, 'DD MMM')} - ${fDate(endDate)}`;\n } else if (isSameYear && isSameMonth && !isSameDay) {\n label = `${fDate(startDate, 'DD')} - ${fDate(endDate)}`;\n } else if (isSameYear && isSameMonth && isSameDay) {\n label = `${fDate(endDate)}`;\n }\n\n return label;\n}\n\nexport type DurationProps = {\n years?: number;\n months?: number;\n days?: number;\n hours?: number;\n minutes?: number;\n seconds?: number;\n milliseconds?: number;\n};\n\nexport function fAdd({\n years = 0,\n months = 0,\n days = 0,\n hours = 0,\n minutes = 0,\n seconds = 0,\n milliseconds = 0,\n}: DurationProps) {\n const result = dayjs()\n .add(\n dayjs.duration({\n years,\n months,\n days,\n hours,\n minutes,\n seconds,\n milliseconds,\n }),\n )\n .format();\n\n return result;\n}\n\nexport function fSub({\n years = 0,\n months = 0,\n days = 0,\n hours = 0,\n minutes = 0,\n seconds = 0,\n milliseconds = 0,\n}: DurationProps) {\n const result = dayjs()\n .subtract(\n dayjs.duration({\n years,\n months,\n days,\n hours,\n minutes,\n seconds,\n milliseconds,\n }),\n )\n .format();\n\n return result;\n}\n\nexport const getDifferenceInDays = (startDate?: Date, endDate?: Date) => {\n if (!startDate || !endDate) return null;\n\n return dayjs(endDate).diff(dayjs(startDate), 'day');\n};\n"]}
|
package/dist/utils/loadable.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { Suspense } from 'react';
|
|
3
|
-
import
|
|
3
|
+
import FixedProgressBar from 'components/FixedProgressBar';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const loadable = (Component) => (
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
function loader(props) {
|
|
8
|
+
return /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(FixedProgressBar, {}), children: /* @__PURE__ */ jsx(Component, { ...props }) });
|
|
9
|
+
}
|
|
10
|
+
);
|
|
11
|
+
var loadable_default = loadable;
|
|
6
12
|
|
|
7
|
-
export {
|
|
13
|
+
export { loadable_default as default };
|
|
14
|
+
//# sourceMappingURL=out.js.map
|
|
15
|
+
//# sourceMappingURL=loadable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/loadable.tsx"],"names":[],"mappings":"AAQ0B;AAR1B,SAAsB,gBAAgB;AAEtC,OAAO,sBAAsB;AAE7B,MAAM,WAAW,CAAC;AAAA;AAAA,EAEhB,SAAS,OAAO,OAAY;AAC1B,WACE,oBAAC,YAAS,UAAU,oBAAC,oBAAiB,GACpC,8BAAC,aAAW,GAAG,OAAO,GACxB;AAAA,EAEJ;AAAA;AAEF,IAAO,mBAAQ","sourcesContent":["import { ElementType, Suspense } from 'react';\n\nimport FixedProgressBar from 'components/FixedProgressBar';\n\nconst loadable = (Component: ElementType) =>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function loader(props: any) {\n return (\n <Suspense fallback={<FixedProgressBar />}>\n <Component {...props} />\n </Suspense>\n );\n };\n\nexport default loadable;\n"]}
|
package/dist/utils/mask.js
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
-
const
|
|
1
|
+
const applyMask = (value = "", mask) => {
|
|
2
|
+
let formattedString = "";
|
|
3
|
+
let j = 0;
|
|
4
|
+
[...mask].forEach((char) => {
|
|
5
|
+
formattedString += char === "#" ? value[j++] || "_" : char;
|
|
6
|
+
});
|
|
7
|
+
return formattedString;
|
|
8
|
+
};
|
|
9
|
+
const cpfMask = (v) => {
|
|
10
|
+
const value = v || "";
|
|
11
|
+
return applyMask(value.replace(/\D/g, ""), "###.###.###-##");
|
|
12
|
+
};
|
|
13
|
+
const cnpjMask = (v) => {
|
|
14
|
+
const value = v || "";
|
|
15
|
+
return applyMask(value.replace(/\D/g, ""), "##.###.###/####-##");
|
|
16
|
+
};
|
|
17
|
+
const cepMask = (v) => {
|
|
18
|
+
const value = v || "";
|
|
19
|
+
return applyMask(value.replace(/\D/g, ""), "#####-###");
|
|
20
|
+
};
|
|
21
|
+
const phoneMask = (v) => {
|
|
22
|
+
const value = v || "";
|
|
23
|
+
const numericValue = value.replace(/\D/g, "");
|
|
24
|
+
const mask = numericValue.length === 11 ? "(##) #####-####" : "(##) ####-####";
|
|
25
|
+
return applyMask(numericValue, mask);
|
|
26
|
+
};
|
|
27
|
+
const cpfMaskOrCnpjMask = (v) => {
|
|
28
|
+
const value = v || "";
|
|
29
|
+
const onlyNumbers = (value || "").replace(/\D/g, "");
|
|
30
|
+
if (onlyNumbers.length === 11)
|
|
31
|
+
return cpfMask(onlyNumbers);
|
|
32
|
+
if (onlyNumbers.length === 14)
|
|
33
|
+
return cnpjMask(onlyNumbers);
|
|
34
|
+
return null;
|
|
35
|
+
};
|
|
2
36
|
|
|
3
|
-
export {
|
|
37
|
+
export { applyMask, cepMask, cnpjMask, cpfMask, cpfMaskOrCnpjMask, phoneMask };
|
|
38
|
+
//# sourceMappingURL=out.js.map
|
|
39
|
+
//# sourceMappingURL=mask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/mask.ts"],"names":[],"mappings":"AAAO,MAAM,YAAY,CAAC,QAAQ,IAAI,SAAiB;AACrD,MAAI,kBAAkB;AACtB,MAAI,IAAI;AAGR,GAAC,GAAG,IAAI,EAAE,QAAQ,UAAQ;AAExB,uBAAmB,SAAS,MAAM,MAAM,GAAG,KAAK,MAAM;AAAA,EACxD,CAAC;AAED,SAAO;AACT;AAEO,MAAM,UAAU,CAAC,MAAc;AACpC,QAAM,QAAQ,KAAK;AACnB,SAAO,UAAU,MAAM,QAAQ,OAAO,EAAE,GAAG,gBAAgB;AAC7D;AAEO,MAAM,WAAW,CAAC,MAAc;AACrC,QAAM,QAAQ,KAAK;AACnB,SAAO,UAAU,MAAM,QAAQ,OAAO,EAAE,GAAG,oBAAoB;AACjE;AAEO,MAAM,UAAU,CAAC,MAAc;AACpC,QAAM,QAAQ,KAAK;AACnB,SAAO,UAAU,MAAM,QAAQ,OAAO,EAAE,GAAG,WAAW;AACxD;AAEO,MAAM,YAAY,CAAC,MAAc;AACtC,QAAM,QAAQ,KAAK;AACnB,QAAM,eAAe,MAAM,QAAQ,OAAO,EAAE;AAC5C,QAAM,OACJ,aAAa,WAAW,KAAK,oBAAoB;AAEnD,SAAO,UAAU,cAAc,IAAI;AACrC;AAEO,MAAM,oBAAoB,CAAC,MAAc;AAC9C,QAAM,QAAQ,KAAK;AACnB,QAAM,eAAe,SAAS,IAAI,QAAQ,OAAO,EAAE;AAEnD,MAAI,YAAY,WAAW;AAAI,WAAO,QAAQ,WAAW;AAEzD,MAAI,YAAY,WAAW;AAAI,WAAO,SAAS,WAAW;AAE1D,SAAO;AACT","sourcesContent":["export const applyMask = (value = '', mask: string) => {\n let formattedString = '';\n let j = 0;\n\n // Iterate through each character in the mask\n [...mask].forEach(char => {\n // If the character is '#', insert the next character from the input string, or '_' if the input string is shorter\n formattedString += char === '#' ? value[j++] || '_' : char;\n });\n\n return formattedString;\n};\n\nexport const cpfMask = (v: string) => {\n const value = v || '';\n return applyMask(value.replace(/\\D/g, ''), '###.###.###-##');\n};\n\nexport const cnpjMask = (v: string) => {\n const value = v || '';\n return applyMask(value.replace(/\\D/g, ''), '##.###.###/####-##');\n};\n\nexport const cepMask = (v: string) => {\n const value = v || '';\n return applyMask(value.replace(/\\D/g, ''), '#####-###');\n};\n\nexport const phoneMask = (v: string) => {\n const value = v || '';\n const numericValue = value.replace(/\\D/g, '');\n const mask =\n numericValue.length === 11 ? '(##) #####-####' : '(##) ####-####';\n\n return applyMask(numericValue, mask);\n};\n\nexport const cpfMaskOrCnpjMask = (v: string) => {\n const value = v || '';\n const onlyNumbers = (value || '').replace(/\\D/g, '');\n\n if (onlyNumbers.length === 11) return cpfMask(onlyNumbers);\n\n if (onlyNumbers.length === 14) return cnpjMask(onlyNumbers);\n\n return null;\n};\n"]}
|
package/dist/utils/number.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
function
|
|
1
|
+
function isMultiple(possibleMultiple, reference, exponent = 0) {
|
|
2
|
+
return Math.round(10 ** (exponent || 0) * possibleMultiple) % Math.round(10 ** (exponent || 0) * reference) === 0;
|
|
3
|
+
}
|
|
4
|
+
function roundIfNecessary(value = 0) {
|
|
5
|
+
return Math.round(value * 100) / 100;
|
|
6
|
+
}
|
|
7
|
+
const isNumeric = (string) => {
|
|
8
|
+
return /^[+-]?\d+(\.\d+)?$/.test(string);
|
|
9
|
+
};
|
|
2
10
|
|
|
3
|
-
export {
|
|
11
|
+
export { isMultiple, isNumeric, roundIfNecessary };
|
|
12
|
+
//# sourceMappingURL=out.js.map
|
|
13
|
+
//# sourceMappingURL=number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/number.ts"],"names":[],"mappings":"AAAO,SAAS,WACd,kBACA,WACA,WAAW,GACX;AACA,SACE,KAAK,MAAM,OAAO,YAAY,KAAK,gBAAgB,IACjD,KAAK,MAAM,OAAO,YAAY,KAAK,SAAS,MAC9C;AAEJ;AAEO,SAAS,iBAAiB,QAAQ,GAAG;AAC1C,SAAO,KAAK,MAAM,QAAQ,GAAG,IAAI;AACnC;AAEO,MAAM,YAAY,CAAC,WAAmB;AAC3C,SAAO,qBAAqB,KAAK,MAAM;AACzC","sourcesContent":["export function isMultiple(\n possibleMultiple: number,\n reference: number,\n exponent = 0,\n) {\n return (\n Math.round(10 ** (exponent || 0) * possibleMultiple) %\n Math.round(10 ** (exponent || 0) * reference) ===\n 0\n );\n}\n\nexport function roundIfNecessary(value = 0) {\n return Math.round(value * 100) / 100;\n}\n\nexport const isNumeric = (string: string) => {\n return /^[+-]?\\d+(\\.\\d+)?$/.test(string);\n};\n"]}
|
package/dist/utils/sort.js
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
function
|
|
1
|
+
function sort(arr, prop, direction = "asc") {
|
|
2
|
+
return arr.slice().sort((a, b) => {
|
|
3
|
+
const aValue = a[prop];
|
|
4
|
+
const bValue = b[prop];
|
|
5
|
+
if (aValue < bValue) {
|
|
6
|
+
return direction === "asc" ? -1 : 1;
|
|
7
|
+
}
|
|
8
|
+
if (aValue > bValue) {
|
|
9
|
+
return direction === "asc" ? 1 : -1;
|
|
10
|
+
}
|
|
11
|
+
return 0;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function updatePosition(initialIndex, newIndex, rows) {
|
|
15
|
+
const rowsClone = [...rows];
|
|
16
|
+
const row = rowsClone.splice(initialIndex, 1)[0];
|
|
17
|
+
rowsClone.splice(newIndex, 0, row);
|
|
18
|
+
return rowsClone;
|
|
19
|
+
}
|
|
2
20
|
|
|
3
|
-
export {
|
|
21
|
+
export { sort, updatePosition };
|
|
22
|
+
//# sourceMappingURL=out.js.map
|
|
23
|
+
//# sourceMappingURL=sort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/sort.ts"],"names":[],"mappings":"AAAA,SAAS,KACP,KACA,MACA,YAA4B,OACvB;AACL,SAAO,IAAI,MAAM,EAAE,KAAK,CAAC,GAAG,MAAM;AAChC,UAAM,SAAS,EAAE,IAAI;AACrB,UAAM,SAAS,EAAE,IAAI;AAErB,QAAI,SAAS,QAAQ;AACnB,aAAO,cAAc,QAAQ,KAAK;AAAA,IACpC;AAEA,QAAI,SAAS,QAAQ;AACnB,aAAO,cAAc,QAAQ,IAAI;AAAA,IACnC;AAEA,WAAO;AAAA,EACT,CAAC;AACH;AAEA,SAAS,eACP,cACA,UACA,MACK;AACL,QAAM,YAAY,CAAC,GAAG,IAAI;AAC1B,QAAM,MAAM,UAAU,OAAO,cAAc,CAAC,EAAE,CAAC;AAC/C,YAAU,OAAO,UAAU,GAAG,GAAG;AAEjC,SAAO;AACT","sourcesContent":["function sort<T>(\n arr: T[],\n prop: keyof T,\n direction: 'asc' | 'desc' = 'asc',\n): T[] {\n return arr.slice().sort((a, b) => {\n const aValue = a[prop];\n const bValue = b[prop];\n\n if (aValue < bValue) {\n return direction === 'asc' ? -1 : 1;\n }\n\n if (aValue > bValue) {\n return direction === 'asc' ? 1 : -1;\n }\n\n return 0;\n });\n}\n\nfunction updatePosition<T>(\n initialIndex: number,\n newIndex: number,\n rows: Array<T>,\n): T[] {\n const rowsClone = [...rows];\n const row = rowsClone.splice(initialIndex, 1)[0];\n rowsClone.splice(newIndex, 0, row);\n\n return rowsClone;\n}\n\nexport { sort, updatePosition };\n"]}
|
package/dist/utils/uuidv4.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
function
|
|
1
|
+
function uuidv4() {
|
|
2
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
3
|
+
const r = Math.random() * 16 | 0, v = c === "x" ? r : r & 3 | 8;
|
|
4
|
+
return v.toString(16);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
2
7
|
|
|
3
|
-
export {
|
|
8
|
+
export { uuidv4 as default };
|
|
9
|
+
//# sourceMappingURL=out.js.map
|
|
10
|
+
//# sourceMappingURL=uuidv4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/uuidv4.ts"],"names":[],"mappings":"AAAe,SAAR,SAA0B;AAC/B,SAAO,uCAAuC,QAAQ,SAAS,SAAU,GAAG;AAC1E,UAAM,IAAK,KAAK,OAAO,IAAI,KAAM,GAC/B,IAAI,MAAM,MAAM,IAAK,IAAI,IAAO;AAClC,WAAO,EAAE,SAAS,EAAE;AAAA,EACtB,CAAC;AACH","sourcesContent":["export default function uuidv4() {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\n const r = (Math.random() * 16) | 0,\n v = c === 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n}\n"]}
|
package/dist/utils/validators.js
CHANGED
|
@@ -1,3 +1,83 @@
|
|
|
1
|
-
const
|
|
1
|
+
const cpfIsValid = (cpf) => {
|
|
2
|
+
if (!cpf)
|
|
3
|
+
return false;
|
|
4
|
+
cpf = cpf?.replace(/[^\d]+/g, "");
|
|
5
|
+
if (cpf.length !== 11 || cpf === "00000000000" || cpf === "11111111111" || cpf === "22222222222" || cpf === "33333333333" || cpf === "44444444444" || cpf === "55555555555" || cpf === "66666666666" || cpf === "77777777777" || cpf === "88888888888" || cpf === "99999999999")
|
|
6
|
+
return false;
|
|
7
|
+
let add = 0;
|
|
8
|
+
for (let i = 0; i < 9; i++)
|
|
9
|
+
add += parseInt(cpf.charAt(i)) * (10 - i);
|
|
10
|
+
let rev = 11 - add % 11;
|
|
11
|
+
if (rev === 10 || rev === 11)
|
|
12
|
+
rev = 0;
|
|
13
|
+
if (rev !== parseInt(cpf.charAt(9)))
|
|
14
|
+
return false;
|
|
15
|
+
add = 0;
|
|
16
|
+
for (let i = 0; i < 10; i++)
|
|
17
|
+
add += parseInt(cpf.charAt(i)) * (11 - i);
|
|
18
|
+
rev = 11 - add % 11;
|
|
19
|
+
if (rev === 10 || rev === 11)
|
|
20
|
+
rev = 0;
|
|
21
|
+
if (rev !== parseInt(cpf.charAt(10)))
|
|
22
|
+
return false;
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
25
|
+
const cnpjIsValid = (cnpj) => {
|
|
26
|
+
if (!cnpj)
|
|
27
|
+
return false;
|
|
28
|
+
cnpj = cnpj.replace(/[^\d]+/g, "");
|
|
29
|
+
if (cnpj.length !== 14)
|
|
30
|
+
return false;
|
|
31
|
+
if (cnpj === "00000000000000" || cnpj === "11111111111111" || cnpj === "22222222222222" || cnpj === "33333333333333" || cnpj === "44444444444444" || cnpj === "55555555555555" || cnpj === "66666666666666" || cnpj === "77777777777777" || cnpj === "88888888888888" || cnpj === "99999999999999")
|
|
32
|
+
return false;
|
|
33
|
+
let size = cnpj.length - 2;
|
|
34
|
+
let numbers = cnpj.substring(0, size);
|
|
35
|
+
const digits = cnpj.substring(size);
|
|
36
|
+
let sum = 0;
|
|
37
|
+
let position = size - 7;
|
|
38
|
+
for (let i = size; i >= 1; i--) {
|
|
39
|
+
sum += parseInt(numbers.charAt(size - i)) * position--;
|
|
40
|
+
if (position < 2)
|
|
41
|
+
position = 9;
|
|
42
|
+
}
|
|
43
|
+
let result = sum % 11 < 2 ? 0 : 11 - sum % 11;
|
|
44
|
+
if (result !== parseInt(digits.charAt(0)))
|
|
45
|
+
return false;
|
|
46
|
+
size += 1;
|
|
47
|
+
numbers = cnpj.substring(0, size);
|
|
48
|
+
sum = 0;
|
|
49
|
+
position = size - 7;
|
|
50
|
+
for (let i = size; i >= 1; i--) {
|
|
51
|
+
sum += parseInt(numbers.charAt(size - i)) * position--;
|
|
52
|
+
if (position < 2)
|
|
53
|
+
position = 9;
|
|
54
|
+
}
|
|
55
|
+
result = sum % 11 < 2 ? 0 : 11 - sum % 11;
|
|
56
|
+
if (result !== parseInt(digits.charAt(1)))
|
|
57
|
+
return false;
|
|
58
|
+
return true;
|
|
59
|
+
};
|
|
60
|
+
const emailIsValid = (email = "") => {
|
|
61
|
+
if (!email)
|
|
62
|
+
return false;
|
|
63
|
+
const isValid = email.toLowerCase().match(
|
|
64
|
+
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
65
|
+
);
|
|
66
|
+
return !!isValid;
|
|
67
|
+
};
|
|
68
|
+
const validatePassword = (password = "", passwordSize = [8, 20], numberChar = false, specialCharacter = false, upperCaseChar = false) => {
|
|
69
|
+
const isLengthValid = password.length >= passwordSize[0] && password.length <= passwordSize[1];
|
|
70
|
+
const hasUpperCaseChar = !upperCaseChar || /[A-Z]/.test(password);
|
|
71
|
+
const hasSpecialCharacter = !specialCharacter || /[!@#$%^&*(),.?":{}|<>]/.test(password);
|
|
72
|
+
const hasNumberChar = !numberChar || /\d/.test(password);
|
|
73
|
+
return {
|
|
74
|
+
isLengthValid,
|
|
75
|
+
hasUpperCaseChar,
|
|
76
|
+
hasSpecialCharacter,
|
|
77
|
+
hasNumberChar
|
|
78
|
+
};
|
|
79
|
+
};
|
|
2
80
|
|
|
3
|
-
export {
|
|
81
|
+
export { cnpjIsValid, cpfIsValid, emailIsValid, validatePassword };
|
|
82
|
+
//# sourceMappingURL=out.js.map
|
|
83
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AAAO,MAAM,aAAa,CAAC,QAAgB;AACzC,MAAI,CAAC;AAAK,WAAO;AACjB,Q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,iBAAW;AAAA,EAC/B;AACA,MAAI,SAAS,MAAM,KAAK,IAAI,IAAI,KAAM,MAAM;AAC5C,MAAI,WAAW,SAAS,OAAO,OAAO,CAAC,CAAC;AAAG,WAAO;AAElD,UAAQ;AACR,YAAU,KAAK,UAAU,GAAG,IAAI;AAChC,QAAM;AACN,aAAW,OAAO;AAClB,WAAS,IAAI,MAAM,KAAK,GAAG,KAAK;AAC9B,WAAO,SAAS,QAAQ,OAAO,OAAO,CAAC,CAAC,IAAI;AAC5C,QAAI,WAAW;AAAG,iBAAW;AAAA,EAC/B;AACA,WAAS,MAAM,KAAK,IAAI,IAAI,KAAM,MAAM;AACxC,MAAI,WAAW,SAAS,OAAO,OAAO,CAAC,CAAC;AAAG,WAAO;AAElD,SAAO;AACT;AAEO,MAAM,eAAe,CAAC,QAAQ,OAAO;AAC1C,MAAI,CAAC;AAAO,WAAO;AAEnB,QAAM,UAAU,MACb,YAAY,EACZ;AAAA,IACC;AAAA,EACF;AAEF,SAAO,CAAC,CAAC;AACX;AAEO,MAAM,mBAAmB,CAC9B,WAAW,IACX,eAAe,CAAC,GAAG,EAAE,GACrB,aAAa,OACb,mBAAmB,OACnB,gBAAgB,UACb;AACH,QAAM,gBACJ,SAAS,UAAU,aAAa,CAAC,KAAK,SAAS,UAAU,aAAa,CAAC;AACzE,QAAM,mBAAmB,CAAC,iBAAiB,QAAQ,KAAK,QAAQ;AAChE,QAAM,sBACJ,CAAC,oBAAoB,yBAAyB,KAAK,QAAQ;AAC7D,QAAM,gBAAgB,CAAC,cAAc,KAAK,KAAK,QAAQ;AAEvD,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF","sourcesContent":["export const cpfIsValid = (cpf: string) => {\n if (!cpf) return false;\n cpf = cpf?.replace(/[^\\d]+/g, '');\n if (\n cpf.length !== 11 ||\n cpf === '00000000000' ||\n cpf === '11111111111' ||\n cpf === '22222222222' ||\n cpf === '33333333333' ||\n cpf === '44444444444' ||\n cpf === '55555555555' ||\n cpf === '66666666666' ||\n cpf === '77777777777' ||\n cpf === '88888888888' ||\n cpf === '99999999999'\n )\n return false;\n let add = 0;\n for (let i = 0; i < 9; i++) add += parseInt(cpf.charAt(i)) * (10 - i);\n let rev = 11 - (add % 11);\n if (rev === 10 || rev === 11) rev = 0;\n if (rev !== parseInt(cpf.charAt(9))) return false;\n add = 0;\n for (let i = 0; i < 10; i++) add += parseInt(cpf.charAt(i)) * (11 - i);\n rev = 11 - (add % 11);\n if (rev === 10 || rev === 11) rev = 0;\n if (rev !== parseInt(cpf.charAt(10))) return false;\n return true;\n};\n\nexport const cnpjIsValid = (cnpj: string) => {\n if (!cnpj) return false;\n cnpj = cnpj.replace(/[^\\d]+/g, '');\n\n if (cnpj.length !== 14) return false;\n\n if (\n cnpj === '00000000000000' ||\n cnpj === '11111111111111' ||\n cnpj === '22222222222222' ||\n cnpj === '33333333333333' ||\n cnpj === '44444444444444' ||\n cnpj === '55555555555555' ||\n cnpj === '66666666666666' ||\n cnpj === '77777777777777' ||\n cnpj === '88888888888888' ||\n cnpj === '99999999999999'\n )\n return false;\n\n let size = cnpj.length - 2;\n let numbers = cnpj.substring(0, size);\n const digits = cnpj.substring(size);\n let sum = 0;\n let position = size - 7;\n for (let i = size; i >= 1; i--) {\n sum += parseInt(numbers.charAt(size - i)) * position--;\n if (position < 2) position = 9;\n }\n let result = sum % 11 < 2 ? 0 : 11 - (sum % 11);\n if (result !== parseInt(digits.charAt(0))) return false;\n\n size += 1;\n numbers = cnpj.substring(0, size);\n sum = 0;\n position = size - 7;\n for (let i = size; i >= 1; i--) {\n sum += parseInt(numbers.charAt(size - i)) * position--;\n if (position < 2) position = 9;\n }\n result = sum % 11 < 2 ? 0 : 11 - (sum % 11);\n if (result !== parseInt(digits.charAt(1))) return false;\n\n return true;\n};\n\nexport const emailIsValid = (email = '') => {\n if (!email) return false;\n\n const isValid = email\n .toLowerCase()\n .match(\n /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/,\n );\n\n return !!isValid;\n};\n\nexport const validatePassword = (\n password = '',\n passwordSize = [8, 20],\n numberChar = false,\n specialCharacter = false,\n upperCaseChar = false,\n) => {\n const isLengthValid =\n password.length >= passwordSize[0] && password.length <= passwordSize[1];\n const hasUpperCaseChar = !upperCaseChar || /[A-Z]/.test(password);\n const hasSpecialCharacter =\n !specialCharacter || /[!@#$%^&*(),.?\":{}|<>]/.test(password);\n const hasNumberChar = !numberChar || /\\d/.test(password);\n\n return {\n isLengthValid,\n hasUpperCaseChar,\n hasSpecialCharacter,\n hasNumberChar,\n };\n};\n"]}
|