@ima/core
Version:
IMA.js framework for isomorphic javascript application
142 lines • 5.43 kB
TypeScript
import { AbstractRoute, AsyncRouteController, AsyncRouteView, RouteParams } from './AbstractRoute';
import { RouteFactoryOptions } from './Router';
import { StringParameters } from '../types';
/**
* Utility for representing and manipulating a single static route in the
* router's configuration using string representation of the path expression
* with special param fields identified by `:paramName` prefix.
*/
export declare class StaticRoute extends AbstractRoute<string> {
protected _trimmedPathExpression: string;
protected _parameterNames: string[];
protected _hasParameters: boolean;
protected _matcher: RegExp;
/**
* @inheritDoc
* @param pathExpression A path expression specifying the URL path
* part matching this route (must not contain a query string),
* optionally containing named parameter placeholders specified as
* `:parameterName`.
*/
constructor(name: string, pathExpression: string, controller: AsyncRouteController, view: AsyncRouteView, options?: Partial<RouteFactoryOptions>);
/**
* @inheritDoc
*/
toPath(params?: RouteParams): string;
/**
* @inheritDoc
*/
matches(path: string): boolean;
/**
* @inheritDoc
*/
extractParameters(path: string, baseUrl: string): {
[x: string]: string;
};
/**
* Replace required parameter placeholder in path with parameter value.
*/
_substituteRequiredParamInPath(path: string, paramName: string, paramValue: string): string;
/**
* Replace optional param placeholder in path with parameter value.
*/
_substituteOptionalParamInPath(path: string, paramName: string, paramValue: string): string;
/**
* Remove unused optional param placeholders in path.
*/
_cleanUnusedOptionalParams(path: string): string;
/**
* Returns true, if paramName is placed in path.
*/
_isOptionalParamInPath(path: string, paramName: string): boolean;
/**
* Returns true, if paramName is placed in path and it's required.
*/
_isRequiredParamInPath(path: string, paramName: string): boolean;
/**
* Extract clear parameter name, e.q. '?name' or 'name'
*/
_getClearParamName(rawParam: string): string;
/**
* Get pattern for subparameter.
*/
_getSubparamPattern(delimiter: string): string;
/**
* Check if all optional params are below required ones
*/
_checkOptionalParamsOrder(allMainParams: string[]): boolean;
/**
* Check if main parameters have correct order.
* It means that required param cannot follow optional one.
*
* @param clearedPathExpr The cleared URL path (removed first and last slash, ...).
* @return Returns TRUE if order is correct.
*/
_checkParametersOrder(clearedPathExpr: string): boolean;
/**
* Convert main optional parameters to capture sequences
*
* @param path The URL path.
* @param optionalParams List of main optimal parameter expressions
* @return RegExp pattern.
*/
_replaceOptionalParametersInPath(path: string, optionalParams: string[]): string;
/**
* Convert required subparameters to capture sequences
*
* @param path The URL path (route definition).
* @param clearedPathExpr The original cleared URL path.
* @return RegExp pattern.
*/
_replaceRequiredSubParametersInPath(path: string, clearedPathExpr: string): string;
/**
* Convert optional subparameters to capture sequences
*
* @param path The URL path (route definition).
* @param optionalSubparamsOthers List of all subparam. expressions but last ones
* @param optionalSubparamsLast List of last subparam. expressions
* @return RegExp pattern.
*/
_replaceOptionalSubParametersInPath(path: string, optionalSubparamsOthers: string[], optionalSubparamsLast: string[]): string;
/**
* Compiles the path expression to a regular expression that can be used
* for easier matching of URL paths against this route, and extracting the
* path parameter values from the URL path.
*
* @param pathExpression The path expression to compile.
* @return The compiled regular expression.
*/
_compileToRegExp(pathExpression: string): RegExp;
/**
* Parses the provided path and extract the in-path parameters. The method
* decodes the parameters and returns them in a hash object.
*/
_getParameters(path: string): StringParameters;
/**
* Extract parameters from given path.
*/
_extractParameters(parameterValues: string[]): StringParameters;
/**
* Returns optional param name without "?"
*
* @param paramName Full param name with "?"
* @return Strict param name without "?"
*/
_cleanOptParamName(paramName: string): string;
/**
* Checks if parameter is optional or not.
*
* @param paramName
* @return return true if is optional, otherwise false
*/
_isParamOptional(paramName: string): boolean;
/**
* Extracts the parameter names from the provided path expression.
*
* @param pathExpression The path expression.
* @return The names of the parameters defined in the provided
* path expression.
*/
_getParameterNames(pathExpression: string): string[];
}
//# sourceMappingURL=StaticRoute.d.ts.map