strong-tie/inbound-calls
0
1'use strict'2 3var UTF8_ACCEPT = 124var UTF8_REJECT = 05var UTF8_DATA = [6 // The first part of the table maps bytes to character to a transition.7 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,8 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,9 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,10 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,11 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,12 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,13 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,14 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,15 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,16 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,17 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,18 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,19 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,20 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,21 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 7, 7,22 10, 9, 9, 9, 11, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,23 24 // The second part of the table maps a state to a new state when adding a25 // transition.26 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,27 12, 0, 0, 0, 0, 24, 36, 48, 60, 72, 84, 96,28 0, 12, 12, 12, 0, 0, 0, 0, 0, 0, 0, 0,29 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0,30 0, 24, 24, 24, 0, 0, 0, 0, 0, 0, 0, 0,31 0, 24, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0,32 0, 48, 48, 48, 0, 0, 0, 0, 0, 0, 0, 0,33 0, 0, 48, 48, 0, 0, 0, 0, 0, 0, 0, 0,34 0, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,35 36 // The third part maps the current transition to a mask that needs to apply37 // to the byte.38 0x7F, 0x3F, 0x3F, 0x3F, 0x00, 0x1F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x0739]40 41function decodeURIComponent (uri) {42 var percentPosition = uri.indexOf('%')43 if (percentPosition === -1) return uri44 45 var length = uri.length46 var decoded = ''47 var last = 048 var codepoint = 049 var startOfOctets = percentPosition50 var state = UTF8_ACCEPT51 52 while (percentPosition > -1 && percentPosition < length) {53 var high = hexCodeToInt(uri[percentPosition + 1], 4)54 var low = hexCodeToInt(uri[percentPosition + 2], 0)55 var byte = high | low56 var type = UTF8_DATA[byte]57 state = UTF8_DATA[256 + state + type]58 codepoint = (codepoint << 6) | (byte & UTF8_DATA[364 + type])59 60 if (state === UTF8_ACCEPT) {61 decoded += uri.slice(last, startOfOctets)62 63 decoded += (codepoint <= 0xFFFF)64 ? String.fromCharCode(codepoint)65 : String.fromCharCode(66 (0xD7C0 + (codepoint >> 10)),67 (0xDC00 + (codepoint & 0x3FF))68 )69 70 codepoint = 071 last = percentPosition + 372 percentPosition = startOfOctets = uri.indexOf('%', last)73 } else if (state === UTF8_REJECT) {74 return null75 } else {76 percentPosition += 377 if (percentPosition < length && uri.charCodeAt(percentPosition) === 37) continue78 return null79 }80 }81 82 return decoded + uri.slice(last)83}84 85var HEX = {86 '0': 0,87 '1': 1,88 '2': 2,89 '3': 3,90 '4': 4,91 '5': 5,92 '6': 6,93 '7': 7,94 '8': 8,95 '9': 9,96 'a': 10,97 'A': 10,98 'b': 11,99 'B': 11,100 'c': 12,101 'C': 12,102 'd': 13,103 'D': 13,104 'e': 14,105 'E': 14,106 'f': 15,107 'F': 15108}109 110function hexCodeToInt (c, shift) {111 var i = HEX[c]112 return i === undefined ? 255 : i << shift113}114 115module.exports = decodeURIComponent116 