30 lines
672 B
TypeScript
30 lines
672 B
TypeScript
|
export const replaceSpacesToEmptyLines = <T = unknown>(object: T): T => {
|
||
|
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, "");
|
||
|
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
if (typeof value === "object") {
|
||
|
result[key] = replaceSpacesToEmptyLines(value);
|
||
|
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
result[key] = value;
|
||
|
}
|
||
|
|
||
|
return result as T;
|
||
|
};
|
||
|
|