Initial Commit on git.saherelm.ir ...
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import {
|
||||
values,
|
||||
toArray,
|
||||
hasChild,
|
||||
XKeyValue,
|
||||
XOneOrManyType,
|
||||
isNullOrEmptyString,
|
||||
} from 'x-framework-core';
|
||||
import { XAccountEndPointParam } from '../typings/x-endpoint.typings';
|
||||
|
||||
export function isContainsParams(
|
||||
route: string,
|
||||
params?: XOneOrManyType<XKeyValue<any, string>>
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
if (isNullOrEmptyString(route)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
const paramValues = values(XAccountEndPointParam) as Array<string>;
|
||||
if (!hasChild(paramValues)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
let result = paramValues.some((param) => route.includes(param));
|
||||
if (!result) {
|
||||
//
|
||||
const paramsArr = toArray(params).map((p) => p.key) as Array<string>;
|
||||
if (!hasChild(paramsArr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
result = paramsArr.some((param) => route.includes(param));
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
export function setParams<TParams>(
|
||||
route: string,
|
||||
params?: XOneOrManyType<XKeyValue<TParams, string>>
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
if (
|
||||
!hasChild(params) ||
|
||||
!isContainsParams(route, params) ||
|
||||
isNullOrEmptyString(route)
|
||||
) {
|
||||
return route;
|
||||
}
|
||||
|
||||
//
|
||||
// Do Actions ...
|
||||
toArray(params).forEach((paramKeyValue) => {
|
||||
//
|
||||
route = route.replace(
|
||||
String(paramKeyValue.key),
|
||||
encodeURIComponent(String(paramKeyValue.value))
|
||||
);
|
||||
});
|
||||
|
||||
//
|
||||
return route;
|
||||
}
|
||||
Reference in New Issue
Block a user