This commit is contained in:
2025-06-04 10:03:22 +02:00
commit 785a2b6134
14182 changed files with 1764617 additions and 0 deletions

View File

@ -0,0 +1,11 @@
"use strict";
exports.buildFormatLongFn = buildFormatLongFn;
function buildFormatLongFn(args) {
return (options = {}) => {
// TODO: Remove String()
const width = options.width ? String(options.width) : args.defaultWidth;
const format = args.formats[width] || args.formats[args.defaultWidth];
return format;
};
}

View File

@ -0,0 +1,14 @@
import type { FormatLongFn, FormatLongWidth } from "../types.js";
export interface BuildFormatLongFnArgs<
DefaultMatchWidth extends FormatLongWidth,
> {
formats: Partial<{
[format in FormatLongWidth]: string;
}> & {
[format in DefaultMatchWidth]: string;
};
defaultWidth: DefaultMatchWidth;
}
export declare function buildFormatLongFn<
DefaultMatchWidth extends FormatLongWidth,
>(args: BuildFormatLongFnArgs<DefaultMatchWidth>): FormatLongFn;

View File

@ -0,0 +1,14 @@
import type { FormatLongFn, FormatLongWidth } from "../types.js";
export interface BuildFormatLongFnArgs<
DefaultMatchWidth extends FormatLongWidth,
> {
formats: Partial<{
[format in FormatLongWidth]: string;
}> & {
[format in DefaultMatchWidth]: string;
};
defaultWidth: DefaultMatchWidth;
}
export declare function buildFormatLongFn<
DefaultMatchWidth extends FormatLongWidth,
>(args: BuildFormatLongFnArgs<DefaultMatchWidth>): FormatLongFn;

View File

@ -0,0 +1,8 @@
export function buildFormatLongFn(args) {
return (options = {}) => {
// TODO: Remove String()
const width = options.width ? String(options.width) : args.defaultWidth;
const format = args.formats[width] || args.formats[args.defaultWidth];
return format;
};
}

65
node_modules/date-fns/locale/_lib/buildLocalizeFn.cjs generated vendored Normal file
View File

@ -0,0 +1,65 @@
"use strict";
exports.buildLocalizeFn = buildLocalizeFn;
/**
* The localize function argument callback which allows to convert raw value to
* the actual type.
*
* @param value - The value to convert
*
* @returns The converted value
*/
/**
* The map of localized values for each width.
*/
/**
* The index type of the locale unit value. It types conversion of units of
* values that don't start at 0 (i.e. quarters).
*/
/**
* Converts the unit value to the tuple of values.
*/
/**
* The tuple of localized era values. The first element represents BC,
* the second element represents AD.
*/
/**
* The tuple of localized quarter values. The first element represents Q1.
*/
/**
* The tuple of localized day values. The first element represents Sunday.
*/
/**
* The tuple of localized month values. The first element represents January.
*/
function buildLocalizeFn(args) {
return (value, options) => {
const context = options?.context ? String(options.context) : "standalone";
let valuesArray;
if (context === "formatting" && args.formattingValues) {
const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
const width = options?.width ? String(options.width) : defaultWidth;
valuesArray =
args.formattingValues[width] || args.formattingValues[defaultWidth];
} else {
const defaultWidth = args.defaultWidth;
const width = options?.width ? String(options.width) : args.defaultWidth;
valuesArray = args.values[width] || args.values[defaultWidth];
}
const index = args.argumentCallback ? args.argumentCallback(value) : value;
// @ts-expect-error - For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it!
return valuesArray[index];
};
}

102
node_modules/date-fns/locale/_lib/buildLocalizeFn.d.cts generated vendored Normal file
View File

@ -0,0 +1,102 @@
import type { Day, Era, Month, Quarter } from "../../types.js";
import type {
LocaleDayPeriod,
LocaleUnitValue,
LocaleWidth,
LocalizeFn,
} from "../types.js";
export type BuildLocalizeFnArgs<
Value extends LocaleUnitValue,
ArgCallback extends LocalizeFnArgCallback<Value> | undefined,
> = {
values: LocalizePeriodValuesMap<Value>;
defaultWidth: LocaleWidth;
formattingValues?: LocalizePeriodValuesMap<Value>;
defaultFormattingWidth?: LocaleWidth;
} & (ArgCallback extends undefined
? {
argumentCallback?: undefined;
}
: {
argumentCallback: LocalizeFnArgCallback<Value>;
});
/**
* The localize function argument callback which allows to convert raw value to
* the actual type.
*
* @param value - The value to convert
*
* @returns The converted value
*/
export type LocalizeFnArgCallback<Value extends LocaleUnitValue | number> = (
value: Value,
) => LocalizeUnitIndex<Value>;
/**
* The map of localized values for each width.
*/
export type LocalizePeriodValuesMap<Value extends LocaleUnitValue> = {
[Pattern in LocaleWidth]?: LocalizeValues<Value>;
};
/**
* The index type of the locale unit value. It types conversion of units of
* values that don't start at 0 (i.e. quarters).
*/
export type LocalizeUnitIndex<Value extends LocaleUnitValue | number> =
Value extends LocaleUnitValue ? keyof LocalizeValues<Value> : number;
/**
* Converts the unit value to the tuple of values.
*/
export type LocalizeValues<Value extends LocaleUnitValue> =
Value extends LocaleDayPeriod
? Record<LocaleDayPeriod, string>
: Value extends Era
? LocalizeEraValues
: Value extends Quarter
? LocalizeQuarterValues
: Value extends Day
? LocalizeDayValues
: Value extends Month
? LocalizeMonthValues
: never;
/**
* The tuple of localized era values. The first element represents BC,
* the second element represents AD.
*/
export type LocalizeEraValues = readonly [string, string];
/**
* The tuple of localized quarter values. The first element represents Q1.
*/
export type LocalizeQuarterValues = readonly [string, string, string, string];
/**
* The tuple of localized day values. The first element represents Sunday.
*/
export type LocalizeDayValues = readonly [
string,
string,
string,
string,
string,
string,
string,
];
/**
* The tuple of localized month values. The first element represents January.
*/
export type LocalizeMonthValues = readonly [
string,
string,
string,
string,
string,
string,
string,
string,
string,
string,
string,
string,
];
export declare function buildLocalizeFn<
Value extends LocaleUnitValue,
ArgCallback extends LocalizeFnArgCallback<Value> | undefined,
>(args: BuildLocalizeFnArgs<Value, ArgCallback>): LocalizeFn<Value>;

102
node_modules/date-fns/locale/_lib/buildLocalizeFn.d.ts generated vendored Normal file
View File

@ -0,0 +1,102 @@
import type { Day, Era, Month, Quarter } from "../../types.js";
import type {
LocaleDayPeriod,
LocaleUnitValue,
LocaleWidth,
LocalizeFn,
} from "../types.js";
export type BuildLocalizeFnArgs<
Value extends LocaleUnitValue,
ArgCallback extends LocalizeFnArgCallback<Value> | undefined,
> = {
values: LocalizePeriodValuesMap<Value>;
defaultWidth: LocaleWidth;
formattingValues?: LocalizePeriodValuesMap<Value>;
defaultFormattingWidth?: LocaleWidth;
} & (ArgCallback extends undefined
? {
argumentCallback?: undefined;
}
: {
argumentCallback: LocalizeFnArgCallback<Value>;
});
/**
* The localize function argument callback which allows to convert raw value to
* the actual type.
*
* @param value - The value to convert
*
* @returns The converted value
*/
export type LocalizeFnArgCallback<Value extends LocaleUnitValue | number> = (
value: Value,
) => LocalizeUnitIndex<Value>;
/**
* The map of localized values for each width.
*/
export type LocalizePeriodValuesMap<Value extends LocaleUnitValue> = {
[Pattern in LocaleWidth]?: LocalizeValues<Value>;
};
/**
* The index type of the locale unit value. It types conversion of units of
* values that don't start at 0 (i.e. quarters).
*/
export type LocalizeUnitIndex<Value extends LocaleUnitValue | number> =
Value extends LocaleUnitValue ? keyof LocalizeValues<Value> : number;
/**
* Converts the unit value to the tuple of values.
*/
export type LocalizeValues<Value extends LocaleUnitValue> =
Value extends LocaleDayPeriod
? Record<LocaleDayPeriod, string>
: Value extends Era
? LocalizeEraValues
: Value extends Quarter
? LocalizeQuarterValues
: Value extends Day
? LocalizeDayValues
: Value extends Month
? LocalizeMonthValues
: never;
/**
* The tuple of localized era values. The first element represents BC,
* the second element represents AD.
*/
export type LocalizeEraValues = readonly [string, string];
/**
* The tuple of localized quarter values. The first element represents Q1.
*/
export type LocalizeQuarterValues = readonly [string, string, string, string];
/**
* The tuple of localized day values. The first element represents Sunday.
*/
export type LocalizeDayValues = readonly [
string,
string,
string,
string,
string,
string,
string,
];
/**
* The tuple of localized month values. The first element represents January.
*/
export type LocalizeMonthValues = readonly [
string,
string,
string,
string,
string,
string,
string,
string,
string,
string,
string,
string,
];
export declare function buildLocalizeFn<
Value extends LocaleUnitValue,
ArgCallback extends LocalizeFnArgCallback<Value> | undefined,
>(args: BuildLocalizeFnArgs<Value, ArgCallback>): LocalizeFn<Value>;

