UNPKG

@bufbuild/protovalidate

Version:

Protocol Buffer Validation for ECMAScript

154 lines (153 loc) 5.99 kB
import { type CelResult } from "@bufbuild/cel"; /** * Returns true if the value is infinite, optionally limit to positive or * negative infinity. */ export declare function isInf(val: number, sign?: number | bigint): boolean; /** * Returns true if the string is an IPv4 or IPv6 address, optionally limited to * a specific version. * * Version 0 means either 4 or 6. Passing a version other than 0, 4, or 6 always * returns false. * * IPv4 addresses are expected in the dotted decimal format, for example "192.168.5.21". * IPv6 addresses are expected in their text representation, for example "::1", * or "2001:0DB8:ABCD:0012::0". * * Both formats are well-defined in the internet standard RFC 3986. Zone * identifiers for IPv6 addresses (for example "fe80::a%en1") are supported. */ export declare function isIp(str: string, version?: number | bigint): boolean; /** * Returns true if the string is a valid IP with prefix length, optionally * limited to a specific version (v4 or v6), and optionally requiring the host * portion to be all zeros. * * An address prefix divides an IP address into a network portion, and a host * portion. The prefix length specifies how many bits the network portion has. * For example, the IPv6 prefix "2001:db8:abcd:0012::0/64" designates the * left-most 64 bits as the network prefix. The range of the network is 2**64 * addresses, from 2001:db8:abcd:0012::0 to 2001:db8:abcd:0012:ffff:ffff:ffff:ffff. * * An address prefix may include a specific host address, for example * "2001:db8:abcd:0012::1f/64". With strict = true, this is not permitted. The * host portion must be all zeros, as in "2001:db8:abcd:0012::0/64". * * The same principle applies to IPv4 addresses. "192.168.1.0/24" designates * the first 24 bits of the 32-bit IPv4 as the network prefix. */ export declare function isIpPrefix(str: string, version?: number | bigint, strict?: boolean): boolean; export declare class Ipv4 { readonly str: string; i: number; readonly l: number; readonly octets: number[]; prefixLen: number; constructor(str: string); getBits(): number; isPrefixOnly(): boolean; address(): boolean; addressPrefix(): boolean; prefixLength(): boolean; addressPart(): boolean; decOctet(): boolean; digit(): boolean; take(char: string): boolean; } export declare class Ipv6 { readonly str: string; i: number; readonly l: number; readonly pieces: number[]; doubleColonAt: number; doubleColonSeen: boolean; dottedRaw: string; dottedAddr: Ipv4 | undefined; zoneIdFound: boolean; prefixLen: number; constructor(str: string); getBits(): [number, number, number, number]; isPrefixOnly(): boolean; address(): boolean; addressPrefix(): boolean; prefixLength(): boolean; addressPart(): boolean; zoneId(): boolean; dotted(): boolean; h16(): boolean | "error"; hexdig(): boolean; digit(): boolean; take(char: string): boolean; } /** * Returns true if the string is a valid hostname, for example "foo.example.com". * * A valid hostname follows the rules below: * - The name consists of one or more labels, separated by a dot ("."). * - Each label can be 1 to 63 alphanumeric characters. * - A label can contain hyphens ("-"), but must not start or end with a hyphen. * - The right-most label must not be digits only. * - The name can have a trailing dot, for example "foo.example.com.". * - The name can be 253 characters at most, excluding the optional trailing dot. */ export declare function isHostname(str: string): boolean; /** * Returns true if the string is a valid host/port pair, for example "example.com:8080". * * If the argument `portRequired` is true, the port is required. If the argument * is false, the port is optional. * * The host can be one of: * - An IPv4 address in dotted decimal format, for example "192.168.0.1". * - An IPv6 address enclosed in square brackets, for example "[::1]". * - A hostname, for example "example.com". * * The port is separated by a colon. It must be non-empty, with a decimal number * in the range of 0-65535, inclusive. */ export declare function isHostAndPort(str: string, portRequired: boolean): boolean; /** * Returns true if the string is an email address, for example "foo@example.com". * * Conforms to the definition for a valid email address from the HTML standard. * Note that this standard willfully deviates from RFC 5322, which allows many * unexpected forms of email addresses and will easily match a typographical * error. */ export declare function isEmail(str: string): boolean; /** * Returns true if the string is a URI, for example "https://example.com/foo/bar?baz=quux#frag". * * URI is defined in the internet standard RFC 3986. * Zone Identifiers in IPv6 address literals are supported (RFC 6874). */ export declare function isUri(str: string): boolean; /** * Returns true if the string is a URI Reference - a URI such as "https://example.com/foo/bar?baz=quux#frag", * or a Relative Reference such as "./foo/bar?query". * * URI, URI Reference, and Relative Reference are defined in the internet * standard RFC 3986. Zone Identifiers in IPv6 address literals are supported * (RFC 6874). */ export declare function isUriRef(str: string): boolean; /** * Returns true if the array only contains values that are distinct from each * other by strict comparison. */ export declare function unique(list: { getItems(): CelResult[]; }): boolean; /** * Returns true if argument bytes contains argument sub. */ export declare function bytesContains(bytes: Uint8Array, sub: Uint8Array): boolean; /** * Returns true if argument bytes starts with argument sub. */ export declare function bytesStartsWith(bytes: Uint8Array, sub: Uint8Array): boolean; /** * Returns true if argument bytes ends with argument sub. */ export declare function bytesEndsWith(bytes: Uint8Array, sub: Uint8Array): boolean;