-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract.ts
34 lines (26 loc) · 879 Bytes
/
extract.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
export const extractI18nContent = (content: string): string | null => {
const i18nStart = '<i18n lang="yaml">';
const i18nEnd = "</i18n>";
const startIndex = content.indexOf(i18nStart);
const endIndex = content.indexOf(i18nEnd, startIndex);
if (startIndex !== -1 && endIndex !== -1) {
return content.slice(startIndex + i18nStart.length, endIndex).trim();
}
return null;
};
export const extractI18nIndexes = (
content: string
): { start: number; end: number } | null => {
const i18nStart = '<i18n lang="yaml">';
const i18nEnd = "</i18n>";
const startIndex = content.indexOf(i18nStart);
const endIndex = content.indexOf(i18nEnd, startIndex);
if (startIndex === -1 || endIndex === -1) {
return null;
}
console.log("startIndex", startIndex);
return {
start: startIndex + '<i18n lang="yaml">'.length + 1,
end: endIndex,
};
};