62
node_modules/date-fns/locale/_lib/buildLocalizeFn.js generated vendored Normal file
View File

@ -0,0 +1,62 @@
/**
* The localize function argument callback which allows to convert raw value to
* the actual type.
*
* @param value - The value to convert
*
* @returns The converted value
*/
/**
* The map of localized values for each width.
*/
/**
* The index type of the locale unit value. It types conversion of units of
* values that don't start at 0 (i.e. quarters).
*/
/**
* Converts the unit value to the tuple of values.
*/
/**
* The tuple of localized era values. The first element represents BC,
* the second element represents AD.
*/
/**
* The tuple of localized quarter values. The first element represents Q1.
*/
/**
* The tuple of localized day values. The first element represents Sunday.
*/
/**
* The tuple of localized month values. The first element represents January.
*/
export function buildLocalizeFn(args) {
return (value, options) => {
const context = options?.context ? String(options.context) : "standalone";
let valuesArray;
if (context === "formatting" && args.formattingValues) {
const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
const width = options?.width ? String(options.width) : defaultWidth;
valuesArray =
args.formattingValues[width] || args.formattingValues[defaultWidth];
} else {
const defaultWidth = args.defaultWidth;
const width = options?.width ? String(options.width) : args.defaultWidth;
valuesArray = args.values[width] || args.values[defaultWidth];
}
const index = args.argumentCallback ? args.argumentCallback(value) : value;
// @ts-expect-error - For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it!
return valuesArray[index];
};
}

60
node_modules/date-fns/locale/_lib/buildMatchFn.cjs generated vendored Normal file
View File

@ -0,0 +1,60 @@
"use strict";
exports.buildMatchFn = buildMatchFn;
function buildMatchFn(args) {
return (string, options = {}) => {
const width = options.width;
const matchPattern =
(width && args.matchPatterns[width]) ||
args.matchPatterns[args.defaultMatchWidth];
const matchResult = string.match(matchPattern);
if (!matchResult) {
return null;
}
const matchedString = matchResult[0];
const parsePatterns =
(width && args.parsePatterns[width]) ||
args.parsePatterns[args.defaultParseWidth];
const key = Array.isArray(parsePatterns)
? findIndex(parsePatterns, (pattern) => pattern.test(matchedString))
: // [TODO] -- I challenge you to fix the type
findKey(parsePatterns, (pattern) => pattern.test(matchedString));
let value;
value = args.valueCallback ? args.valueCallback(key) : key;
value = options.valueCallback
? // [TODO] -- I challenge you to fix the type
options.valueCallback(value)
: value;
const rest = string.slice(matchedString.length);
return { value, rest };
};
}
function findKey(object, predicate) {
for (const key in object) {
if (
Object.prototype.hasOwnProperty.call(object, key) &&
predicate(object[key])
) {
return key;
}
}
return undefined;
}
function findIndex(array, predicate) {
for (let key = 0; key < array.length; key++) {
if (predicate(array[key])) {
return key;
}
}
return undefined;
}

