fix extractNavigate
This commit is contained in:
parent
0536dc400d
commit
79287ceb0c
|
|
@ -191,27 +191,35 @@ const streamPage = (p: PG, id: string) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const extractNavigate = (str: string) => {
|
export const extractNavigate = (str: string) => {
|
||||||
|
return [
|
||||||
|
...findBetween(str, `navigate(`, `)`),
|
||||||
|
...findBetween(str, `href = `, `;`),
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
const findBetween = (text: string, opener: string, closer: string) => {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
const nstr = "navigate(";
|
let last = 0;
|
||||||
const founds: string[] = [];
|
const founds: string[] = [];
|
||||||
let lasti = 0;
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const start = str.indexOf(nstr, i);
|
const startIndex = text.indexOf(opener, i);
|
||||||
lasti = i;
|
last = i;
|
||||||
if (start >= 0) {
|
if (startIndex >= 0) {
|
||||||
const char = str[start + nstr.length];
|
const char = text[startIndex + opener.length];
|
||||||
if (char === '"' || char === "'" || char === "`") {
|
if (char === '"' || char === "'" || char === "`") {
|
||||||
const end = str.indexOf(`${char})`, start + nstr.length + 1);
|
const end = text.indexOf(
|
||||||
const text = str.substring(start + nstr.length + 1, end);
|
`${char}${closer}`,
|
||||||
i = end + 3;
|
startIndex + opener.length + 1
|
||||||
founds.push(text);
|
);
|
||||||
|
const found = text.substring(startIndex + opener.length + 1, end);
|
||||||
|
i = end + 2 + closer.length;
|
||||||
|
founds.push(found);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lasti === i) {
|
if (last === i) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return founds;
|
return founds;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue