Files
klz-cables.com/.pnpm-store/v10/files/fd/10f1171b32d65ef4711a911e1846b747afb07cc69741dd6c6d56d640e212e4e552de514fb3b35166c548e6b2dae8adb1739bc92d65fc397ec78fc3747a85d9
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

58 lines
1.8 KiB
Plaintext

"use strict";
exports.closestTo = closestTo;
var _index = require("./_lib/normalizeDates.cjs");
var _index2 = require("./closestIndexTo.cjs");
var _index3 = require("./constructFrom.cjs");
/**
* The {@link closestTo} function options.
*/
/**
* The {@link closestTo} function result type. It resolves the proper data type.
* It uses the first argument date object type, starting from the date argument,
* then the start interval date, and finally the end interval date. If
* a context function is passed, it uses the context function return type.
*/
/**
* @name closestTo
* @category Common Helpers
* @summary Return a date from the array closest to the given date.
*
* @description
* Return a date from the array closest to the given date.
*
* @typeParam DateToCompare - Date to compare argument type.
* @typeParam DatesType - Dates array argument type.
* @typeParam Options - Options type.
*
* @param dateToCompare - The date to compare with
* @param dates - The array to search
*
* @returns The date from the array closest to the given date or undefined if no valid value is given
*
* @example
* // Which date is closer to 6 September 2015: 1 January 2000 or 1 January 2030?
* const dateToCompare = new Date(2015, 8, 6)
* const result = closestTo(dateToCompare, [
* new Date(2000, 0, 1),
* new Date(2030, 0, 1)
* ])
* //=> Tue Jan 01 2030 00:00:00
*/
function closestTo(dateToCompare, dates, options) {
const [dateToCompare_, ...dates_] = (0, _index.normalizeDates)(
options?.in,
dateToCompare,
...dates,
);
const index = (0, _index2.closestIndexTo)(dateToCompare_, dates_);
if (typeof index === "number" && isNaN(index))
return (0, _index3.constructFrom)(dateToCompare_, NaN);
if (index !== undefined) return dates_[index];
}