67
node_modules/date-fns/locale/_lib/buildMatchFn.d.cts generated vendored Normal file
View File

@ -0,0 +1,67 @@
import type { Quarter, Era, Day, Month } from "../../types.js";
import type {
LocaleUnitValue,
LocaleWidth,
LocaleDayPeriod,
MatchFn,
MatchValueCallback,
} from "../types.js";
export interface BuildMatchFnArgs<
Result extends LocaleUnitValue,
DefaultMatchWidth extends LocaleWidth,
DefaultParseWidth extends LocaleWidth,
> {
matchPatterns: BuildMatchFnMatchPatterns<DefaultMatchWidth>;
defaultMatchWidth: DefaultMatchWidth;
parsePatterns: BuildMatchFnParsePatterns<Result, DefaultParseWidth>;
defaultParseWidth: DefaultParseWidth;
valueCallback?: MatchValueCallback<
Result extends LocaleDayPeriod ? string : number,
Result
>;
}
export type BuildMatchFnMatchPatterns<DefaultWidth extends LocaleWidth> = {
[Width in LocaleWidth]?: RegExp;
} & {
[Width in DefaultWidth]: RegExp;
};
export type BuildMatchFnParsePatterns<
Value extends LocaleUnitValue,
DefaultWidth extends LocaleWidth,
> = {
[Width in LocaleWidth]?: ParsePattern<Value>;
} & {
[Width in DefaultWidth]: ParsePattern<Value>;
};
export type ParsePattern<Value extends LocaleUnitValue> =
Value extends LocaleDayPeriod
? Record<LocaleDayPeriod, RegExp>
: Value extends Quarter
? readonly [RegExp, RegExp, RegExp, RegExp]
: Value extends Era
? readonly [RegExp, RegExp]
: Value extends Day
? readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]
: Value extends Month
? readonly [
RegExp,
RegExp,
RegExp,
RegExp,
RegExp,
RegExp,
RegExp,
RegExp,
RegExp,
RegExp,
RegExp,
RegExp,
]
: never;
export declare function buildMatchFn<
Value extends LocaleUnitValue,
DefaultMatchWidth extends LocaleWidth,
DefaultParseWidth extends LocaleWidth,
>(
args: BuildMatchFnArgs<Value, DefaultMatchWidth, DefaultParseWidth>,
): MatchFn<Value>;

67
node_modules/date-fns/locale/_lib/buildMatchFn.d.ts generated vendored Normal file
View File

@ -0,0 +1,67 @@
import type { Quarter, Era, Day, Month } from "../../types.js";
import type {
LocaleUnitValue,
LocaleWidth,
LocaleDayPeriod,
MatchFn,
MatchValueCallback,
} from "../types.js";
export interface BuildMatchFnArgs<
Result extends LocaleUnitValue,
DefaultMatchWidth extends LocaleWidth,
DefaultParseWidth extends LocaleWidth,
> {
matchPatterns: BuildMatchFnMatchPatterns<DefaultMatchWidth>;
defaultMatchWidth: DefaultMatchWidth;
parsePatterns: BuildMatchFnParsePatterns<Result, DefaultParseWidth>;
defaultParseWidth: DefaultParseWidth;
valueCallback?: MatchValueCallback<
Result extends LocaleDayPeriod ? string : number,
Result
>;
}
export type BuildMatchFnMatchPatterns<DefaultWidth extends LocaleWidth> = {
[Width in LocaleWidth]?: RegExp;
} & {
[Width in DefaultWidth]: RegExp;
};
export type BuildMatchFnParsePatterns<
Value extends LocaleUnitValue,
DefaultWidth extends LocaleWidth,
> = {
[Width in LocaleWidth]?: ParsePattern<Value>;
} & {
[Width in DefaultWidth]: ParsePattern<Value>;
};
export type ParsePattern<Value extends LocaleUnitValue> =
Value extends LocaleDayPeriod
? Record<LocaleDayPeriod, RegExp>
: Value extends Quarter
? readonly [RegExp, RegExp, RegExp, RegExp]
: Value extends Era
? readonly [RegExp, RegExp]
: Value extends Day
? readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp]
: Value extends Month
? readonly [
RegExp,
RegExp,
RegExp,
RegExp,
RegExp,
RegExp,
RegExp,
RegExp,
RegExp,
RegExp,
RegExp,
RegExp,
]
: never;
export declare function buildMatchFn<
Value extends LocaleUnitValue,
DefaultMatchWidth extends LocaleWidth,
DefaultParseWidth extends LocaleWidth,
>(
args: BuildMatchFnArgs<Value, DefaultMatchWidth, DefaultParseWidth>,
): MatchFn<Value>;

