hanbiro-react16-sdk 1.0.19 → 1.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/components/ChatAIDraft/SettingPopper.js +5 -5
  2. package/dist/components/CountryFlag/flags/KRFlag.js +1 -1
  3. package/dist/hanbiro-react16-sdk.style.css +1 -1
  4. package/dist/hanbiro-react16-sdk.umd.js +2 -2
  5. package/dist/index.js +10 -10
  6. package/dist/utils/api.d.ts +9 -0
  7. package/dist/utils/api.js +55 -0
  8. package/package.json +9 -7
  9. package/dist/node_modules/axios/index.js +0 -38
  10. package/dist/node_modules/axios/lib/adapters/adapters.js +0 -71
  11. package/dist/node_modules/axios/lib/adapters/fetch.js +0 -272
  12. package/dist/node_modules/axios/lib/adapters/xhr.js +0 -153
  13. package/dist/node_modules/axios/lib/axios.js +0 -50
  14. package/dist/node_modules/axios/lib/cancel/CancelToken.js +0 -99
  15. package/dist/node_modules/axios/lib/cancel/CanceledError.js +0 -20
  16. package/dist/node_modules/axios/lib/cancel/isCancel.js +0 -6
  17. package/dist/node_modules/axios/lib/core/Axios.js +0 -220
  18. package/dist/node_modules/axios/lib/core/AxiosError.js +0 -76
  19. package/dist/node_modules/axios/lib/core/AxiosHeaders.js +0 -238
  20. package/dist/node_modules/axios/lib/core/InterceptorManager.js +0 -66
  21. package/dist/node_modules/axios/lib/core/buildFullPath.js +0 -12
  22. package/dist/node_modules/axios/lib/core/dispatchRequest.js +0 -48
  23. package/dist/node_modules/axios/lib/core/mergeConfig.js +0 -100
  24. package/dist/node_modules/axios/lib/core/settle.js +0 -20
  25. package/dist/node_modules/axios/lib/core/transformData.js +0 -17
  26. package/dist/node_modules/axios/lib/defaults/index.js +0 -120
  27. package/dist/node_modules/axios/lib/defaults/transitional.js +0 -9
  28. package/dist/node_modules/axios/lib/env/data.js +0 -4
  29. package/dist/node_modules/axios/lib/helpers/AxiosURLSearchParams.js +0 -34
  30. package/dist/node_modules/axios/lib/helpers/HttpStatusCode.js +0 -77
  31. package/dist/node_modules/axios/lib/helpers/bind.js +0 -8
  32. package/dist/node_modules/axios/lib/helpers/buildURL.js +0 -32
  33. package/dist/node_modules/axios/lib/helpers/combineURLs.js +0 -6
  34. package/dist/node_modules/axios/lib/helpers/composeSignals.js +0 -41
  35. package/dist/node_modules/axios/lib/helpers/cookies.js +0 -49
  36. package/dist/node_modules/axios/lib/helpers/formDataToJSON.js +0 -54
  37. package/dist/node_modules/axios/lib/helpers/isAbsoluteURL.js +0 -9
  38. package/dist/node_modules/axios/lib/helpers/isAxiosError.js +0 -7
  39. package/dist/node_modules/axios/lib/helpers/isURLSameOrigin.js +0 -11
  40. package/dist/node_modules/axios/lib/helpers/null.js +0 -4
  41. package/dist/node_modules/axios/lib/helpers/parseHeaders.js +0 -47
  42. package/dist/node_modules/axios/lib/helpers/parseProtocol.js +0 -7
  43. package/dist/node_modules/axios/lib/helpers/progressEventReducer.js +0 -44
  44. package/dist/node_modules/axios/lib/helpers/resolveConfig.js +0 -52
  45. package/dist/node_modules/axios/lib/helpers/speedometer.js +0 -36
  46. package/dist/node_modules/axios/lib/helpers/spread.js +0 -8
  47. package/dist/node_modules/axios/lib/helpers/throttle.js +0 -35
  48. package/dist/node_modules/axios/lib/helpers/toFormData.js +0 -120
  49. package/dist/node_modules/axios/lib/helpers/toURLEncodedForm.js +0 -33
  50. package/dist/node_modules/axios/lib/helpers/trackStream.js +0 -169
  51. package/dist/node_modules/axios/lib/helpers/validator.js +0 -70
  52. package/dist/node_modules/axios/lib/platform/browser/classes/Blob.js +0 -4
  53. package/dist/node_modules/axios/lib/platform/browser/classes/FormData.js +0 -4
  54. package/dist/node_modules/axios/lib/platform/browser/classes/URLSearchParams.js +0 -5
  55. package/dist/node_modules/axios/lib/platform/browser/index.js +0 -15
  56. package/dist/node_modules/axios/lib/platform/common/utils.js +0 -15
  57. package/dist/node_modules/axios/lib/platform/index.js +0 -22
  58. package/dist/node_modules/axios/lib/utils.js +0 -429
  59. package/dist/utils/axiosAPI.d.ts +0 -1
  60. package/dist/utils/axiosAPI.js +0 -89
