|
- export const TEXT_SERIALIZER_PAIR = {
- name: 'text/plain',
- serialize(obj: unknown, level = 0): string {
- if (Array.isArray(obj)) {
- return obj.map((o) => this.serialize(o)).join('\n\n');
- }
-
- if (typeof obj === 'object') {
- if (obj !== null) {
- return Object.entries(obj)
- .map(([key, value]) => `${Array(level * 2).fill(' ').join('')}${key}: ${this.serialize(value, level + 1)}`)
- .join('\n');
- }
-
- return '';
- }
-
- if (typeof obj === 'number' && Number.isFinite(obj)) {
- return obj.toString();
- }
-
- if (typeof obj === 'string') {
- return obj;
- }
-
- return '';
- },
- deserialize: <T>(str: string) => str as T
- };
|