param iban returns export function isQRIBAN ( iban ) { iban = iban . replace ( / /g , "" ) ; const QRIID = iban . substr ( 4 , 5 ) ; return ( + QRIID >= 30000 && + QRIID <= 31999 ) ; } param iban returns export function isIBANValid ( iban ) { iban = iban . replace ( / /g , "" ) ; iban = iban . toUpperCase ( ) ; iban = iban . substr ( 4 ) + iban . substr ( 0 , 4 ) ; const A = "A" . charCodeAt ( 0 ) ; const ibanArr = iban . split ( "" ) ; for ( let i = 0 ; i < ibanArr . length ; i ++ ) { const charCode = ibanArr [ i ] . charCodeAt ( 0 ) ; if ( charCode >= A ) { ibanArr [ i ] = charCode - A + 10 + "" ; } } return mod9710 ( ibanArr . join ( "" ) ) === 1 ; } param iban returns export function formatIBAN ( iban ) { iban = iban . replace ( / /g , "" ) ; const ibanArray = iban . replace ( / /g , "" ) . match ( /.{1,4}/g ) ; return ibanArray ?. join ( " " ) ?? iban ; } param reference returns export function isQRReference ( reference ) { reference = reference . replace ( / /g , "" ) ; if ( reference . length === 27 ) { if ( ! isNaN ( + reference ) ) { return true ; } } if ( reference . replace ( / /g , "" ) . length <= 25 ) { return false ; } throw new Error ( "Reference is not valid." ) ; } param reference returns export function isQRReferenceValid ( reference ) { reference = reference . replace ( / /g , "" ) ; if ( Number . isNaN ( reference ) ) { return false ; } if ( reference . length !== 27 ) { return false ; } const ref = reference . substr ( 0 , 26 ) ; const checksum = reference . substr ( 26 , 1 ) ; const calculatedChecksum = calculateQRReferenceChecksum ( ref ) ; return calculatedChecksum === checksum ; } param reference returns export function calculateQRReferenceChecksum ( reference ) { return mod10 ( reference ) ; } param reference returns export function formatQRReference ( reference ) { reference = reference . replace ( / /g , "" ) ; let referenceArray = [ ] ; const match = reference . substring ( 2 ) . match ( /.{1,5}/g ) ; if ( match !== null ) { referenceArray = [ reference . substring ( 0 , 2 ) ] . concat ( match ) ; } return referenceArray . join ( " " ) ; } param reference returns export function formatReference ( reference ) { const referenceType = getReferenceType ( reference ) ; if ( referenceType === "QRR" ) { return formatQRReference ( reference ) ; } else if ( referenceType === "SCOR" ) { return formatSCORReference ( reference ) ; } return reference ; } param reference returns export function formatSCORReference ( reference ) { reference = reference . replace ( / /g , "" ) ; let referenceArray = [ ] ; const match = reference . match ( /.{1,4}/g ) ; if ( match !== null ) { referenceArray = match ; } return referenceArray . join ( " " ) ; } param amount returns export function formatAmount ( amount ) { const amountString = amount . toFixed ( 2 ) ; const amountArray = amountString . split ( "." ) ; let formattedAmountWithoutDecimals = "" ; for ( let x = amountArray [ 0 ] . length - 1 , i = 1 ; x >= 0 ; x -- , i ++ ) { formattedAmountWithoutDecimals = amountArray [ 0 ] [ x ] + formattedAmountWithoutDecimals ; if ( i === 3 ) { formattedAmountWithoutDecimals = " " + formattedAmountWithoutDecimals ; i = 0 ; } } return formattedAmountWithoutDecimals . trim ( ) + "." + amountArray [ 1 ] ; } param millimeters returns export function mm2pt ( millimeters ) { return millimeters * 2.83465 ; } param points returns export function pt2mm ( points ) { return points / 2.83465 ; } param millimeters returns export function mm2px ( millimeters ) { return millimeters * 960 / 254 ; } param pixels returns export function px2mm ( pixels ) { return pixels * 254 / 960 ; } export function getReferenceType ( reference ) { if ( typeof reference === "undefined" ) { return "NON" ; } else if ( isQRReference ( reference ) ) { return "QRR" ; } else { return "SCOR" ; } } function mod9710 ( iban ) { let remainder = iban ; let block ; while ( remainder . length > 2 ) { block = remainder . slice ( 0 , 9 ) ; remainder = parseInt ( block , 10 ) % 97 + remainder . slice ( block . length ) ; } return parseInt ( remainder , 10 ) % 97 ; } function mod10 ( code ) { code = code . replace ( / /g , "" ) ; const table = [ 0 , 9 , 4 , 6 , 8 , 2 , 7 , 1 , 3 , 5 ] ; let carry = 0 ; for ( let i = 0 ; i < code . length ; i ++ ) { carry = table [ ( carry + parseInt ( code . substr ( i , 1 ) , 10 ) ) % 10 ] ; } return ( ( 10 - carry ) % 10 ) . toString ( ) ; }