Files
klz-cables.com/.pnpm-store/v10/files/3c/77e0d6496c3ad88d37a49b4ad658b6dafac6808b32bdc7445fbb3fd04af1de7d128f944773d2033a66ee8be1365dcb2d8445b96b2f7a93336474a2bcf74394
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

62 lines
1.8 KiB
Plaintext

"use strict";
exports.clamp = clamp;
var _index = require("./_lib/normalizeDates.cjs");
var _index2 = require("./max.cjs");
var _index3 = require("./min.cjs");
/**
* The {@link clamp} function options.
*/
/**
* The {@link clamp} 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 clamp
* @category Interval Helpers
* @summary Return a date bounded by the start and the end of the given interval.
*
* @description
* Clamps a date to the lower bound with the start of the interval and the upper
* bound with the end of the interval.
*
* - When the date is less than the start of the interval, the start is returned.
* - When the date is greater than the end of the interval, the end is returned.
* - Otherwise the date is returned.
*
* @typeParam DateType - Date argument type.
* @typeParam IntervalType - Interval argument type.
* @typeParam Options - Options type.
*
* @param date - The date to be bounded
* @param interval - The interval to bound to
* @param options - An object with options
*
* @returns The date bounded by the start and the end of the interval
*
* @example
* // What is Mar 21, 2021 bounded to an interval starting at Mar 22, 2021 and ending at Apr 01, 2021
* const result = clamp(new Date(2021, 2, 21), {
* start: new Date(2021, 2, 22),
* end: new Date(2021, 3, 1),
* })
* //=> Mon Mar 22 2021 00:00:00
*/
function clamp(date, interval, options) {
const [date_, start, end] = (0, _index.normalizeDates)(
options?.in,
date,
interval.start,
interval.end,
);
return (0, _index3.min)(
[(0, _index2.max)([date_, start], options), end],
options,
);
}