closestIndexTo.d.cts 915 B

1234567891011121314151617181920212223242526272829
  1. import type { DateArg } from "./types.js";
  2. /**
  3. * @name closestIndexTo
  4. * @category Common Helpers
  5. * @summary Return an index of the closest date from the array comparing to the given date.
  6. *
  7. * @description
  8. * Return an index of the closest date from the array comparing to the given date.
  9. *
  10. * @param dateToCompare - The date to compare with
  11. * @param dates - The array to search
  12. *
  13. * @returns An index of the date closest to the given date or undefined if no valid value is given
  14. *
  15. * @example
  16. * // Which date is closer to 6 September 2015?
  17. * const dateToCompare = new Date(2015, 8, 6)
  18. * const datesArray = [
  19. * new Date(2015, 0, 1),
  20. * new Date(2016, 0, 1),
  21. * new Date(2017, 0, 1)
  22. * ]
  23. * const result = closestIndexTo(dateToCompare, datesArray)
  24. * //=> 1
  25. */
  26. export declare function closestIndexTo(
  27. dateToCompare: DateArg<Date> & {},
  28. dates: Array<DateArg<Date> & {}>,
  29. ): number | undefined;