UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.

57 lines (56 loc) • 3.15 kB
import type { Numeric } from '../types/index'; import type { $TimeZoneIdentifier, ClockTime, DateLike, TimeWithUnit, TimeZoneIdNative, UTCOffset } from './types'; /** * * Checks if the provided value is a valid time string in "HH:MM" format. * * @param value - The value to check. * @returns `true` if the value is a valid time string, `false` otherwise. */ export declare function isValidTime(value: unknown): value is ClockTime; /** * * Checks if the provided value is a valid `UTCOffset` (e.g. `UTC-01:30`). * * @param value - The value to check. * @returns `true` if the value is a valid utc offset, `false` otherwise. */ export declare function isValidUTCOffset(value: unknown): value is UTCOffset; /** * * Validates whether the provided value is a recognized IANA time zone identifier (excluding `"Factory"`), based on the {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones IANA TZ Database}. * * @remarks * - Relies on a large constant map of time zone identifiers, which can increase bundle size in browser environments. Matches against `597` identifiers. * - Prefer {@link isNativeTimeZoneId} when you want a lightweight, native-only validation approach. Matches against `418` identifiers. * * @param value Time zone identifier to validate. * @returns `true` if the value is a valid IANA time zone identifier, otherwise `false`. */ export declare function isValidTimeZoneId(value: unknown): value is $TimeZoneIdentifier; /** * * Validates whether the provided value is a supported time zone identifier using the native JavaScript API (`Intl.supportedValuesOf('timeZone')`). * * @remarks * - Uses only native {@link Intl} capabilities—minimal code footprint, highly performant. Matches against `418` identifiers. * - Prefer {@link isValidTimeZoneId} when validation must align strictly with the full * {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones IANA TZ Database}. Matches against `597` identifiers. * * @param value Time zone identifier to validate. * @returns `true` if the value is a valid native JS-supported time zone identifier, otherwise `false`. */ export declare function isNativeTimeZoneId(value: unknown): value is TimeZoneIdNative; /** * * Checks if the year is a leap year. * * - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400. * - For example, 2000 and 2400 are leap years, but 1900 and 2100 are not. * @param year The year to check. * @returns `true` if the year is a leap year, `false` otherwise. */ export declare function isLeapYear(year: Numeric): boolean; /** * * Checks if a value is a date-like object from `Date`, `Chronos`, `Moment.js`, `Day.js`, `Luxon`, `JS-Joda`, or `Temporal` * @param value Value to check if it is date-like object. * @returns `true` if the value is date-like object, otherwise `false`. */ export declare function isDateLike(value: unknown): value is DateLike; /** Checks if a value represents time value (number) with different forms of {@link TimeWithUnit units} */ export declare function isTimeWithUnit(value: unknown): value is TimeWithUnit;