@@ -1,77 +0,0 @@
1
- const HttpStatusCode = {
2
- Continue: 100,
3
- SwitchingProtocols: 101,
4
- Processing: 102,
5
- EarlyHints: 103,
6
- Ok: 200,
7
- Created: 201,
8
- Accepted: 202,
9
- NonAuthoritativeInformation: 203,
10
- NoContent: 204,
11
- ResetContent: 205,
12
- PartialContent: 206,
13
- MultiStatus: 207,
14
- AlreadyReported: 208,
15
- ImUsed: 226,
16
- MultipleChoices: 300,
17
- MovedPermanently: 301,
18
- Found: 302,
19
- SeeOther: 303,
20
- NotModified: 304,
21
- UseProxy: 305,
22
- Unused: 306,
23
- TemporaryRedirect: 307,
24
- PermanentRedirect: 308,
25
- BadRequest: 400,
26
- Unauthorized: 401,
27
- PaymentRequired: 402,
28
- Forbidden: 403,
29
- NotFound: 404,
30
- MethodNotAllowed: 405,
31
- NotAcceptable: 406,
32
- ProxyAuthenticationRequired: 407,
33
- RequestTimeout: 408,
34
- Conflict: 409,
35
- Gone: 410,
36
- LengthRequired: 411,
37
- PreconditionFailed: 412,
38
- PayloadTooLarge: 413,
39
- UriTooLong: 414,
40
- UnsupportedMediaType: 415,
41
- RangeNotSatisfiable: 416,
42
- ExpectationFailed: 417,
43
- ImATeapot: 418,
44
- MisdirectedRequest: 421,
45
- UnprocessableEntity: 422,
46
- Locked: 423,
47
- FailedDependency: 424,
48
- TooEarly: 425,
49
- UpgradeRequired: 426,
50
- PreconditionRequired: 428,
51
- TooManyRequests: 429,
52
- RequestHeaderFieldsTooLarge: 431,
53
- UnavailableForLegalReasons: 451,
54
- InternalServerError: 500,
55
- NotImplemented: 501,
56
- BadGateway: 502,
57
- ServiceUnavailable: 503,
58
- GatewayTimeout: 504,
59
- HttpVersionNotSupported: 505,
60
- VariantAlsoNegotiates: 506,
61
- InsufficientStorage: 507,
62
- LoopDetected: 508,
63
- NotExtended: 510,
64
- NetworkAuthenticationRequired: 511,
65
- WebServerIsDown: 521,
66
- ConnectionTimedOut: 522,
67
- OriginIsUnreachable: 523,
68
- TimeoutOccurred: 524,
69
- SslHandshakeFailed: 525,
70
- InvalidSslCertificate: 526
71
- };
72
- Object.entries(HttpStatusCode).forEach(([key, value]) => {
73
- HttpStatusCode[value] = key;
74
- });
75
- export {
76
- HttpStatusCode as default
77
- };
@@ -1,8 +0,0 @@
1
- function bind(fn, thisArg) {
2
- return function wrap() {
3
- return fn.apply(thisArg, arguments);
4
- };
5
- }
6
- export {
7
- bind as default
8
- };
@@ -1,32 +0,0 @@
1
- import utils from "../utils.js";
2
- import AxiosURLSearchParams from "./AxiosURLSearchParams.js";
3
- function encode(val) {
4
- return encodeURIComponent(val).replace(/%3A/gi, ":").replace(/%24/g, "$").replace(/%2C/gi, ",").replace(/%20/g, "+");
5
- }
6
- function buildURL(url, params, options) {
7
- if (!params) {
8
- return url;
9
- }
10
- const _encode = options && options.encode || encode;
11
- const _options = utils.isFunction(options) ? {
12
- serialize: options
13
- } : options;
14
- const serializeFn = _options && _options.serialize;
15
- let serializedParams;
16
- if (serializeFn) {
17
- serializedParams = serializeFn(params, _options);
18
- } else {
19
- serializedParams = utils.isURLSearchParams(params) ? params.toString() : new AxiosURLSearchParams(params, _options).toString(_encode);
20
- }
21
- if (serializedParams) {
22
- const hashmarkIndex = url.indexOf("#");
23
- if (hashmarkIndex !== -1) {
24
- url = url.slice(0, hashmarkIndex);
25
- }
26
- url += (url.indexOf("?") === -1 ? "?" : "&") + serializedParams;
27
- }
28
- return url;
29
- }
30
- export {
31
- buildURL as default
32
- };
@@ -1,6 +0,0 @@
1
- function combineURLs(baseURL, relativeURL) {
2
- return relativeURL ? baseURL.replace(/\/?\/$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
3
- }
4
- export {
5
- combineURLs as default
6
- };
@@ -1,41 +0,0 @@
1
- import CanceledError from "../cancel/CanceledError.js";
2
- import AxiosError from "../core/AxiosError.js";
3
- import utils from "../utils.js";
4
- const composeSignals = (signals, timeout) => {
5
- const { length } = signals = signals ? signals.filter(Boolean) : [];
6
- if (timeout || length) {
7
- let controller = new AbortController();
8
- let aborted;
9
- const onabort = function(reason) {
10
- if (!aborted) {
11
- aborted = true;
12
- unsubscribe();
13
- const err = reason instanceof Error ? reason : this.reason;
14
- controller.abort(
15
- err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err)
16
- );
17
- }
18
- };
19
- let timer = timeout && setTimeout(() => {
20
- timer = null;
21
- onabort(new AxiosError(`timeout of ${timeout}ms exceeded`, AxiosError.ETIMEDOUT));
22
- }, timeout);
23
- const unsubscribe = () => {
24
- if (signals) {
25
- timer && clearTimeout(timer);
26
- timer = null;
27
- signals.forEach((signal2) => {
28
- signal2.unsubscribe ? signal2.unsubscribe(onabort) : signal2.removeEventListener("abort", onabort);
29
- });
30
- signals = null;
31
- }
32
- };
33
- signals.forEach((signal2) => signal2.addEventListener("abort", onabort));
34
- const { signal } = controller;
35
- signal.unsubscribe = () => utils.asap(unsubscribe);
36
- return signal;
37
- }
38
- };
39
- export {
40
- composeSignals as default
41
- };
@@ -1,49 +0,0 @@
1
- import utils from "../utils.js";
2
- import platform from "../platform/index.js";
3
- const cookies = platform.hasStandardBrowserEnv ? (
4
- // Standard browser envs support document.cookie
5
- {
6
- write(name, value, expires, path, domain, secure, sameSite) {
7
- if (typeof document === "undefined") return;
8
- const cookie = [`${name}=${encodeURIComponent(value)}`];
9
- if (utils.isNumber(expires)) {
10
- cookie.push(`expires=${new Date(expires).toUTCString()}`);
11
- }
12
- if (utils.isString(path)) {
13
- cookie.push(`path=${path}`);
14
- }
15
- if (utils.isString(domain)) {
16
- cookie.push(`domain=${domain}`);
17
- }
18
- if (secure === true) {
19
- cookie.push("secure");
20
- }
21
- if (utils.isString(sameSite)) {
22
- cookie.push(`SameSite=${sameSite}`);
23
- }
24
- document.cookie = cookie.join("; ");
25
- },
26
- read(name) {
27
- if (typeof document === "undefined") return null;
28
- const match = document.cookie.match(new RegExp("(?:^|; )" + name + "=([^;]*)"));
29
- return match ? decodeURIComponent(match[1]) : null;
30
- },
31
- remove(name) {
32
- this.write(name, "", Date.now() - 864e5, "/");
33
- }
34
- }
35
- ) : (
36
- // Non-standard browser env (web workers, react-native) lack needed support.
37
- {
38
- write() {
39
- },
40
- read() {
41
- return null;
42
- },
43
- remove() {
44
- }
45
- }
46
- );
47
- export {
48
- cookies as default
49
- };
@@ -1,54 +0,0 @@
1
- import utils from "../utils.js";
2
- function parsePropPath(name) {
3
- return utils.matchAll(/\w+|\[(\w*)]/g, name).map((match) => {
4
- return match[0] === "[]" ? "" : match[1] || match[0];
5
- });
6
- }
7
- function arrayToObject(arr) {
8
- const obj = {};
9
- const keys = Object.keys(arr);
10
- let i;
11
- const len = keys.length;
12
- let key;
13
- for (i = 0; i < len; i++) {
14
- key = keys[i];
15
- obj[key] = arr[key];
16
- }
17
- return obj;
18
- }
19
- function formDataToJSON(formData) {
20
- function buildPath(path, value, target, index) {
21
- let name = path[index++];
22
- if (name === "__proto__") return true;
23
- const isNumericKey = Number.isFinite(+name);
24
- const isLast = index >= path.length;
25
- name = !name && utils.isArray(target) ? target.length : name;
26
- if (isLast) {
27
- if (utils.hasOwnProp(target, name)) {
28
- target[name] = [target[name], value];
29
- } else {
30
- target[name] = value;
31
- }
32
- return !isNumericKey;
33
- }
34
- if (!target[name] || !utils.isObject(target[name])) {
35
- target[name] = [];
36
- }
37
- const result = buildPath(path, value, target[name], index);
38
- if (result && utils.isArray(target[name])) {
39
- target[name] = arrayToObject(target[name]);
40
- }
41
- return !isNumericKey;
42
- }
43
- if (utils.isFormData(formData) && utils.isFunction(formData.entries)) {
44
- const obj = {};
45
- utils.forEachEntry(formData, (name, value) => {
46
- buildPath(parsePropPath(name), value, obj, 0);
47
- });
48
- return obj;
49
- }
50
- return null;
51
- }
52
- export {
53
- formDataToJSON as default
54
- };
@@ -1,9 +0,0 @@
1
- function isAbsoluteURL(url) {
2
- if (typeof url !== "string") {
3
- return false;
4
- }
5
- return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
6
- }
7
- export {
8
- isAbsoluteURL as default
9
- };
@@ -1,7 +0,0 @@
1
- import utils from "../utils.js";
2
- function isAxiosError(payload) {
3
- return utils.isObject(payload) && payload.isAxiosError === true;
4
- }
5
- export {
6
- isAxiosError as default
7
- };
@@ -1,11 +0,0 @@
1
- import platform from "../platform/index.js";
2
- const isURLSameOrigin = platform.hasStandardBrowserEnv ? /* @__PURE__ */ ((origin, isMSIE) => (url) => {
3
- url = new URL(url, platform.origin);
4
- return origin.protocol === url.protocol && origin.host === url.host && (isMSIE || origin.port === url.port);
5
- })(
6
- new URL(platform.origin),
7
- platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent)
8
- ) : () => true;
9
- export {
10
- isURLSameOrigin as default
11
- };
@@ -1,4 +0,0 @@
1
- const httpAdapter = null;
2
- export {
3
- httpAdapter as default
4
- };
@@ -1,47 +0,0 @@
1
- import utils from "../utils.js";
2
- const ignoreDuplicateOf = utils.toObjectSet([
3
- "age",
4
- "authorization",
5
- "content-length",
6
- "content-type",
7
- "etag",
8
- "expires",
9
- "from",
10
- "host",
11
- "if-modified-since",
12
- "if-unmodified-since",
13
- "last-modified",
14
- "location",
15
- "max-forwards",
16
- "proxy-authorization",
17
- "referer",
18
- "retry-after",
19
- "user-agent"
20
- ]);
21
- const parseHeaders = (rawHeaders) => {
22
- const parsed = {};
23
- let key;
24
- let val;
25
- let i;
26
- rawHeaders && rawHeaders.split("\n").forEach(function parser(line) {
27
- i = line.indexOf(":");
28
- key = line.substring(0, i).trim().toLowerCase();
29
- val = line.substring(i + 1).trim();
30
- if (!key || parsed[key] && ignoreDuplicateOf[key]) {
31
- return;
32
- }
33
- if (key === "set-cookie") {
34
- if (parsed[key]) {
35
- parsed[key].push(val);
36
- } else {
37
- parsed[key] = [val];
38
- }
39
- } else {
40
- parsed[key] = parsed[key] ? parsed[key] + ", " + val : val;
41
- }
42
- });
43
- return parsed;
44
- };
45
- export {
46
- parseHeaders as default
47
- };
@@ -1,7 +0,0 @@
1
- function parseProtocol(url) {
2
- const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
3
- return match && match[1] || "";
4
- }
5
- export {
6
- parseProtocol as default
7
- };
@@ -1,44 +0,0 @@
1
- import speedometer from "./speedometer.js";
2
- import throttle from "./throttle.js";
3
- import utils from "../utils.js";
4
- const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
5
- let bytesNotified = 0;
6
- const _speedometer = speedometer(50, 250);
7
- return throttle((e) => {
8
- const loaded = e.loaded;
9
- const total = e.lengthComputable ? e.total : void 0;
10
- const progressBytes = loaded - bytesNotified;
11
- const rate = _speedometer(progressBytes);
12
- const inRange = loaded <= total;
13
- bytesNotified = loaded;
14
- const data = {
15
- loaded,
16
- total,
17
- progress: total ? loaded / total : void 0,
18
- bytes: progressBytes,
19
- rate: rate ? rate : void 0,
20
- estimated: rate && total && inRange ? (total - loaded) / rate : void 0,
21
- event: e,
22
- lengthComputable: total != null,
23
- [isDownloadStream ? "download" : "upload"]: true
24
- };
25
- listener(data);
26
- }, freq);
27
- };
28
- const progressEventDecorator = (total, throttled) => {
29
- const lengthComputable = total != null;
30
- return [
31
- (loaded) => throttled[0]({
32
- lengthComputable,
33
- total,
34
- loaded
35
- }),
36
- throttled[1]
37
- ];
38
- };
39
- const asyncDecorator = (fn) => (...args) => utils.asap(() => fn(...args));
40
- export {
41
- asyncDecorator,
42
- progressEventDecorator,
43
- progressEventReducer
44
- };
@@ -1,52 +0,0 @@
1
- import platform from "../platform/index.js";
2
- import utils from "../utils.js";
3
- import isURLSameOrigin from "./isURLSameOrigin.js";
4
- import cookies from "./cookies.js";
5
- import buildFullPath from "../core/buildFullPath.js";
6
- import mergeConfig from "../core/mergeConfig.js";
7
- import AxiosHeaders from "../core/AxiosHeaders.js";
8
- import buildURL from "./buildURL.js";
9
- const resolveConfig = (config) => {
10
- const newConfig = mergeConfig({}, config);
11
- let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
12
- newConfig.headers = headers = AxiosHeaders.from(headers);
13
- newConfig.url = buildURL(
14
- buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls),
15
- config.params,
16
- config.paramsSerializer
17
- );
18
- if (auth) {
19
- headers.set(
20
- "Authorization",
21
- "Basic " + btoa(
22
- (auth.username || "") + ":" + (auth.password ? unescape(encodeURIComponent(auth.password)) : "")
23
- )
24
- );
25
- }
26
- if (utils.isFormData(data)) {
27
- if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
28
- headers.setContentType(void 0);
29
- } else if (utils.isFunction(data.getHeaders)) {
30
- const formHeaders = data.getHeaders();
31
- const allowedHeaders = ["content-type", "content-length"];
32
- Object.entries(formHeaders).forEach(([key, val]) => {
33
- if (allowedHeaders.includes(key.toLowerCase())) {
34
- headers.set(key, val);
35
- }
36
- });
37
- }
38
- }
39
- if (platform.hasStandardBrowserEnv) {
40
- withXSRFToken && utils.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
41
- if (withXSRFToken || withXSRFToken !== false && isURLSameOrigin(newConfig.url)) {
42
- const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
43
- if (xsrfValue) {
44
- headers.set(xsrfHeaderName, xsrfValue);
45
- }
46
- }
47
- }
48
- return newConfig;
49
- };
50
- export {
51
- resolveConfig as default
52
- };
@@ -1,36 +0,0 @@
1
- function speedometer(samplesCount, min) {
2
- samplesCount = samplesCount || 10;
3
- const bytes = new Array(samplesCount);
4
- const timestamps = new Array(samplesCount);
5
- let head = 0;
6
- let tail = 0;
7
- let firstSampleTS;
8
- min = min !== void 0 ? min : 1e3;
9
- return function push(chunkLength) {
10
- const now = Date.now();
11
- const startedAt = timestamps[tail];
12
- if (!firstSampleTS) {
13
- firstSampleTS = now;
14
- }
15
- bytes[head] = chunkLength;
16
- timestamps[head] = now;
17
- let i = tail;
18
- let bytesCount = 0;
19
- while (i !== head) {
20
- bytesCount += bytes[i++];
21
- i = i % samplesCount;
22
- }
23
- head = (head + 1) % samplesCount;
24
- if (head === tail) {
25
- tail = (tail + 1) % samplesCount;
26
- }
27
- if (now - firstSampleTS < min) {
28
- return;
29
- }
30
- const passed = startedAt && now - startedAt;
31
- return passed ? Math.round(bytesCount * 1e3 / passed) : void 0;
32
- };
33
- }
34
- export {
35
- speedometer as default
36
- };
@@ -1,8 +0,0 @@
1
- function spread(callback) {
2
- return function wrap(arr) {
3
- return callback.apply(null, arr);
4
- };
5
- }
6
- export {
7
- spread as default
8
- };
@@ -1,35 +0,0 @@
1
- function throttle(fn, freq) {
2
- let timestamp = 0;
3
- let threshold = 1e3 / freq;
4
- let lastArgs;
5
- let timer;
6
- const invoke = (args, now = Date.now()) => {
7
- timestamp = now;
8
- lastArgs = null;
9
- if (timer) {
10
- clearTimeout(timer);
11
- timer = null;
12
- }
13
- fn(...args);
14
- };
15
- const throttled = (...args) => {
16
- const now = Date.now();
17
- const passed = now - timestamp;
18
- if (passed >= threshold) {
19
- invoke(args, now);
20
- } else {
21
- lastArgs = args;
22
- if (!timer) {
23
- timer = setTimeout(() => {
24
- timer = null;
25
- invoke(lastArgs);
26
- }, threshold - passed);
27
- }
28
- }
29
- };
30
- const flush = () => lastArgs && invoke(lastArgs);
31
- return [throttled, flush];
32
- }
33
- export {
34
- throttle as default
35
- };
@@ -1,120 +0,0 @@
1
- import utils from "../utils.js";
2
- import AxiosError from "../core/AxiosError.js";
3
- function isVisitable(thing) {
4
- return utils.isPlainObject(thing) || utils.isArray(thing);
5
- }
6
- function removeBrackets(key) {
7
- return utils.endsWith(key, "[]") ? key.slice(0, -2) : key;
8
- }
9
- function renderKey(path, key, dots) {
10
- if (!path) return key;
11
- return path.concat(key).map(function each(token, i) {
12
- token = removeBrackets(token);
13
- return !dots && i ? "[" + token + "]" : token;
14
- }).join(dots ? "." : "");
15
- }
16
- function isFlatArray(arr) {
17
- return utils.isArray(arr) && !arr.some(isVisitable);
18
- }
19
- const predicates = utils.toFlatObject(utils, {}, null, function filter(prop) {
20
- return /^is[A-Z]/.test(prop);
21
- });
22
- function toFormData(obj, formData, options) {
23
- if (!utils.isObject(obj)) {
24
- throw new TypeError("target must be an object");
25
- }
26
- formData = formData || new FormData();
27
- options = utils.toFlatObject(
28
- options,
29
- {
30
- metaTokens: true,
31
- dots: false,
32
- indexes: false
33
- },
34
- false,
35
- function defined(option, source) {
36
- return !utils.isUndefined(source[option]);
37
- }
38
- );
39
- const metaTokens = options.metaTokens;
40
- const visitor = options.visitor || defaultVisitor;
41
- const dots = options.dots;
42
- const indexes = options.indexes;
43
- const _Blob = options.Blob || typeof Blob !== "undefined" && Blob;
44
- const useBlob = _Blob && utils.isSpecCompliantForm(formData);
45
- if (!utils.isFunction(visitor)) {
46
- throw new TypeError("visitor must be a function");
47
- }
48
- function convertValue(value) {
49
- if (value === null) return "";
50
- if (utils.isDate(value)) {
51
- return value.toISOString();
52
- }
53
- if (utils.isBoolean(value)) {
54
- return value.toString();
55
- }
56
- if (!useBlob && utils.isBlob(value)) {
57
- throw new AxiosError("Blob is not supported. Use a Buffer instead.");
58
- }
59
- if (utils.isArrayBuffer(value) || utils.isTypedArray(value)) {
60
- return useBlob && typeof Blob === "function" ? new Blob([value]) : Buffer.from(value);
61
- }
62
- return value;
63
- }
64
- function defaultVisitor(value, key, path) {
65
- let arr = value;
66
- if (utils.isReactNative(formData) && utils.isReactNativeBlob(value)) {
67
- formData.append(renderKey(path, key, dots), convertValue(value));
68
- return false;
69
- }
70
- if (value && !path && typeof value === "object") {
71
- if (utils.endsWith(key, "{}")) {
72
- key = metaTokens ? key : key.slice(0, -2);
73
- value = JSON.stringify(value);
74
- } else if (utils.isArray(value) && isFlatArray(value) || (utils.isFileList(value) || utils.endsWith(key, "[]")) && (arr = utils.toArray(value))) {
75
- key = removeBrackets(key);
76
- arr.forEach(function each(el, index) {
77
- !(utils.isUndefined(el) || el === null) && formData.append(
78
- // eslint-disable-next-line no-nested-ternary
79
- indexes === true ? renderKey([key], index, dots) : indexes === null ? key : key + "[]",
80
- convertValue(el)
81
- );
82
- });
83
- return false;
84
- }
85
- }
86
- if (isVisitable(value)) {
87
- return true;
88
- }
89
- formData.append(renderKey(path, key, dots), convertValue(value));
90
- return false;
91
- }
92
- const stack = [];
93
- const exposedHelpers = Object.assign(predicates, {
94
- defaultVisitor,
95
- convertValue,
96
- isVisitable
97
- });
98
- function build(value, path) {
99
- if (utils.isUndefined(value)) return;
100
- if (stack.indexOf(value) !== -1) {
101
- throw Error("Circular reference detected in " + path.join("."));
102
- }
103
- stack.push(value);
104
- utils.forEach(value, function each(el, key) {
105
- const result = !(utils.isUndefined(el) || el === null) && visitor.call(formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers);
106
- if (result === true) {
107
- build(el, path ? path.concat(key) : [key]);
108
- }
109
- });
110
- stack.pop();
111
- }
112
- if (!utils.isObject(obj)) {
113
- throw new TypeError("data must be an object");
114
- }
115
- build(obj);
116
- return formData;
117
- }
118
- export {
119
- toFormData as default
120
- };