@bespunky/angular-zen
Version:
The Angular tools you always wished were there.
196 lines (195 loc) • 7.12 kB
TypeScript
import { ActivatedRoute, Params, Router } from '@angular/router';
import { DocumentRef } from '@bespunky/angular-zen/core';
import { RouterXConfig } from '../config/router-x-config';
import * as i0 from "@angular/core";
/**
* Provides tools for breaking the current and any url to their different parts.
*
* @export
* @class UrlReflectionService
*/
export declare class UrlReflectionService {
private document;
readonly router: Router;
readonly route: ActivatedRoute;
private config?;
/**
* A regular expression to match the route part of a url. The url can be fully qualified or start at the route.
* The extracted group will be named 'route'.
*
* @example
* The regex will extract '/this/is/the/route' for all of the following:
*
* Fully qualified urls:
* `https://some.website.com/this/is/the/route?a=1&b=2&c=3`
* `https://some.website.com/this/is/the/route#someFragment`
* `https://some.website.com/this/is/the/route?debug=true#fragment`
*
* Relative routes:
* `/this/is/the/route?a=1&b=2&c=3`
* `/this/is/the/route#someFragment`
* `/this/is/the/route?debug=true#fragment`
*
* The regex will extract 'this/is/the/route' (no head slash) for all of the following:
* `this/is/the/route?a=1&b=2&c=3`
* `this/is/the/route#someFragment`
* `this/is/the/route?debug=true#fragment`
**/
readonly RouteRegex: RegExp;
/**
* A regular expression to match all segments of a route.
* Looks for `/<segment>/` parts and extract them without the slashes.
* The extracted groups will be named 'segment'.
*/
readonly RouteSegmentsRegex: RegExp;
/**
* A regular expression to match the question mark and everything that follows in a url.
* The extracted group will be named 'queryString'.
*
* @example
* The regex will extract '?a=1&b=2&c=3' for all of the following:
* https://some.website.com/some/route?a=1&b=2&c=3
* https://some.website.com/some/route?a=1&b=2&c=3#fragment
* /some/route?a=1&b=2&c=3#fragment
* ?a=1&b=2&c=3#fragment
*/
readonly QueryStringRegex: RegExp;
/**
* A regular expression to match the hash sign and everything that follows in a url.
* The extracted group will be named 'fragment'.
*
* @example
* The regex will extract '#fragment' for all of the following:
* https://some.website.com/some/route?a=1&b=2&c=3#fragment
* /some/route?a=1&b=2&c=3#fragment
* some/route?a=1&b=2&c=3#fragment
*/
readonly FragmentRegex: RegExp;
/**
* The complete host portion (e.g. https://www.example.com) of the currently navigated url as fetched from the `document.location` object.
* If the `hostUrl` option was provided when importing the language integration module, it will be used instead.
*
* @type {string}
*/
readonly hostUrl: string;
constructor(document: DocumentRef, router: Router, route: ActivatedRoute, config?: RouterXConfig | undefined);
/**
* Extracts the route portion of a given url.
*
* @example
* routeOf('https://some.website.com/some/route?a=1&b=2&c=3') === '/some/route'
*
* @param {string} url The url for which to extract the route portion.
* @returns {string} The route portion of the url.
*/
routeOf(url: string): string;
/**
* Extracts the route portion of a url as an array of route segments, not including the empty root segment.
*
* @example
* routeSegmentsOf('https://some.website.com/some/route?a=1&b=2&c=3') === ['some', 'route']
* routeSegmentsOf('/some/route') === ['some', 'route']
*
* @param {string} routeOrUrl The route or complete url from which to extract the route segments.
* @returns {string[]} The segments of the route.
*/
routeSegmentsOf(routeOrUrl: string): string[];
/**
* Extracts the query string of a specified url.
*
* @example
* queryStringOf('https://some.website.com/some/route?a=1&b=2&c=3') === '?a=1&b=2&c=3'
*
* @param {string} url The url from which to extract the query string.
* @returns {string} The query string extracted from the url.
*/
queryStringOf(url: string): string;
/**
* Removes the query portion of a url.
*
* @example
* stripQuery('https://some.website.com/some/route?a=1&b=2&c=3#fragment') === 'https://some.website.com/some/route#fragment'
*
* @param {string} url The url from which to remove the query.
* @returns {string} The specified url without the query portion.
*/
stripQuery(url: string): string;
/**
* Extracts the fragment from a url.
*
* @example
* fragmentOf('https://some.website.com/some/route?a=1&b=2&c=3#fragment') === '#fragment'
*
* @param {string} url The url from which to extract the fragment.
* @returns {string} The fragment extracted from the url.
*/
fragmentOf(url: string): string;
/**
* Removes the fragment portion of a url.
*
* @example
* stripFragment('https://some.website.com/some/route?a=1&b=2&c=3#fragment') === 'https://some.website.com/some/route?a=1&b=2&c=3'
*
* @param {string} url The url to remove the fragment.
* @returns {string} The url without the fragment portion.
*/
stripFragment(url: string): string;
/**
* Makes sure the url is prefixed with https instead of http.
*
* @param {string} url The url to secure.
* @returns {string} The secure url.
*/
forceHttps(url: string): string;
/**
* The fully qualified url of the currently navigated route (e.g. 'https://some.website.com/some/route?a=1&b=2&c=3#fragment').
*
* @readonly
* @type {string}
*/
get fullUrl(): string;
/**
* The route url of the currently navigated route (e.g. '/some/route').
*
* @readonly
* @type {string}
*/
get routeUrl(): string;
/**
* The segments of the currently navigated route (e.g. ['some', 'route']).
*
* @readonly
* @type {string[]}
*/
get routeSegments(): string[];
/**
* The object representing the query params in the currently navigated route.
*
* @readonly
* @type {*}
*/
get queryParams(): Params;
/**
* The query string portion of the currently navigated route (e.g. '?a=1&b=2&c=3').
*
* @readonly
* @type {string}
*/
get queryString(): string;
/**
* The fragment portion of the currently navigated route, without the hash sign (e.g. 'fragment').
*
* @readonly
* @type {string}
*/
get fragment(): string;
/**
* The fragment portion of the currently navigated route, with the hash sign (e.g. '#fragment').
*
* @readonly
* @type {string}
*/
get fragmentString(): string;
static ɵfac: i0.ɵɵFactoryDeclaration<UrlReflectionService, [null, null, null, { optional: true; }]>;
static ɵprov: i0.ɵɵInjectableDeclaration<UrlReflectionService>;
}