melhoria em tipagem rota
This commit is contained in:
parent
d628f0fc32
commit
457973873b
5 changed files with 16 additions and 35 deletions
|
|
@ -17,22 +17,17 @@ export class TipagemRotas<T extends { [q: string]: string | undefined }> {
|
|||
** export const mCaminho = new TipagemRotas<{q:string}>("aplicacao","funcionalidade")
|
||||
*/
|
||||
constructor({
|
||||
caminhos,
|
||||
caminho,
|
||||
acaoIr,
|
||||
}: {
|
||||
caminhos: string[] | string
|
||||
caminho: string[] | string
|
||||
acaoIr?: undefined | ((endereco: string) => undefined)
|
||||
}) {
|
||||
this._acaoIr = acaoIr
|
||||
;[Array.isArray(caminhos) ? caminhos : [caminhos]].forEach((caminho) => {
|
||||
String(caminho)
|
||||
.split("/")
|
||||
.forEach((parte) => {
|
||||
if (parte) {
|
||||
this._partesCaminho.push(parte)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
this._partesCaminho = (Array.isArray(caminho) ? caminho : [caminho])
|
||||
.flatMap((a) => a.split("/"))
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
/** Retorna o caminho completo da rota
|
||||
|
|
@ -40,11 +35,7 @@ export class TipagemRotas<T extends { [q: string]: string | undefined }> {
|
|||
** "/caminho"
|
||||
*/
|
||||
get caminho() {
|
||||
let ret = `/${this._partesCaminho.join("/")}`
|
||||
ret = ret.replace(/\/+/g, "/")
|
||||
if (ret.length > 1 && ret.endsWith("/")) {
|
||||
ret = ret.slice(0, -1)
|
||||
}
|
||||
const ret = `/${this._partesCaminho.join("/")}`
|
||||
return ret
|
||||
}
|
||||
/** Define o caminho completo da rota
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue