UNPKG

@hhgtech/hhg-components

Version:
24 lines (20 loc) 808 B
import dayjs from 'dayjs'; const ageGenerate = (birthDate, calculateDate = new Date()) => { const numberOfWeek = Math.ceil(dayjs(calculateDate).diff(birthDate, 'week', true)); const numberOfMonth = dayjs(calculateDate).diff(birthDate, 'month'); const numberOfYear = Math.floor(numberOfMonth / 12); return { year: numberOfYear, month: numberOfMonth % 12, week: numberOfWeek, }; }; const localizeNumberFormat = (num, locale, maximumFractionDigits = 2) => { return Intl.NumberFormat(undefined, { maximumFractionDigits, }).format(num); }; const convertLocalizedStringToNumber = (value) => { return Number(value.replace(/,/gi, '.')); }; export { ageGenerate as a, convertLocalizedStringToNumber as c, localizeNumberFormat as l };