UNPKG

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