MCPcopy Index your code
hub / github.com/nodejs/node / decode

Function decode

lib/punycode.js:208–293  ·  view source on GitHub ↗
(input)

Source from the content-addressed store, hash-verified

206 * @returns {String} The resulting string of Unicode symbols.
207 */
208const decode = function(input) {
209 // Don't use UCS-2.
210 const output = [];
211 const inputLength = input.length;
212 let i = 0;
213 let n = initialN;
214 let bias = initialBias;
215
216 // Handle the basic code points: let `basic` be the number of input code
217 // points before the last delimiter, or `0` if there is none, then copy
218 // the first basic code points to the output.
219
220 let basic = input.lastIndexOf(delimiter);
221 if (basic < 0) {
222 basic = 0;
223 }
224
225 for (let j = 0; j < basic; ++j) {
226 // if it's not a basic code point
227 if (input.charCodeAt(j) >= 0x80) {
228 error('not-basic');
229 }
230 output.push(input.charCodeAt(j));
231 }
232
233 // Main decoding loop: start just after the last delimiter if any basic code
234 // points were copied; start at the beginning otherwise.
235
236 for (let index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
237
238 // `index` is the index of the next character to be consumed.
239 // Decode a generalized variable-length integer into `delta`,
240 // which gets added to `i`. The overflow checking is easier
241 // if we increase `i` as we go, then subtract off its starting
242 // value at the end to obtain `delta`.
243 const oldi = i;
244 for (let w = 1, k = base; /* no condition */; k += base) {
245
246 if (index >= inputLength) {
247 error('invalid-input');
248 }
249
250 const digit = basicToDigit(input.charCodeAt(index++));
251
252 if (digit >= base) {
253 error('invalid-input');
254 }
255 if (digit > floor((maxInt - i) / w)) {
256 error('overflow');
257 }
258
259 i += digit * w;
260 const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
261
262 if (digit < t) {
263 break;
264 }
265

Callers 2

toUnicodeFunction · 0.70
string_decoder.jsFile · 0.70

Calls 4

basicToDigitFunction · 0.85
adaptFunction · 0.85
errorFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…