export function quoteVal ( val ) { return `"${ val . replace ( /"/g , `\\"` ) }"` ; } export function parseCsv ( value ) { return ( CSVtoArray ( value ) || ( [ ] as unknown ) ) as string [ ] ; } function CSVtoArray ( value ) { const reValid = /^\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*(?:,\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*)*$/ ; const reValue = /(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g ; if ( ! reValid . test ( value ) ) { return [ value ] ; } const a = [ ] ; value . replace ( reValue , ( m0 , m1 , m2 , m3 ) => { if ( m1 !== undefined ) { a . push ( m1 . replace ( /\\'/g , "'" ) ) ; } else if ( m2 !== undefined ) { a . push ( m2 . replace ( /\\"/g , '"' ) ) ; } else if ( m3 !== undefined ) { a . push ( m3 ) ; } return '' ; } ) ; if ( /,\s*$/ . test ( value ) ) { a . push ( '' ) ; } return a ; }