import * as Papa from 'papaparse' ; import { OutputBlockModel } from "./output-block.model" ; export class ScanModel { id : number ; outputBlocks : OutputBlockModel [ ] ; cancelled : boolean ; repeated : boolean ; ack : boolean ; /**
     * This field should be set when the scan is created. Like this:
     * scan.displayValue = ScanModel.ToString(scan);
     */ displayValue : string ; deprecated format : 'QR_CODE' | 'DATA_MATRIX' | 'UPC_E' | 'UPC_A' | 'EAN_8' | 'EAN_13' | 'CODE_128' | 'CODE_39' | 'CODE_93' | 'CODABAR' | 'ITF' | 'RSS14' | 'RSS_EXPANDED' | 'PDF_417' | 'AZTEC' | 'MSI' ; deprecated date : number ; deprecated quantity : string ; deprecated text : string ; param scan param fieldSeparator static ToString ( scan , fieldSeparator = ' ' ) { if ( ! scan || ! scan . outputBlocks ) { return '' ; } return scan . outputBlocks . map ( block => { if ( block . skipOutput ) { return '' ; } switch ( block . type ) { case 'key' : { if ( block . value == 'tab' ) { return '\t' ; } else if ( block . value == 'space' ) { return ' ' ; } else { return '' ; } } case 'text' : return block . value ; case 'variable' : return block . value ; case 'date_time' : return block . value ; case 'select_option' : return block . value ; case 'function' : return block . value ; case 'http' : return block . value ; case 'run' : return block . value ; case 'csv_lookup' : return block . value ; case 'csv_update' : return block . value ; case 'barcode' : return block . value ; case 'delay' : return '' ; case 'beep' : return '' ; case 'alert' : return '' ; default : return '' ; } } ) . join ( fieldSeparator ) . replace ( /\s+/g , ' ' ) ; } param newLineCharacter static ToCSV ( scannings , exportOnlyText , enableQuotes , csvDelimiter , newLineCharacter ) { return Papa . unparse ( scannings . map ( scan => { if ( exportOnlyText ) { return scan . outputBlocks . filter ( outputBlock => ( outputBlock . type != 'key' && outputBlock . type != 'delay' && outputBlock . type != 'beep' && outputBlock . type != 'alert' && ! outputBlock . skipOutput ) ) . map ( outputBlock => outputBlock . value ) ; } return scan . outputBlocks . map ( outputBlock => outputBlock . value ) ; } ) , { quotes : enableQuotes , delimiter : csvDelimiter , newline : newLineCharacter } ) ; } }