feat: init
This commit is contained in:
94
node_modules/compatx/dist/index.d.mts
generated
vendored
Normal file
94
node_modules/compatx/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* Known platform names
|
||||
*/
|
||||
declare const platforms: readonly ["aws", "azure", "cloudflare", "deno", "firebase", "netlify", "vercel"];
|
||||
/**
|
||||
* Known platform name
|
||||
*/
|
||||
type PlatformName = (typeof platforms)[number] | (string & {});
|
||||
|
||||
/**
|
||||
* Normalize the compatibility dates from input config and defaults.
|
||||
*/
|
||||
declare function resolveCompatibilityDates(input?: CompatibilityDateSpec | undefined, defaults?: CompatibilityDateSpec): CompatibilityDates;
|
||||
/**
|
||||
* Resolve compatibility dates with environment variables as defaults.
|
||||
*
|
||||
* Environment variable name format is `COMPATIBILITY_DATE` for default and `COMPATIBILITY_DATE_<PLATFORM>` for specific platforms.
|
||||
*/
|
||||
declare function resolveCompatibilityDatesFromEnv(overridesInput?: CompatibilityDateSpec | undefined): CompatibilityDates;
|
||||
/**
|
||||
* Format compatibility date spec to a string
|
||||
*/
|
||||
declare function formatCompatibilityDate(input: CompatibilityDateSpec): string;
|
||||
/**
|
||||
* Format a date to a `YYYY-MM-DD` string
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* formatDateString(new Date("2021/01/01")) // "2021-01-01"
|
||||
* ```
|
||||
*/
|
||||
declare function formatDate(date: Date | string): DateString;
|
||||
type Year = `${number}${number}${number}${number}`;
|
||||
type Month = `${"0" | "1"}${number}`;
|
||||
type Day = `${"0" | "1" | "2" | "3"}${number}`;
|
||||
/**
|
||||
* Typed date string in `YYYY-MM-DD` format
|
||||
*
|
||||
* Empty string is used to represent an "unspecified" date.
|
||||
*
|
||||
* "latest" is used to represent the latest date available (date of today).
|
||||
*/
|
||||
type DateString = "" | "latest" | `${Year}-${Month}-${Day}`;
|
||||
/**
|
||||
* Last known compatibility dates for platforms
|
||||
*
|
||||
* @example
|
||||
* {
|
||||
* "default": "2024-01-01",
|
||||
* "cloudflare": "2024-03-01",
|
||||
* }
|
||||
*/
|
||||
type CompatibilityDates = {
|
||||
/**
|
||||
* Default compatibility date for all unspecified platforms (required)
|
||||
*/
|
||||
default: DateString;
|
||||
} & Partial<Record<PlatformName, DateString>>;
|
||||
/**
|
||||
* Last known compatibility date for the used platform
|
||||
*/
|
||||
type CompatibilityDateSpec = DateString | Partial<CompatibilityDates>;
|
||||
|
||||
/**
|
||||
* Get compatibility updates applicable for the user given platform and date range.
|
||||
*/
|
||||
declare function getCompatibilityUpdates(allUpdates: CompatibilityUpdates, compatibilityDate: CompatibilityDateSpec): CompatibilityUpdates;
|
||||
/**
|
||||
* Get compatibility changes between two dates.
|
||||
*/
|
||||
declare function getCompatibilityChanges(allUpdates: CompatibilityUpdates, compatibilityDate1: CompatibilityDateSpec, compatibilityDate2: CompatibilityDateSpec): {
|
||||
added: CompatibilityUpdates;
|
||||
removed: CompatibilityUpdates;
|
||||
};
|
||||
/**
|
||||
* Compatibility updateinformation.
|
||||
*/
|
||||
interface CompatibilityUpdate {
|
||||
/** Applicable platform name */
|
||||
platform: PlatformName;
|
||||
/** Description */
|
||||
description: string;
|
||||
/** URL for more information */
|
||||
url?: string;
|
||||
/** The starting date of updatebeing effective */
|
||||
from?: DateString;
|
||||
/** The ending date until the updateis effective */
|
||||
until?: DateString;
|
||||
}
|
||||
type CompatibilityUpdates = CompatibilityUpdate[];
|
||||
|
||||
export { formatCompatibilityDate, formatDate, getCompatibilityChanges, getCompatibilityUpdates, platforms, resolveCompatibilityDates, resolveCompatibilityDatesFromEnv };
|
||||
export type { CompatibilityDateSpec, CompatibilityDates, CompatibilityUpdate, CompatibilityUpdates, DateString, PlatformName };
|
||||
103
node_modules/compatx/dist/index.mjs
generated
vendored
Normal file
103
node_modules/compatx/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
const platforms = [
|
||||
"aws",
|
||||
"azure",
|
||||
"cloudflare",
|
||||
"deno",
|
||||
"firebase",
|
||||
"netlify",
|
||||
"vercel"
|
||||
];
|
||||
|
||||
function resolveCompatibilityDates(input, defaults) {
|
||||
const dates = {
|
||||
default: ""
|
||||
};
|
||||
const _defaults = typeof defaults === "string" ? { default: defaults } : defaults || {};
|
||||
for (const [key, value] of Object.entries(_defaults)) {
|
||||
if (value) {
|
||||
dates[key] = formatDate(value);
|
||||
}
|
||||
}
|
||||
const _input = typeof input === "string" ? { default: input } : input || {};
|
||||
for (const [key, value] of Object.entries(_input)) {
|
||||
if (value) {
|
||||
dates[key] = formatDate(value);
|
||||
}
|
||||
}
|
||||
dates.default = formatDate(dates.default || "") || Object.values(dates).sort().pop() || "";
|
||||
return dates;
|
||||
}
|
||||
function resolveCompatibilityDatesFromEnv(overridesInput) {
|
||||
const defaults = {
|
||||
default: process.env.COMPATIBILITY_DATE ? formatDate(process.env.COMPATIBILITY_DATE) : void 0
|
||||
};
|
||||
for (const platform of platforms) {
|
||||
const envName = `COMPATIBILITY_DATE_${platform.toUpperCase()}`;
|
||||
const env = process.env[envName];
|
||||
if (env) {
|
||||
defaults[platform] = formatDate(env);
|
||||
}
|
||||
}
|
||||
return resolveCompatibilityDates(overridesInput, defaults);
|
||||
}
|
||||
function formatCompatibilityDate(input) {
|
||||
const dates = resolveCompatibilityDates(input);
|
||||
const entries = Object.entries(dates);
|
||||
if (entries.length === 0) {
|
||||
return "-";
|
||||
}
|
||||
return [
|
||||
`${dates["default"]}`,
|
||||
...Object.entries(dates).filter(
|
||||
([key, value]) => key !== "default" && value && value !== dates["default"]
|
||||
).map(([key, value]) => `${key}: ${value}`)
|
||||
].join(", ");
|
||||
}
|
||||
function formatDate(date) {
|
||||
const d = normalizeDate(date);
|
||||
if (Number.isNaN(d.getDate())) {
|
||||
return "";
|
||||
}
|
||||
const year = d.getFullYear().toString();
|
||||
const month = (d.getMonth() + 1).toString().padStart(2, "0");
|
||||
const day = d.getDate().toString().padStart(2, "0");
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
function normalizeDate(date) {
|
||||
if (date instanceof Date) {
|
||||
return date;
|
||||
}
|
||||
if (date === "latest") {
|
||||
return /* @__PURE__ */ new Date();
|
||||
}
|
||||
return new Date(date);
|
||||
}
|
||||
|
||||
function getCompatibilityUpdates(allUpdates, compatibilityDate) {
|
||||
const _date = resolveCompatibilityDates(compatibilityDate);
|
||||
return allUpdates.filter((change) => {
|
||||
const _platformDate = _date[change.platform] || _date.default;
|
||||
if (!_platformDate) {
|
||||
return false;
|
||||
}
|
||||
if (change.from && _platformDate < change.from) {
|
||||
return false;
|
||||
}
|
||||
if (change.until && _platformDate > change.until) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
function getCompatibilityChanges(allUpdates, compatibilityDate1, compatibilityDate2) {
|
||||
const updates1 = getCompatibilityUpdates(allUpdates, compatibilityDate1);
|
||||
const updates2 = getCompatibilityUpdates(allUpdates, compatibilityDate2);
|
||||
const added = updates2.filter((update) => !updates1.includes(update));
|
||||
const removed = updates1.filter((update) => !updates2.includes(update));
|
||||
return {
|
||||
added,
|
||||
removed
|
||||
};
|
||||
}
|
||||
|
||||
export { formatCompatibilityDate, formatDate, getCompatibilityChanges, getCompatibilityUpdates, platforms, resolveCompatibilityDates, resolveCompatibilityDatesFromEnv };
|
||||
Reference in New Issue
Block a user