source: imaps-frontend/node_modules/axios/lib/helpers/AxiosURLSearchParams.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[d565449]1'use strict';
2
3import 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 */
13function encode(str) {
14 const charMap = {
15 '!': '%21',
16 "'": '%27',
17 '(': '%28',
18 ')': '%29',
19 '~': '%7E',
20 '%20': '+',
21 '%00': '\x00'
22 };
23 return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) {
24 return charMap[match];
25 });
26}
27
28/**
29 * It takes a params object and converts it to a FormData object
30 *
31 * @param {Object<string, any>} params - The parameters to be converted to a FormData object.
32 * @param {Object<string, any>} options - The options object passed to the Axios constructor.
33 *
34 * @returns {void}
35 */
36function AxiosURLSearchParams(params, options) {
37 this._pairs = [];
38
39 params && toFormData(params, this, options);
40}
41
42const prototype = AxiosURLSearchParams.prototype;
43
44prototype.append = function append(name, value) {
45 this._pairs.push([name, value]);
46};
47
48prototype.toString = function toString(encoder) {
49 const _encode = encoder ? function(value) {
50 return encoder.call(this, value, encode);
51 } : encode;
52
53 return this._pairs.map(function each(pair) {
54 return _encode(pair[0]) + '=' + _encode(pair[1]);
55 }, '').join('&');
56};
57
58export default AxiosURLSearchParams;
Note: See TracBrowser for help on using the repository browser.