import { convertSegmentsToSvgString } from './svg' ; import { QrSegment , QrCode } from './qr' ; import { QrOptions } from './types' ; import Ecc = QrCode . Ecc ; /** Default width and height of QR code */ const DEFAULT_SIZE = 128 ; /** Default background color of QR code*/ const BACKGROUND_COLOR_DEFAULT = '#ffffff' ; /** Default foreground color */ const FOREGROUND_COLOR_DEFAULT = '#000000' ; /** Default logo color */ const LOGO_COLOR_DEFAULT = '#07f' ; param text param options function createQR ( text , options ? ) ; deprecated param text param qrSize param className param options function createQR ( text , qrSize , className , options ? ) ; /**
 * Implementation
 */ function createQR ( text , qrSizeOrOptions ? , classNameLegacy ? , legacyOptions ? ) { if ( typeof text !== 'string' ) { throw new TypeError ( 'Enter text for encoding' ) ; } const options = { ... ( typeof qrSizeOrOptions === 'object' && qrSizeOrOptions !== null ? qrSizeOrOptions : { } ) , ... ( typeof legacyOptions === 'object' && legacyOptions !== null ? legacyOptions : { } ) , qrSize : typeof qrSizeOrOptions === 'object' && qrSizeOrOptions !== null && typeof qrSizeOrOptions . qrSize === 'number' ? qrSizeOrOptions . qrSize : ( qrSizeOrOptions as number ) , className : typeof qrSizeOrOptions === 'object' && qrSizeOrOptions !== null && typeof qrSizeOrOptions . className === 'string' ? qrSizeOrOptions . className : classNameLegacy } ; const eccLevels = [ QrCode . Ecc . LOW , QrCode . Ecc . MEDIUM , QrCode . Ecc . QUARTILE , QrCode . Ecc . HIGH ] ; const fallbackOptions = { qrSize : typeof options . qrSize === 'number' ? options . qrSize : DEFAULT_SIZE , className : typeof options . className === 'string' ? options . className : classNameLegacy || '' , isShowLogo : ! ! options . isShowLogo || false , isShowBackground : ! ! options . isShowBackground || false , foregroundColor : typeof options . foregroundColor === 'string' ? options . foregroundColor : FOREGROUND_COLOR_DEFAULT , backgroundColor : typeof options . backgroundColor === 'string' ? options . backgroundColor : BACKGROUND_COLOR_DEFAULT , logoColor : typeof options . logoColor === 'string' ? options . logoColor : LOGO_COLOR_DEFAULT , suffix : options . suffix ? options . suffix . toString ( ) : '0' , logoData : typeof options . logoData === 'string' ? options . logoData : null , ecc : ( typeof options . ecc === 'number' && eccLevels [ options . ecc ] ? options . ecc : 3 ) , } ; const segments = QrSegment . makeSegments ( text ) ; const qrCode = QrCode . encodeSegments ( segments , eccLevels [ fallbackOptions . ecc ] , 1 , 40 , - 1 , true ) ; const svgCode = convertSegmentsToSvgString ( qrCode , fallbackOptions ) ; return svgCode ; } export default { createQR } ;