Initial Commit ...
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import {
|
||||
hasChild,
|
||||
XKeyValue,
|
||||
isNullOrUndefined,
|
||||
isNullOrEmptyString,
|
||||
} from 'x-framework-core';
|
||||
|
||||
/**
|
||||
* Prepare a route by replacing it's params by providing values ...
|
||||
*/
|
||||
export function fillRouteParams(
|
||||
route: string,
|
||||
params?: Array<XKeyValue<string, string>>
|
||||
) {
|
||||
//
|
||||
let result = '';
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (isNullOrEmptyString(route)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Params Has Child ...
|
||||
if (!isNullOrUndefined(params) && hasChild(params)) {
|
||||
//
|
||||
result = route;
|
||||
for (let param of params) {
|
||||
//
|
||||
const key = `{${param.key}}`;
|
||||
result = result.replace(key, param.value);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user