eai-frontend-components 2.0.20 → 2.0.21

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/index.js CHANGED
@@ -792,6 +792,20 @@ const removeMaskNumber = (value) => {
792
792
  };
793
793
 
794
794
  // PHONE
795
+ /**
796
+ * Formats a phone number string with proper mask.
797
+ * Automatically detects landline vs mobile format.
798
+ *
799
+ * @param telefone - Raw phone number string
800
+ * @param removerCountryCode - Whether to remove country code (55) if present
801
+ * @returns Formatted phone number string
802
+ *
803
+ * @example
804
+ * ```tsx
805
+ * formatPhone('11987654321') // '(11) 9 8765-4321'
806
+ * formatPhone('1134567890') // '(11) 3456-7890'
807
+ * ```
808
+ */
795
809
  function formatPhone(telefone, removerCountryCode = true) {
796
810
  if (!telefone)
797
811
  return '';
@@ -803,6 +817,19 @@ function formatPhone(telefone, removerCountryCode = true) {
803
817
  return mask.format(numberPhone, maskPhone(numberPhone));
804
818
  }
805
819
  // CPF/CNPJ
820
+ /**
821
+ * Formats a CPF or CNPJ string with proper mask.
822
+ * Automatically detects CPF vs CNPJ format based on length.
823
+ *
824
+ * @param cpfCnpj - Raw CPF/CNPJ string
825
+ * @returns Formatted CPF/CNPJ string
826
+ *
827
+ * @example
828
+ * ```tsx
829
+ * formatCpfCnpj('12345678901') // '123.456.789-01'
830
+ * formatCpfCnpj('12345678000195') // '12.345.678/0001-95'
831
+ * ```
832
+ */
806
833
  function formatCpfCnpj(cpfCnpj) {
807
834
  if (!cpfCnpj)
808
835
  return '';
@@ -819,6 +846,19 @@ function getMonth(date) {
819
846
  function getYear(date) {
820
847
  return date.getFullYear().toString();
821
848
  }
849
+ /**
850
+ * Formats a date to Brazilian format (DD/MM/YYYY).
851
+ *
852
+ * @param date - Date string, Date object, or undefined
853
+ * @param separator - Date separator (default: '/')
854
+ * @returns Formatted date string in Brazilian format
855
+ *
856
+ * @example
857
+ * ```tsx
858
+ * formatDate('2023-12-25') // '25/12/2023'
859
+ * formatDate(new Date()) // '13/10/2025'
860
+ * ```
861
+ */
822
862
  const formatDate = (date, separator = '/') => {
823
863
  if (!date)
824
864
  return '';
@@ -890,6 +930,19 @@ const formatNumber = (value) => {
890
930
  });
891
931
  };
892
932
  // DECIMAL
933
+ /**
934
+ * Formats a number with Brazilian decimal format.
935
+ *
936
+ * @param value - Numeric value to format
937
+ * @param decimalPlaces - Number of decimal places (default: 2)
938
+ * @returns Formatted decimal string
939
+ *
940
+ * @example
941
+ * ```tsx
942
+ * formatDecimal(1234.56) // '1.234,56'
943
+ * formatDecimal(1000.1, 1) // '1.000,1'
944
+ * ```
945
+ */
893
946
  const formatDecimal = (value, decimalPlaces = 2) => {
894
947
  return value.toLocaleString('pt-BR', {
895
948
  style: 'decimal',
@@ -897,6 +950,87 @@ const formatDecimal = (value, decimalPlaces = 2) => {
897
950
  maximumFractionDigits: decimalPlaces,
898
951
  });
899
952
  };
953
+ // PERCENT
954
+ /**
955
+ * Formats a number as percentage with Brazilian decimal format.
956
+ *
957
+ * @param value - Numeric value to format
958
+ * @param decimalPlaces - Number of decimal places (default: 2)
959
+ * @returns Formatted percentage string
960
+ *
961
+ * @example
962
+ * ```tsx
963
+ * formatPercent(15.5) // '% 15,50'
964
+ * formatPercent(100, 0) // '% 100'
965
+ * ```
966
+ */
967
+ const formatPercent = (value, decimalPlaces = 2) => {
968
+ return `% ${formatDecimal(value, decimalPlaces)}`;
969
+ };
970
+ // CURRENCY
971
+ /**
972
+ * Formats a number as Brazilian currency (BRL).
973
+ *
974
+ * @param value - Numeric value to format
975
+ * @param decimalPlaces - Number of decimal places (default: 2)
976
+ * @returns Formatted currency string
977
+ *
978
+ * @example
979
+ * ```tsx
980
+ * formatCurrency(1234.56) // 'R$ 1.234,56'
981
+ * formatCurrency(1000, 0) // 'R$ 1.000'
982
+ * ```
983
+ */
984
+ const formatCurrency = (value, decimalPlaces = 2) => {
985
+ return value.toLocaleString('pt-BR', {
986
+ style: 'currency',
987
+ currency: 'BRL',
988
+ minimumFractionDigits: decimalPlaces,
989
+ maximumFractionDigits: decimalPlaces,
990
+ });
991
+ };
992
+ const isInvalidCurrencyValue = (rawValue) => {
993
+ if (!rawValue || rawValue.trim() === '')
994
+ return true;
995
+ const numericValue = stringToNumber(rawValue);
996
+ return Number.isNaN(numericValue) || numericValue <= 0;
997
+ };
998
+ // OTHERS
999
+ /**
1000
+ * Formats an MSISDN (mobile phone number) to display format.
1001
+ *
1002
+ * @param value - Raw MSISDN string
1003
+ * @returns Formatted MSISDN string
1004
+ *
1005
+ * @example
1006
+ * ```tsx
1007
+ * formatMsisdn('5511987654321') // '(11) 98765-4321'
1008
+ * ```
1009
+ */
1010
+ function formatMsisdn(value = '') {
1011
+ const msisdn = value.replace(/\D/g, '');
1012
+ return `(${msisdn.slice(2, 4)}) ${msisdn.slice(4, 9)}-${msisdn.slice(9)}`;
1013
+ }
1014
+ /**
1015
+ * Formats a CEP (Brazilian postal code) with proper mask.
1016
+ *
1017
+ * @param cep - Raw CEP string
1018
+ * @returns Formatted CEP string (XXXXX-XXX)
1019
+ *
1020
+ * @example
1021
+ * ```tsx
1022
+ * formatCEP('01234567') // '01234-567'
1023
+ * formatCEP('12345') // '12345'
1024
+ * ```
1025
+ */
1026
+ function formatCEP(cep) {
1027
+ if (!cep)
1028
+ return '';
1029
+ return cep
1030
+ .replace(/\D/g, '')
1031
+ .replace(/(\d{5})(\d)/, '$1-$2')
1032
+ .replace(/(-\d{3})\d+?$/, '$1');
1033
+ }
900
1034
 
901
1035
  function buildFormatLongFn(args) {
902
1036
  return (options = {}) => {
@@ -3723,17 +3857,22 @@ exports.formHelpText = formHelpText;
3723
3857
  exports.formLabel = formLabel;
3724
3858
  exports.formLabelAndSubLabel = formLabelAndSubLabel;
3725
3859
  exports.formMessage = formMessage;
3860
+ exports.formatCEP = formatCEP;
3726
3861
  exports.formatCpfCnpj = formatCpfCnpj;
3862
+ exports.formatCurrency = formatCurrency;
3727
3863
  exports.formatDate = formatDate;
3728
3864
  exports.formatDateCalendar = formatDateCalendar;
3729
3865
  exports.formatDateTime = formatDateTime;
3730
3866
  exports.formatDecimal = formatDecimal;
3867
+ exports.formatMsisdn = formatMsisdn;
3731
3868
  exports.formatNumber = formatNumber;
3869
+ exports.formatPercent = formatPercent;
3732
3870
  exports.formatPhone = formatPhone;
3733
3871
  exports.getFirstDayOf90DaysAgo = getFirstDayOf90DaysAgo;
3734
3872
  exports.getFirstDayOfCurrentMonth = getFirstDayOfCurrentMonth;
3735
3873
  exports.getTailwindColorShades = getTailwindColorShades;
3736
3874
  exports.invertDate = invertDate;
3875
+ exports.isInvalidCurrencyValue = isInvalidCurrencyValue;
3737
3876
  exports.isUUIDv4 = isUUIDv4;
3738
3877
  exports.maskCpfCnpj = maskCpfCnpj;
3739
3878
  exports.maskPhone = maskPhone;