import symbology from '../binding' ; import BinResult from '../types/BinResult' ; import OutputType from '../types/enums/OutputType' ; import SymbologyConfig from '../types/SymbologyConfig' ; param { SymbologyConfig } config param { string } barcodeData return { BinResult } function createBuffer ( config , barcodeData ) { return symbology . createStream ( barcodeData , config . symbology , config . height , config . whitespaceWidth , config . borderWidth , config . outputOptions , config . backgroundColor , config . foregroundColor , config . fileName ?. replace ( /\.png$/g , '.bmp' ) , config . scale , config . option1 , config . option2 , config . option3 , config . showHumanReadableText ? 1 : 0 , ( config . text || barcodeData ) , config . encoding , config . eci , config . primary , config . rotation , config . dotSize ) ; } note param { SymbologyConfig } config param { string } barcodeData param { OutputType } outputType returns { Promise < BinResult > } function invoke ( config , barcodeData , outputType ) { const symbol = { ... config } ; if ( ! [ OutputType . PNG , OutputType . EPS , OutputType . SVG ] . includes ( outputType ) ) { return Promise . reject ( `Invalid output type: ${ outputType }` ) ; } if ( outputType !== OutputType . PNG ) { symbol . fileName = `out.${ outputType }` ; if ( symbol . outputOptions ) { symbol . outputOptions += 8 ; } else { symbol . outputOptions = 8 ; } } const res = binary . createBuffer ( symbol , barcodeData ) ; if ( res . code <= 2 ) { res . encodedData = res . encodedData . split ( '<<< EOF >>>' ) [ 0 ] ; if ( res . code === 0 ) { res . message = 'Symbology successfully created.' ; } return Promise . resolve ( res ) ; } return Promise . reject ( res . message ) ; } param { string } fileName returns { OutputType } function getOutputType ( fileName ) { switch ( fileName . toLowerCase ( ) . substr ( - 3 ) ) { case 'svg' : return OutputType . SVG ; case 'eps' : return OutputType . EPS ; default : return OutputType . PNG ; } } const binary = { createBuffer , invoke , getOutputType } ; export default binary ;