mirror of
https://github.com/Kong/insomnia.git
synced 2026-06-04 06:10:24 -04:00
Move insomnia-data models, services, database code, and common utilities into a dedicated workspace package. Update consumers to import from the new package entrypoints and declare workspace dependencies for the extracted package.
28 lines
613 B
TypeScript
28 lines
613 B
TypeScript
export const serializeNDJSON = (data: any[]): string => {
|
|
return data.map((item: any) => JSON.stringify(item) + '\n').join('');
|
|
};
|
|
export const deserializeNDJSON = (data: string): any[] => {
|
|
if (data?.trim() === '') {
|
|
return [];
|
|
}
|
|
// Legacy content - a single JSON array
|
|
if (data.startsWith('[')) {
|
|
try {
|
|
return JSON.parse(data);
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|
|
return data
|
|
.split('\n')
|
|
.filter(e => e?.trim())
|
|
.map((line: string) => {
|
|
try {
|
|
return JSON.parse(line);
|
|
} catch {
|
|
return;
|
|
}
|
|
})
|
|
.filter(e => e !== undefined);
|
|
};
|