filepond
Version:
FilePond, where files go to stretch their bits.
133 lines (132 loc) • 3.03 kB
JavaScript
/*!
* FilePond v5.0.2
* Copyright (c) 2017-2026 Pqina B.V.
* Released under the MIT License
* https://filepond.com
*/
import { toKebabCase as v, toCamelCase as C } from "./string.js";
import { toURL as L } from "./url.js";
import { noop as P } from "./placeholder.js";
import { thread as U, createThreadWorker as y } from "./thread.js";
import { arrayRemoveFalsy as $ } from "./array.js";
import { httpRequest as d } from "../workers/httpRequest.js";
function T(r, t) {
const {
method: e,
queryString: n,
headers: s,
data: a,
formData: m,
responseType: g,
withCredentials: R,
timeout: w,
useWebWorkers: F = !1,
workersURL: H,
signal: l,
onprogress: q = P
} = t ?? {}, p = {
url: E(r, n),
responseType: g,
method: e,
headers: Object.entries(s ?? {}).map(([i, u]) => [
v(i),
`${u}`
]),
data: a,
formData: m,
timeout: w,
withCredentials: R
}, f = { onprogress: q, signal: l };
function h(i) {
return new Promise((u, o) => {
i.then((c) => {
u({
getAllResponseHeaders: () => c.responseHeaders,
response: c.response
});
}).catch(o);
});
}
return h(
F ? (
// @ts-ignore fix types
U(y(H, d), [p], f)
) : new Promise(
(i, u) => (
// httpRequest()
d(
p,
(o, c) => {
if (o !== null) {
u(o === l?.reason ? o : new Error(`${o}`));
return;
}
i(c);
},
f
)
)
)
);
}
function E(r, t = {}) {
const e = L(r);
return Object.entries(t).forEach(
([n, s]) => e.searchParams.append(n, `${s}`)
), `${e}`;
}
function j(r, t, e) {
return new ProgressEvent("progress", {
lengthComputable: r || !1,
loaded: r ? t && e === 1 ? t * 100 : t : 0,
total: r ? e === 1 ? 100 : e : 0
});
}
function K(r) {
return r ? $(
r.getAllResponseHeaders().split(`
`).map((e) => {
const n = e.match(/(^.*?):/) || [], [s, a] = n;
if (!s)
return;
const m = e.replace(s, "").trim();
return [a, m];
})
).reduce(
(e, n) => {
const [s, a] = n;
return e[C(s)] = a, e;
},
{}
) : {};
}
function S(r) {
const { contentDisposition: t } = r;
return !t || !t.length ? null : b(t);
}
function W(r) {
try {
return decodeURI(r);
} catch {
return r;
}
}
function b(r) {
if (!r.toLowerCase().startsWith("attachment"))
return null;
const t = r.split(/filename=|filename\*=.+''/i).splice(1).map((e) => e.trim().replace(/^["']|[;"']{0,2}$/g, "")).filter((e) => e.length);
return t.length ? W(t[t.length - 1]) : null;
}
function V(r, t) {
const e = t.toLowerCase().split(`
`).find((n) => n.includes(r));
return e ? e.split(":")[1].trim() : void 0;
}
export {
j as createProgressEvent,
b as getFilenameFromContentDispositionHeader,
S as getFilenameFromResponseHeaders,
V as getResponseHeaderValue,
K as getResponseHeaders,
T as xhr
};