UNPKG

@northguild/gmt

Version:

Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.

34 lines (33 loc) • 1.13 kB
// src/internal/validatedZones.ts /** Ids that passed both `isValidTimeZone` checks. Whether an id names a zone is fixed by the host data. */ const validatedZones = /* @__PURE__ */ new Set(); /** Past this many ids the set clears. */ const MAX_VALIDATED_ZONES = 1024; /** * Whether this id already passed `isValidTimeZone`. * * @param timeZone the identifier * @returns `true` for an id remembered as valid * * @example isRememberedZone("Europe/London") // false until `rememberZone("Europe/London")` */ function isRememberedZone(timeZone) { return validatedZones.has(timeZone); } /** * Remember an id that passed. Only a pass is stored, so hostile strings cannot grow the set; * past 1,024 ids the set clears. * * @param timeZone the identifier that passed * * @example rememberZone("Europe/London") // stores it */ function rememberZone(timeZone) { if (validatedZones.size >= MAX_VALIDATED_ZONES) validatedZones.clear(); validatedZones.add(timeZone); } /** Test seam: forget every remembered id. */ function clearValidatedZones() { validatedZones.clear(); } export { clearValidatedZones, isRememberedZone, rememberZone };