yearsToMonths.js 583 B

12345678910111213141516171819202122232425
  1. import { monthsInYear } from "./constants.js";
  2. /**
  3. * @name yearsToMonths
  4. * @category Conversion Helpers
  5. * @summary Convert years to months.
  6. *
  7. * @description
  8. * Convert a number of years to a full number of months.
  9. *
  10. * @param years - The number of years to be converted
  11. *
  12. * @returns The number of years converted in months
  13. *
  14. * @example
  15. * // Convert 2 years into months
  16. * const result = yearsToMonths(2)
  17. * //=> 24
  18. */
  19. export function yearsToMonths(years) {
  20. return Math.trunc(years * monthsInYear);
  21. }
  22. // Fallback for modularized imports:
  23. export default yearsToMonths;