1/** 2 * @param {string} message 3 * @returns {never} 4 */ 5function fail(message) { 6 throw new Error(message); 7} 8 9/** 10 * @param {number} value 11 */ 12function base64FormatEncode(value) { 13 return value < 0 ? fail("Invalid value") : 14 value < 26 ? 0x41 /*A*/ + value : 15 value < 52 ? 0x61 /*a*/ + value - 26 : 16 value < 62 ? 0x30 /*0*/ + value - 52 : 17 value === 62 ? 0x2B /*+*/ : 18 value === 63 ? 0x2F /*/*/ : 19 fail("Invalid value"); 20} 21 22/** 23 * @param {number} value 24 */ 25export function base64VLQFormatEncode(value) { 26 if (value < 0) { 27 value = ((-value) << 1) + 1; 28 } 29 else { 30 value = value << 1; 31 } 32 33 // Encode 5 bits at a time starting from least significant bits 34 let result = ""; 35 do { 36 let currentDigit = value & 31; // 11111 37 value = value >> 5; 38 if (value > 0) { 39 // There are still more digits to decode, set the msb (6th bit) 40 currentDigit = currentDigit | 32; 41 } 42 result += String.fromCharCode(base64FormatEncode(currentDigit)); 43 } while (value > 0); 44 45 return result; 46} 47 48/** @typedef {object} RawSourceMap */ 49