Files
recap/node_modules/@start9labs/start-sdk/base/lib/util/regexes.d.ts
T

60 lines
2.8 KiB
TypeScript

/**
* A wrapper around RegExp that supports composition into larger patterns.
* Provides helpers to produce anchored (full-match), grouped (sub-expression),
* and unanchored (contains) regex source strings.
*
* @example
* ```ts
* const digit = new ComposableRegex(/\d+/)
* digit.matches() // "^\\d+$"
* digit.contains() // "\\d+"
* digit.asExpr() // "(\\d+)"
* ```
*/
export declare class ComposableRegex {
readonly regex: RegExp;
constructor(regex: RegExp | string);
/** Returns the regex source wrapped in a capturing group, suitable for embedding in a larger expression. */
asExpr(): string;
/** Returns the regex source anchored with `^...$` for full-string matching. */
matches(): string;
/** Returns the raw regex source string for substring/containment matching. */
contains(): string;
}
/**
* Escapes all regex special characters in a string so it can be used as a literal in a RegExp.
* @param str - The string to escape
* @returns The escaped string safe for regex interpolation
*/
export declare const escapeLiteral: (str: string) => string;
/** Composable regex for matching IPv6 addresses (all standard forms including `::` shorthand). */
export declare const ipv6: ComposableRegex;
/** Composable regex for matching IPv4 addresses in dotted-decimal notation. */
export declare const ipv4: ComposableRegex;
/** Composable regex for matching RFC-compliant hostnames. */
export declare const hostname: ComposableRegex;
/** Composable regex for matching `.local` mDNS hostnames. */
export declare const localHostname: ComposableRegex;
/** Composable regex for matching HTTP/HTTPS URLs. */
export declare const url: ComposableRegex;
/** Composable regex for matching `.local` URLs (mDNS/LAN). */
export declare const localUrl: ComposableRegex;
/** Composable regex for matching printable ASCII characters (space through tilde). */
export declare const ascii: ComposableRegex;
/** Composable regex for matching fully qualified domain names. */
export declare const domain: ComposableRegex;
/** Composable regex for matching email addresses. */
export declare const email: ComposableRegex;
/** Composable regex for matching email addresses optionally preceded by a display name (e.g. `"Name <email>"`). */
export declare const emailWithName: ComposableRegex;
/** Composable regex for matching base64-encoded strings (no whitespace). */
export declare const base64: ComposableRegex;
/** Composable regex for matching base64-encoded strings that may contain interspersed whitespace. */
export declare const base64Whitespace: ComposableRegex;
/**
* Creates a composable regex for matching PEM-encoded blocks with the given label.
* @param label - The PEM label (e.g. `"CERTIFICATE"`, `"RSA PRIVATE KEY"`)
* @returns A ComposableRegex matching `-----BEGIN <label>-----...-----END <label>-----`
*/
export declare const pem: (label: string) => ComposableRegex;