packageDocumentation module internal namespace Utf8ToString { function inRange ( a , min , max ) { return min <= a && a <= max ; } function utf8Handler ( bytes ) { let codePoint = 0 ; let bytesSeen = 0 ; let bytesNeeded = 0 ; let lowerBoundary = 0x80 ; let upperBoundary = 0xbf ; const codePoints = [ ] ; const length = bytes . length ; for ( let i = 0 ; i < length ; i ++ ) { const currentByte = bytes [ i ] ; if ( 0 === bytesNeeded ) { if ( inRange ( currentByte , 0x00 , 0x7f ) ) { codePoints . push ( currentByte ) ; continue ; } if ( inRange ( currentByte , 0xc2 , 0xdf ) ) { bytesNeeded = 1 ; codePoint = currentByte & 0x1f ; continue ; } if ( inRange ( currentByte , 0xe0 , 0xef ) ) { if ( 0xe0 === currentByte ) lowerBoundary = 0xa0 ; else if ( 0xed === currentByte ) upperBoundary = 0x9f ; bytesNeeded = 2 ; codePoint = currentByte & 0xf ; continue ; } if ( inRange ( currentByte , 0xf0 , 0xf4 ) ) { if ( 0xf0 === currentByte ) lowerBoundary = 0x90 ; else if ( 0xf4 === currentByte ) upperBoundary = 0x8f ; bytesNeeded = 3 ; codePoint = currentByte & 0x7 ; continue ; } return undefined ; } if ( ! inRange ( currentByte , lowerBoundary , upperBoundary ) ) { codePoint = bytesNeeded = bytesSeen = 0 ; lowerBoundary = 0x80 ; upperBoundary = 0xbf ; -- i ; continue ; } lowerBoundary = 0x80 ; upperBoundary = 0xbf ; codePoint = ( codePoint << 6 ) | ( currentByte & 0x3f ) ; ++ bytesSeen ; if ( bytesSeen === bytesNeeded ) { codePoints . push ( codePoint ) ; codePoint = bytesNeeded = bytesSeen = 0 ; } } return codePoints ; } export function decodeWithFromCharCode ( view ) { let result = "" ; const codePoints = utf8Handler ( view ) ; if ( undefined === codePoints ) return undefined ; for ( let cp of codePoints ) { if ( cp <= 0xffff ) { result += String . fromCharCode ( cp ) ; } else { cp -= 0x10000 ; result += String . fromCharCode ( ( cp >> 10 ) + 0xd800 , ( cp & 0x3ff ) + 0xdc00 ) ; } } return result ; } } internal export function utf8ToStringPolyfill ( utf8 ) { return Utf8ToString . decodeWithFromCharCode ( utf8 ) ; } let textDecoderSupported = true ; param utf8 returns note public export function utf8ToString ( utf8 ) { let decoder ; if ( textDecoderSupported ) { try { decoder = new TextDecoder ( "utf-8" ) ; } catch ( _ex ) { textDecoderSupported = false ; } } if ( undefined !== decoder ) return decoder . decode ( utf8 ) ; else return utf8ToStringPolyfill ( utf8 ) ; } param base64 returns throws public export function base64StringToUint8Array ( base64 ) { return new Uint8Array ( atob ( base64 ) . split ( "" ) . map ( ( c ) => c . charCodeAt ( 0 ) ) ) ; }