UNPKG

tshttpurl

Version:

Http URL and IP address parser and normalizer

70 lines (69 loc) 2.53 kB
import { IPv6 } from './IPv6'; /** * HttpURL parses and normalizes http and https URLs. * * A missing scheme is assumed to be `http` * * The scheme and host are converted to lowercase * * If the host is an IP V6 address, then IPv6::toString value is used * * A missing port is assumed to be `80` or `443` * * Percent encoded triplets are converted to upper case * * Unnecessary percent encoded triplets are decoded * * Path traversals: * * `.` and `..`are interpreted * * `//` is collapsed * * The path is verified to not climb out past the root * * Query parameters are ordered by name, then value */ export declare class HttpURL { private static pctXX; private static qSep; private static regEx; readonly scheme: 'https' | 'http'; readonly ipAddress?: IPv6; readonly host: string; readonly port: number; readonly path: Array<string>; readonly query: Array<QueryParam>; readonly fragment?: string; readonly isDir: boolean; constructor(url: string); /** * @returns The normalized http URL. */ toString(): string; /** * Function used to determine the order of `HttpURL`s. It is suitable * for use with `Array<T>.sort(fn)`. If an argument is not an `HttpURL`, * then its toString() value is used to create one. * * `HttpURL`s are ordered by thier string representation * * @param a The first http URL to compare * @param b The second http URL to compare */ static compare(a: Object, b: Object): number; } export declare class QueryParam { readonly name: string; readonly value: string; /** * Creates a QueryParam instance. * @param name The name of the query parameter. The value may optionally * be included. E.g. "age=65" * @param value The value, if not included in the name parameter. * * @throws Error if a value is included in both name and value */ constructor(name: string, value?: string); toString(): string; /** * Function used to determine the order of `QueryParam`s. It is suitable * for use with `Array<T>.sort(fn)`. If an argument is not a `QueryParam`, * then its toString() value is used to create one. * * `QueryParam`s are ordered by thier name, and then their value. * * @param a The first query parameter to compare * @param b The second query parameter to compare */ static compare(a: Object, b: Object): number; }