lepu-test-platform-web/node_modules/core-js/modules/es.unescape.js

40 lines
1011 B
JavaScript

'use strict';
var $ = require('../internals/export');
var fromCharCode = String.fromCharCode;
var hex2 = /^[\da-f]{2}$/i;
var hex4 = /^[\da-f]{4}$/i;
// `unescape` method
// https://tc39.es/ecma262/#sec-unescape-string
$({ global: true }, {
unescape: function unescape(string) {
var str = String(string);
var result = '';
var length = str.length;
var index = 0;
var chr, slice;
while (index < length) {
chr = str.charAt(index++);
if (chr === '%') {
if (str.charAt(index) === 'u') {
slice = str.slice(index + 1, index + 5);
if (hex4.test(slice)) {
result += fromCharCode(parseInt(slice, 16));
index += 5;
continue;
}
} else {
slice = str.slice(index, index + 2);
if (hex2.test(slice)) {
result += fromCharCode(parseInt(slice, 16));
index += 2;
continue;
}
}
}
result += chr;
} return result;
}
});