22
33import type { ExportFormat } from './types' ;
44
5- export function convertToCSV < T extends Record < string , unknown > > ( data : T [ ] ) : string {
5+ export function convertToCSV < T extends Record < string , unknown > > (
6+ data : T [ ]
7+ ) : string {
68 if ( data . length === 0 ) return '' ;
79
810 const headers = Object . keys ( data [ 0 ] || { } ) . join ( ',' ) ;
@@ -31,7 +33,9 @@ export function convertToCSV<T extends Record<string, unknown>>(data: T[]): stri
3133 return `${ headers } \n${ rows } ` ;
3234}
3335
34- export function convertToTXT < T extends Record < string , unknown > > ( data : T [ ] ) : string {
36+ export function convertToTXT < T extends Record < string , unknown > > (
37+ data : T [ ]
38+ ) : string {
3539 if ( data . length === 0 ) return '' ;
3640
3741 const headers = Object . keys ( data [ 0 ] || { } ) . join ( '\t' ) ;
@@ -53,20 +57,20 @@ export function convertToTXT<T extends Record<string, unknown>>(data: T[]): stri
5357}
5458
5559export function convertToProto < T extends Record < string , unknown > > (
56- data : T [ ] ,
60+ data : T [ ] ,
5761 typeName : string
5862) : string {
5963 if ( data . length === 0 ) return '' ;
6064
6165 let protoContent = `# Protocol Buffer Text Format\n# Type: ${ typeName } \n\n` ;
62-
66+
6367 for ( const [ index , row ] of data . entries ( ) ) {
6468 protoContent += `${ typeName } {\n` ;
65-
69+
6670 for ( const [ key , value ] of Object . entries ( row ) ) {
6771 if ( value !== null && value !== undefined ) {
6872 const fieldName = key . toLowerCase ( ) . replace ( / [ ^ a - z 0 - 9 _ ] / g, '_' ) ;
69-
73+
7074 if ( typeof value === 'string' ) {
7175 // Escape quotes in string values
7276 const escapedValue = value . replace ( / " / g, '\\"' ) . replace ( / \n / g, '\\n' ) ;
@@ -77,24 +81,26 @@ export function convertToProto<T extends Record<string, unknown>>(
7781 protoContent += ` ${ fieldName } : ${ value } \n` ;
7882 } else {
7983 // Convert other types to string
80- const stringValue = String ( value ) . replace ( / " / g, '\\"' ) . replace ( / \n / g, '\\n' ) ;
84+ const stringValue = String ( value )
85+ . replace ( / " / g, '\\"' )
86+ . replace ( / \n / g, '\\n' ) ;
8187 protoContent += ` ${ fieldName } : "${ stringValue } "\n` ;
8288 }
8389 }
8490 }
85-
91+
8692 protoContent += '}\n' ;
8793 if ( index < data . length - 1 ) {
8894 protoContent += '\n' ;
8995 }
9096 }
91-
97+
9298 return protoContent ;
9399}
94100
95101export function formatData < T extends Record < string , unknown > > (
96- data : T [ ] ,
97- format : ExportFormat ,
102+ data : T [ ] ,
103+ format : ExportFormat ,
98104 typeName : string
99105) : string {
100106 switch ( format ) {
0 commit comments