Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | 'use strict';
|
---|
| 2 | var $ = require('../internals/export');
|
---|
| 3 | var toString = require('../internals/to-string');
|
---|
| 4 |
|
---|
| 5 | var fromCharCode = String.fromCharCode;
|
---|
| 6 | var hex2 = /^[\da-f]{2}$/i;
|
---|
| 7 | var hex4 = /^[\da-f]{4}$/i;
|
---|
| 8 |
|
---|
| 9 | // `unescape` method
|
---|
| 10 | // https://tc39.es/ecma262/#sec-unescape-string
|
---|
| 11 | $({ global: true }, {
|
---|
| 12 | unescape: function unescape(string) {
|
---|
| 13 | var str = toString(string);
|
---|
| 14 | var result = '';
|
---|
| 15 | var length = str.length;
|
---|
| 16 | var index = 0;
|
---|
| 17 | var chr, slice;
|
---|
| 18 | while (index < length) {
|
---|
| 19 | chr = str.charAt(index++);
|
---|
| 20 | if (chr === '%') {
|
---|
| 21 | if (str.charAt(index) === 'u') {
|
---|
| 22 | slice = str.slice(index + 1, index + 5);
|
---|
| 23 | if (hex4.test(slice)) {
|
---|
| 24 | result += fromCharCode(parseInt(slice, 16));
|
---|
| 25 | index += 5;
|
---|
| 26 | continue;
|
---|
| 27 | }
|
---|
| 28 | } else {
|
---|
| 29 | slice = str.slice(index, index + 2);
|
---|
| 30 | if (hex2.test(slice)) {
|
---|
| 31 | result += fromCharCode(parseInt(slice, 16));
|
---|
| 32 | index += 2;
|
---|
| 33 | continue;
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
| 36 | }
|
---|
| 37 | result += chr;
|
---|
| 38 | } return result;
|
---|
| 39 | }
|
---|
| 40 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.