|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.4 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | import toFormData from './toFormData.js';
|
|---|
| 4 |
|
|---|
| 5 | /**
|
|---|
| 6 | * It encodes a string by replacing all characters that are not in the unreserved set with
|
|---|
| 7 | * their percent-encoded equivalents
|
|---|
| 8 | *
|
|---|
| 9 | * @param {string} str - The string to encode.
|
|---|
| 10 | *
|
|---|
| 11 | * @returns {string} The encoded string.
|
|---|
| 12 | */
|
|---|
| 13 | function encode(str) {
|
|---|
| 14 | const charMap = {
|
|---|
| 15 | '!': '%21',
|
|---|
| 16 | "'": '%27',
|
|---|
| 17 | '(': '%28',
|
|---|
| 18 | ')': '%29',
|
|---|
| 19 | '~': '%7E',
|
|---|
| 20 | '%20': '+',
|
|---|
| 21 | };
|
|---|
| 22 | return encodeURIComponent(str).replace(/[!'()~]|%20/g, function replacer(match) {
|
|---|
| 23 | return charMap[match];
|
|---|
| 24 | });
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | /**
|
|---|
| 28 | * It takes a params object and converts it to a FormData object
|
|---|
| 29 | *
|
|---|
| 30 | * @param {Object<string, any>} params - The parameters to be converted to a FormData object.
|
|---|
| 31 | * @param {Object<string, any>} options - The options object passed to the Axios constructor.
|
|---|
| 32 | *
|
|---|
| 33 | * @returns {void}
|
|---|
| 34 | */
|
|---|
| 35 | function AxiosURLSearchParams(params, options) {
|
|---|
| 36 | this._pairs = [];
|
|---|
| 37 |
|
|---|
| 38 | params && toFormData(params, this, options);
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | const prototype = AxiosURLSearchParams.prototype;
|
|---|
| 42 |
|
|---|
| 43 | prototype.append = function append(name, value) {
|
|---|
| 44 | this._pairs.push([name, value]);
|
|---|
| 45 | };
|
|---|
| 46 |
|
|---|
| 47 | prototype.toString = function toString(encoder) {
|
|---|
| 48 | const _encode = encoder
|
|---|
| 49 | ? function (value) {
|
|---|
| 50 | return encoder.call(this, value, encode);
|
|---|
| 51 | }
|
|---|
| 52 | : encode;
|
|---|
| 53 |
|
|---|
| 54 | return this._pairs
|
|---|
| 55 | .map(function each(pair) {
|
|---|
| 56 | return _encode(pair[0]) + '=' + _encode(pair[1]);
|
|---|
| 57 | }, '')
|
|---|
| 58 | .join('&');
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | export default AxiosURLSearchParams;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.