registration

This commit is contained in:
User
2025-02-02 16:08:03 +03:00
parent 7f6495eb4d
commit 78afbaed71
6334 changed files with 196774 additions and 165754 deletions

View File

@@ -1,3 +1,4 @@
import type { ConstructableDate, ContextFn, DateArg } from "./types.js";
/**
* @name constructFrom
* @category Generic Helpers
@@ -10,6 +11,11 @@
*
* It defaults to `Date` if the passed reference date is a number or a string.
*
* Starting from v3.7.0, it allows to construct a date using `[Symbol.for("constructDateFrom")]`
* enabling to transfer extra properties from the reference date to the new date.
* It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
* that accept a time zone as a constructor argument.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The reference date to take constructor from
@@ -18,17 +24,20 @@
* @returns Date initialized using the given date and value
*
* @example
* import { constructFrom } from 'date-fns'
* import { constructFrom } from "./constructFrom/date-fns";
*
* // A function that clones a date preserving the original type
* function cloneDate<DateType extends Date(date: DateType): DateType {
* function cloneDate<DateType extends Date>(date: DateType): DateType {
* return constructFrom(
* date, // Use contrustor from the given date
* date, // Use constructor from the given date
* date.getTime() // Use the date value to create a new date
* )
* );
* }
*/
export declare function constructFrom<DateType extends Date>(
date: DateType | number | string,
value: Date | number | string,
): DateType;
export declare function constructFrom<
DateType extends Date | ConstructableDate,
ResultDate extends Date = DateType,
>(
date: DateArg<DateType> | ContextFn<ResultDate> | undefined,
value: DateArg<Date> & {},
): ResultDate;