UNPKG

nhb-toolbox

Version:

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

89 lines (88 loc) 3.92 kB
import type { UUID, UUIDVersion } from '../hash/types'; /** * * Type guard to check if a value is a valid email string. * @param value - The value to check. * @returns `true` if the value is a valid email, otherwise `false`. */ export declare function isEmail(value: unknown): value is string; /** * * Type guard to check if a value is an array of valid email strings. * @param value - The value to check. * @returns `true` if the value is an array of valid email strings, otherwise `false`. */ export declare function isEmailArray(value: unknown): value is string[]; /** * * Type guard to check if a value is a valid date string. * @param value - The value to check. * @returns `true` if the value is a valid date string, otherwise `false`. */ export declare function isDateString(value: unknown): value is string; /** * * Type guard to check if a value is a valid UUID (`RFC4122` `v1`-`v8`). * @param value - The value to check. * @returns `true` if the value matches standard UUID pattern, otherwise `false`. */ export declare function isUUID(value: unknown): value is UUID<UUIDVersion>; /** * * Type guard to check if the code is running in a browser environment. * @returns `true` if the code is running in a browser, otherwise `false`. */ export declare function isBrowser(): boolean; /** * * Type guard to check if the code is running in a Node.js environment. * @returns `true` if the code is running in Node.js, otherwise `false`. */ export declare function isNode(): boolean; /** * * Type guard to check if a value is a valid URL. * @param value - The value to check. * @returns `true` if the value is a valid URL, otherwise `false`. */ export declare function isURL(value: unknown): value is string; /** * * Type guard to check if a value is a valid Base64 encoded string. * @param value - The value to check. * @returns `true` if the value is a valid Base64 string, otherwise `false`. */ export declare function isBase64(value: unknown): value is string; /** * * Type guard to check if a value is a valid hexadecimal byte sequence. * @param value - The value to check, spaced between bytes or un-spaced. * @returns `true` if the value is a valid hexadecimal byte sequence, otherwise `false`. */ export declare function isHexString(value: unknown): value is string; /** * * Type guard to check if a value is a valid binary byte sequence. * @param value - The value to check, spaced between bytes or un-spaced. * @returns `true` if the value is a valid binary byte sequence, otherwise `false`. */ export declare function isBinaryString(value: unknown): value is string; /** * * Type guard to check if a value is a valid phone number. * @param value - The value to check. * @returns `true` if the value is a valid phone number, otherwise `false`. */ export declare function isPhoneNumber(value: unknown): value is string; /** * * Type guard to check if a value is a valid IP address (IPv4 or IPv6). * @param value - The value to check. * @returns `true` if the value is a valid IP address, otherwise `false`. */ export declare function isIPAddress(value: unknown): value is string; /** * * Type guard to check if the current environment matches a given string. * @param env - The expected environment (e.g., "production", "development"). * @returns `true` if the value equals to `process.env.NODE_ENV`, otherwise `false`. */ export declare function isEnvironment(env: string): boolean; /** * * Type guard to check if a value is a string representing a finite number. * * @remarks * - Accepts strings like: `"42"`, `" -5.5 "`, `"0.123"`, `"-0"`, `"1e5"`. * - Rejects strings like: `"NaN"`, `"Infinity"`, `"-Infinity"`, `"abc"`, `""`, `"42abc"`. * * @param value - The value to test. * @returns `true` if the value is a string that fully represents a finite number. */ export declare function isNumericString(value: unknown): value is `${number}`;