import { JSECell , JSEFont , JSEHeaderCell , JSERow , JSESheet , JSExcel , JSEBorder , JSECellBorder } from "../Types" ; export function excelTotalCellCounter ( excel ) { if ( excel == null || excel == undefined || excel . sheets == undefined ) return 0 ; return excel . sheets . map ( sheetTotalCellCounter ) . reduce ( add , 0 ) ; } function sheetTotalCellCounter ( sheet ) { if ( sheet == null || sheet == undefined ) return 0 ; const { columns , data } = sheet ; return columns ? columns . length + data . map ( rowTotalCellCounter ) . reduce ( add , 0 ) : data . map ( rowTotalCellCounter ) . reduce ( add , 0 ) ; } function rowTotalCellCounter ( row ) { if ( row == null || row == undefined ) return 0 ; return row . length ; } function add ( item1 , item2 ) { return item1 + item2 ; } /**
 * Fonts utility/helper functions
 */ export function hasFontsInExcel ( excel ) { if ( excel == null || excel == undefined ) return false ; return excel . sheets . some ( hasFontInSheet ) ; } function hasFontInSheet ( sheet ) { if ( sheet == null || sheet == undefined ) return false ; return ( sheet . columns && sheet . columns . some ( hasFontInCell ) ) || sheet . data . some ( row => row . some ( hasFontInCell ) ) ; } function hasFontInCell ( cell ) { if ( cell == null || cell == undefined ) return false ; return ! ! ( cell . font && cell . font . name ) ; } export function extractFontsFromExcel ( excel ) { if ( excel == null || excel == undefined ) return [ ] ; return excel . sheets . flatMap ( getFontsFromSheet ) ; } function getFontsFromSheet ( sheet ) { const fonts = [ ] ; if ( sheet . columns ) { sheet . columns . map ( ( col ) => { if ( col . font ) { fonts . push ( col . font ) ; } } ) ; } if ( sheet . data ) { sheet . data . forEach ( ( row ) => { row . forEach ( ( col ) => { if ( col . font ) { fonts . push ( col . font ) ; } } ) ; } ) ; } return fonts ; } /**
 *  Fills utility/helper functions
 *  */ export function hasBordersInExcel ( excel ) { if ( excel == null || excel == undefined ) return false ; return excel . sheets . some ( hasBordersInSheet ) ; } function hasBordersInSheet ( sheet ) { if ( sheet == null || sheet == undefined ) return false ; return ( sheet . columns && sheet . columns . some ( hasBordersInCell ) ) || sheet . data . some ( row => row . some ( hasBordersInCell ) ) ; } function hasBordersInCell ( cell ) { if ( cell == null || cell == undefined ) return false ; return ! ! ( cell . font && cell . font . name ) ; } export function extractBordersFromExcel ( excel ) { if ( excel == null || excel == undefined ) return [ ] ; return excel . sheets . flatMap ( getBordersFromSheet ) ; } function getBordersFromSheet ( sheet ) { const borders = [ ] ; if ( sheet . columns ) { sheet . columns . map ( ( col ) => { if ( col . border ) { borders . push ( col . border ) ; } } ) ; } if ( sheet . data ) { sheet . data . forEach ( ( row ) => { row . forEach ( ( col ) => { if ( col . border ) { borders . push ( col . border ) ; } } ) ; } ) ; } return borders ; }