57
node_modules/date-fns/locale/_lib/buildMatchFn.js generated vendored Normal file
View File

@ -0,0 +1,57 @@
export function buildMatchFn(args) {
return (string, options = {}) => {
const width = options.width;
const matchPattern =
(width && args.matchPatterns[width]) ||
args.matchPatterns[args.defaultMatchWidth];
const matchResult = string.match(matchPattern);
if (!matchResult) {
return null;
}
const matchedString = matchResult[0];
const parsePatterns =
(width && args.parsePatterns[width]) ||
args.parsePatterns[args.defaultParseWidth];
const key = Array.isArray(parsePatterns)
? findIndex(parsePatterns, (pattern) => pattern.test(matchedString))
: // [TODO] -- I challenge you to fix the type
findKey(parsePatterns, (pattern) => pattern.test(matchedString));
let value;
value = args.valueCallback ? args.valueCallback(key) : key;
value = options.valueCallback
? // [TODO] -- I challenge you to fix the type
options.valueCallback(value)
: value;
const rest = string.slice(matchedString.length);
return { value, rest };
};
}
function findKey(object, predicate) {
for (const key in object) {
if (
Object.prototype.hasOwnProperty.call(object, key) &&
predicate(object[key])
) {
return key;
}
}
return undefined;
}
function findIndex(array, predicate) {
for (let key = 0; key < array.length; key++) {
if (predicate(array[key])) {
return key;
}
}
return undefined;
}

View File

@ -0,0 +1,23 @@
"use strict";
exports.buildMatchPatternFn = buildMatchPatternFn;
function buildMatchPatternFn(args) {
return (string, options = {}) => {
const matchResult = string.match(args.matchPattern);
if (!matchResult) return null;
const matchedString = matchResult[0];
const parseResult = string.match(args.parsePattern);
if (!parseResult) return null;
let value = args.valueCallback
? args.valueCallback(parseResult[0])
: parseResult[0];
// [TODO] I challenge you to fix the type
value = options.valueCallback ? options.valueCallback(value) : value;
const rest = string.slice(matchedString.length);
return { value, rest };
};
}

View File

@ -0,0 +1,9 @@
import type { MatchFn, MatchValueCallback } from "../types.js";
export interface BuildMatchPatternFnArgs<Result> {
matchPattern: RegExp;
parsePattern: RegExp;
valueCallback?: MatchValueCallback<string, Result>;
}
export declare function buildMatchPatternFn<Result>(
args: BuildMatchPatternFnArgs<Result>,
): MatchFn<Result>;

View File

@ -0,0 +1,9 @@
import type { MatchFn, MatchValueCallback } from "../types.js";
export interface BuildMatchPatternFnArgs<Result> {
matchPattern: RegExp;
parsePattern: RegExp;
valueCallback?: MatchValueCallback<string, Result>;
}
export declare function buildMatchPatternFn<Result>(
args: BuildMatchPatternFnArgs<Result>,
): MatchFn<Result>;

View File

@ -0,0 +1,20 @@
export function buildMatchPatternFn(args) {
return (string, options = {}) => {
const matchResult = string.match(args.matchPattern);
if (!matchResult) return null;
const matchedString = matchResult[0];
const parseResult = string.match(args.parsePattern);
if (!parseResult) return null;
let value = args.valueCallback
? args.valueCallback(parseResult[0])
: parseResult[0];
// [TODO] I challenge you to fix the type
value = options.valueCallback ? options.valueCallback(value) : value;
const rest = string.slice(matchedString.length);
return { value, rest };
};
}