Utils Functions

Utils Function

Folder location: src/lib


import formatDistanceStrict from 'date-fns/formatDistanceStrict'
function getDateDifference(date) {
  const distance = formatDistanceStrict(new Date(), new Date(date))
  return distance + ' ago'


It takes two arguments, subtracts the discount from the original price, and returns the new price.

function calculateDiscount(price, discount) {
  const afterDiscount = Number((price - price * (discount / 100)).toFixed(2))
  return currency(afterDiscount)


The price, which is a number, and the length of the fraction are the two arguments it receives.

function currency(price, fraction = 2) {
  const formatCurrency = currencyJs(price).format({ precision: fraction })
  return formatCurrency