2025-01-24 14:27:10 +01:00
|
|
|
export const getJSONfromString = <T>(str: string): T => {
|
2023-06-14 02:26:19 +02:00
|
|
|
const jsonSubstring = str.substring(0, str.lastIndexOf("}") + 1);
|
2025-01-24 14:27:10 +01:00
|
|
|
return JSON.parse(jsonSubstring) as T;
|
2023-06-14 02:26:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export const getSubstringFromKeyword = (str: string, keyword: string): string => {
|
|
|
|
const index = str.indexOf(keyword);
|
|
|
|
if (index == -1) {
|
|
|
|
throw new Error(`keyword ${keyword} not found in string ${str}`);
|
|
|
|
}
|
|
|
|
return str.substring(index);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getSubstringFromKeywordToKeyword = (str: string, keywordBegin: string, keywordEnd: string): string => {
|
|
|
|
const beginIndex = str.lastIndexOf(keywordBegin) + 1;
|
|
|
|
const endIndex = str.indexOf(keywordEnd);
|
|
|
|
return str.substring(beginIndex, endIndex + 1);
|
|
|
|
};
|
2024-01-25 14:49:45 +01:00
|
|
|
|
2024-12-29 21:47:18 +01:00
|
|
|
export const getIndexAfter = (str: string, searchWord: string): number => {
|
2024-01-25 14:49:45 +01:00
|
|
|
const index = str.indexOf(searchWord);
|
|
|
|
if (index === -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return index + searchWord.length;
|
|
|
|
};
|