'a'
mh-two-thousand-and-two
2024-04-12 44d2c92345cd156a59fc327b3060292a282d2893
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var each = require('./each');
var ucs2 = require('./ucs2');
var map = require('./map');
var utf8 = require('./utf8');
exports = function(str) {
    try {
        return decodeURIComponent(str);
    } catch (e) {
        var matches = str.match(regMatcher);
        if (!matches) {
            return str;
        }
        each(matches, function(match) {
            str = str.replace(match, decode(match));
        });
        return str;
    }
};
function decode(str) {
    str = str.split('%').slice(1);
    var bytes = map(str, hexToInt);
    str = ucs2.encode(bytes);
    str = utf8.decode(str, true);
    return str;
}
function hexToInt(numStr) {
    return +('0x' + numStr);
}
var regMatcher = /(%[a-f0-9]{2})+/gi;
 
module.exports = exports;