import { AuthDateConstructor } from '../types.js'; /** * Normalize a possibly-sync function into a Promise. * * @typeParam T - The return type of the executor. * * @param executor - A function that may return `T` or `Promise`, and may throw. * @returns A `Promise` that resolves/rejects to the executor's outcome. * * @remarks * - Synchronously thrown errors are converted into a rejected Promise. * - Already-Promise returns are awaited via `Promise.resolve(...)`. * * @example * ```ts * await execPromise(() => 42); // resolves 42 * await execPromise(async () => 42); // resolves 42 * await execPromise(() => { throw e }); // rejects with e * ``` */ export declare function execPromise(executor: () => T | Promise): Promise; /** * Deeply clone simple JSON-like values with special handling for `Date`. * * @typeParam T - Value type. * * @param v - The value to clone. * @returns A deep copy of `v` for supported shapes; otherwise returns `v` as-is. * * @remarks * - Clones: * - `null`/`undefined` → returned as-is. * - `Date` → new `Date(valueOf)`. * - Arrays → element-wise deep clone. * - Plain objects (prototype exactly `Object.prototype`) → property-wise deep clone. * - Non-plain objects (e.g., classes, Maps, Sets, RegExps, Buffers) are **returned as-is**. * - Functions and accessors are not copied. * - This is not a general-purpose deep clone; it is designed for config/POJO data. */ export declare function cloneDeep(v: T): T; /** * Clone a value through JSON serialization to mirror Firebase's network * boundary for request payloads. */ export declare function jsonRoundTrip(v: T): T; /** * Convert a `Date` or epoch seconds into a numeric seconds since epoch, preserving `undefined`. * * @param value - A `Date`, epoch milliseconds `number`, or `undefined`. * @returns Epoch milliseconds if provided, otherwise `undefined`. * * @example * ```ts * valueOfDate(new Date(0)) // 0 * valueOfDate(1730000000000) // 1730000000000 * valueOfDate(undefined) // undefined * ``` */ export declare function epochSeconds(value: AuthDateConstructor): number; /** * Generates a UTC Date string from an `AuthDateConstructor`. */ export declare function utcDate(value: AuthDateConstructor): string; /** * Converts a duration from milliseconds to whole seconds. * * @param {number} millis - The duration in milliseconds. * @returns {number} The duration in whole seconds, truncated (not rounded). * * @example * millisToSeconds(1234); // returns 1 * millisToSeconds(2500); // returns 2 */ export declare function millisToSeconds(millis: number): number; export declare function secondsToMillis(millis: number): number; /** * Parses an ISO date and returns the date expressed as seconds elapsed since the Unix epoch. */ export declare function isoDateToEpoch(iso: string | null | undefined): number | undefined; /** * Return a trimmed string or a supplied default when empty/whitespace/undefined. * * @param s - Input string (possibly `undefined`). * @param defaultValue - Fallback to use when `s` is missing or blank. * @returns `s.trim()` if non-empty; otherwise `defaultValue`. * * @example * ```ts * defaultString(' hi ', 'x') // 'hi' * defaultString(' ', 'x') // 'x' * defaultString(undefined, 'x') // 'x' * ``` */ export declare function defaultString(s: string | undefined, defaultValue: string): string; /** * Returns a `Promise` that resolves asynchronously with latency. */ export declare function resolvePromise(): Promise; /** * Returns a `Promise` that resolves `value` asynchronously with latency. */ export declare function resolvePromise(value: T, delay?: number): Promise; /** * Returns a `Promise` that rejects asynchronously using `queueMicrotask`. */ export declare function rejectPromise(reason: unknown): Promise; /** * Assigns the `value` to `target` if value is defined and not an empty string and the target property * is not already defined. */ export declare function assignDefer(target: T, key: K, value: T[K] | undefined): void; /** * Assigns the `value` to `target` if value is defined and not an empty string. * * @returns `true` if the assignment occurred; otherwise `false`. */ export declare function assignIf(target: T, key: K, value: T[K] | undefined | null): boolean; /** * Assigns the `value` to `target` if value is defined and not an empty string, * or deletes the * * @returns `true` if the assignment or deletion occurred; otherwise `false`. */ export declare function assignIfOrDeleteNull(target: T, key: K, value: T[K] | undefined | null): boolean; /** * Checks whether the provided value appears to be a valid email address. * * @remarks * This helper performs a pragmatic validation suitable for most application-level * checks. It does **not** attempt to fully implement RFC 5322, but it enforces: * * - Non-empty value after trimming. * - No spaces. * - At most 320 characters in total. * - Exactly one `@` symbol. * - Non-empty local part and domain. * - Domain contains at least one `.` (for example, `example.com`). * - Domain consists of dot-separated labels using letters, digits, or hyphens, * with no empty labels and no labels starting or ending with `-`. * * `null` and `undefined` are treated as invalid and return `false`. * * @param email - Email address to validate. * @returns `true` if the value looks like a valid email address; otherwise `false`. * * @example * ```ts * isValidEmail('alice@example.com'); // true * isValidEmail('alice.smith@sub.example.com'); // true * isValidEmail('not-an-email'); // false * isValidEmail('foo@bar'); // false * isValidEmail(null); // false * ``` */ export declare function isValidEmail(email: string | null | undefined): boolean; /** * Tests whether a string is a valid E.164-formatted phone number. * * @remarks * E.164 numbers: * * - Start with a `'+'` sign. * - Are followed by a country code and subscriber number. * - Contain only digits after the `'+'`. * - Have a maximum of 15 digits in total. * - Do not start with a leading zero after the `'+'` (i.e. country code * must be `1–9`). * * This function only validates the **format** of the number. It does not * check whether the number is actually assigned or reachable. * * `null` and `undefined` are treated as invalid and return `false`. * * @param phoneNumber - Phone number to validate. * @returns `true` if the value is a syntactically valid E.164 number; otherwise `false`. * * @example * ```ts * isValidE164Phone('+15551234567'); // true * isValidE164Phone('+64211234567'); // true (NZ mobile example) * isValidE164Phone('5551234567'); // false (missing '+') * isValidE164Phone('+0123456789'); // false (country code cannot start with 0) * isValidE164Phone(null); // false * ``` */ export declare function isValidE164Phone(phoneNumber: string | null | undefined): boolean; //# sourceMappingURL=util.d.ts.map