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