{"size": 692, "ext": "js", "max_stars_repo_path": ".history/src/utils/format_20191214143554.js", "max_stars_repo_name": "vadyvarela/gympoint-web", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": ".history/src/utils/format_20191214143554.js", "max_issues_repo_name": "vadyvarela/gympoint-web", "max_issues_repo_issues_event_min_datetime": "2021-05-10T20:48:17.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-06T08:32:06.000Z", "max_forks_repo_path": "src/utils/format.js", "max_forks_repo_name": "vadyvarela/gympoint-web", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 27.68, "max_line_length": 72, "alphanum_fraction": 0.6156069364}
import { format, parseISO } from 'date-fns';

export const { format: formatPrice } = new Intl.NumberFormat('pt-BR', {
  style: 'currency',
  currency: 'BRL',
});

export const formatCurrency = value => {
  if (!value) return value;
  value = value.replace(/\./g, ',');
  const index = value.lastIndexOf(',');
  const first = `${value.substr(0, index).replace(/,/g, '')}`;
  const decimal = `${value.substr(index).replace(',', '.')}`;
  const currency = Number(`${first}${decimal}`);

  return currency;
};

export const formatDatePicker = value => {
  if (!value) return null;
  const dateFormatted = format(parseISO(value), 'yyyy-MM-dd');

  return dateFormatted;
};
