frontAnswerer/src/pages/ViewPublicationPage/tools/replaceSpacesToEmptyLines.ts

36 lines
902 B
TypeScript
Raw Normal View History

2023-12-29 00:58:19 +00:00
export const replaceSpacesToEmptyLines = <T = unknown>(object: T): T => {
2024-01-11 13:13:42 +00:00
if (Array.isArray(object)) {
return object.map(replaceSpacesToEmptyLines) as T;
}
if (!object || typeof object !== "object") {
return object;
}
const result: Record<string, unknown> = {};
for (const [key, value] of Object.entries(object)) {
if (typeof value === "string") {
result[key] = value.replace(/\" \"/g, '""');
// ↓ ЭТО ВРЕМЕННЫЙ КОД ДЛЯ ДЕМОНСТРАЦИИ ДИМЕ
result[key] = value.replace(
"squiz.pena.digital",
"storage.yandexcloud.net"
);
// ↑ ЭТО ВРЕМЕННЫЙ КОД ДЛЯ ДЕМОНСТРАЦИИ ДИМЕ
continue;
2023-12-29 00:58:19 +00:00
}
2024-01-11 13:13:42 +00:00
if (typeof value === "object") {
result[key] = replaceSpacesToEmptyLines(value);
continue;
2023-12-29 00:58:19 +00:00
}
2024-01-11 13:13:42 +00:00
result[key] = value;
}
return result as T;
};