@zag-js/file-utils 1.34.0 → 1.35.0
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.
- package/dist/data-transfer.d.mts +3 -0
- package/dist/data-transfer.d.ts +3 -0
- package/dist/data-transfer.js +83 -0
- package/dist/data-transfer.mjs +58 -0
- package/dist/data-url-to-blob.d.mts +3 -0
- package/dist/data-url-to-blob.d.ts +3 -0
- package/dist/data-url-to-blob.js +39 -0
- package/dist/data-url-to-blob.mjs +14 -0
- package/dist/download-file.d.mts +33 -0
- package/dist/download-file.d.ts +33 -0
- package/dist/download-file.js +81 -0
- package/dist/download-file.mjs +56 -0
- package/dist/get-accept-attr.d.mts +3 -0
- package/dist/get-accept-attr.d.ts +3 -0
- package/dist/get-accept-attr.js +46 -0
- package/dist/get-accept-attr.mjs +21 -0
- package/dist/get-file-data-url.d.mts +3 -0
- package/dist/get-file-data-url.d.ts +3 -0
- package/dist/get-file-data-url.js +47 -0
- package/dist/get-file-data-url.mjs +22 -0
- package/dist/get-file-mime-type.d.mts +5 -0
- package/dist/get-file-mime-type.d.ts +5 -0
- package/dist/get-file-mime-type.js +34 -0
- package/dist/get-file-mime-type.mjs +9 -0
- package/dist/get-total-file-size.d.mts +3 -0
- package/dist/get-total-file-size.d.ts +3 -0
- package/dist/get-total-file-size.js +32 -0
- package/dist/get-total-file-size.mjs +7 -0
- package/dist/index.d.mts +11 -62
- package/dist/index.d.ts +11 -62
- package/dist/index.js +40 -238
- package/dist/index.mjs +11 -229
- package/dist/is-file-equal.d.mts +3 -0
- package/dist/is-file-equal.d.ts +3 -0
- package/dist/is-file-equal.js +32 -0
- package/dist/is-file-equal.mjs +7 -0
- package/dist/is-valid-file-size.d.mts +5 -0
- package/dist/is-valid-file-size.d.ts +5 -0
- package/dist/is-valid-file-size.js +43 -0
- package/dist/is-valid-file-size.mjs +18 -0
- package/dist/is-valid-file-type.d.mts +5 -0
- package/dist/is-valid-file-type.d.ts +5 -0
- package/dist/is-valid-file-type.js +54 -0
- package/dist/is-valid-file-type.mjs +29 -0
- package/dist/mime-types.d.mts +4 -0
- package/dist/mime-types.d.ts +4 -0
- package/dist/mime-types.js +38 -0
- package/dist/mime-types.mjs +12 -0
- package/dist/types.d.mts +12 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +0 -0
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,229 +1,11 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (!entry) return null;
|
|
13
|
-
if (isDirectoryEntry(entry) && traverseDirectories) {
|
|
14
|
-
return getDirectoryFiles(entry.createReader(), `${entry.name}`);
|
|
15
|
-
}
|
|
16
|
-
if (isFileEntry(entry) && typeof item.getAsFile === "function") {
|
|
17
|
-
const file = item.getAsFile();
|
|
18
|
-
return Promise.resolve(file ? addRelativePath(file, "") : null);
|
|
19
|
-
}
|
|
20
|
-
if (isFileEntry(entry)) {
|
|
21
|
-
return new Promise((resolve) => {
|
|
22
|
-
entry.file((file) => {
|
|
23
|
-
resolve(addRelativePath(file, ""));
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}).filter((b) => b)
|
|
28
|
-
);
|
|
29
|
-
var getDirectoryFiles = (reader, path = "") => new Promise((resolve) => {
|
|
30
|
-
const entryPromises = [];
|
|
31
|
-
const readDirectoryEntries = () => {
|
|
32
|
-
reader.readEntries((entries) => {
|
|
33
|
-
if (entries.length === 0) {
|
|
34
|
-
resolve(Promise.all(entryPromises).then((entries2) => entries2.flat()));
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const promises = entries.map((entry) => {
|
|
38
|
-
if (!entry) return null;
|
|
39
|
-
if (isDirectoryEntry(entry)) {
|
|
40
|
-
return getDirectoryFiles(entry.createReader(), `${path}${entry.name}`);
|
|
41
|
-
}
|
|
42
|
-
if (isFileEntry(entry)) {
|
|
43
|
-
return new Promise((resolve2) => {
|
|
44
|
-
entry.file((file) => {
|
|
45
|
-
resolve2(addRelativePath(file, path));
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}).filter((b) => b);
|
|
50
|
-
entryPromises.push(Promise.all(promises));
|
|
51
|
-
readDirectoryEntries();
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
readDirectoryEntries();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// src/data-url-to-blob.ts
|
|
58
|
-
function dataURItoBlob(uri) {
|
|
59
|
-
const binary = atob(uri.split(",")[1]);
|
|
60
|
-
const mimeString = uri.split(",")[0].split(":")[1].split(";")[0];
|
|
61
|
-
const buffer = new ArrayBuffer(binary.length);
|
|
62
|
-
const intArray = new Uint8Array(buffer);
|
|
63
|
-
for (let i = 0; i < binary.length; i++) {
|
|
64
|
-
intArray[i] = binary.charCodeAt(i);
|
|
65
|
-
}
|
|
66
|
-
return new Blob([buffer], { type: mimeString });
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// src/download-file.ts
|
|
70
|
-
var BOM_REGEX = /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i;
|
|
71
|
-
var MAC_REGEX = /Macintosh/;
|
|
72
|
-
var APPLE_WEBKIT_REGEX = /AppleWebKit/;
|
|
73
|
-
var SAFARI_REGEX = /Safari/;
|
|
74
|
-
function getBlob(blobOrString, type, appendBOM) {
|
|
75
|
-
let blob = typeof blobOrString === "string" ? new Blob([blobOrString], { type }) : blobOrString;
|
|
76
|
-
if (appendBOM && BOM_REGEX.test(blob.type)) {
|
|
77
|
-
return new Blob([String.fromCharCode(65279), blob], { type: blob.type });
|
|
78
|
-
}
|
|
79
|
-
return blob;
|
|
80
|
-
}
|
|
81
|
-
function isMSEdge(win) {
|
|
82
|
-
return Boolean(win.navigator && win.navigator.msSaveOrOpenBlob);
|
|
83
|
-
}
|
|
84
|
-
function isWebView(win) {
|
|
85
|
-
return win.navigator && MAC_REGEX.test(win.navigator.userAgent) && APPLE_WEBKIT_REGEX.test(win.navigator.userAgent) && !SAFARI_REGEX.test(win.navigator.userAgent);
|
|
86
|
-
}
|
|
87
|
-
function downloadFile(options) {
|
|
88
|
-
const { file, win = window, type, name, appendBOM, revokeTimeout = 0 } = options;
|
|
89
|
-
const doc = win.document;
|
|
90
|
-
const blob = getBlob(file, type, appendBOM);
|
|
91
|
-
const fileName = (file instanceof File ? name || file.name : name) || "file-download";
|
|
92
|
-
if (isMSEdge(win)) {
|
|
93
|
-
win.navigator.msSaveOrOpenBlob(blob, fileName);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const isMacOSWebView = isWebView(win);
|
|
97
|
-
const anchor = doc.createElement("a");
|
|
98
|
-
const canUseDownload = "download" in anchor && !isMacOSWebView;
|
|
99
|
-
if (canUseDownload) {
|
|
100
|
-
const url2 = win.URL.createObjectURL(blob);
|
|
101
|
-
anchor.href = url2;
|
|
102
|
-
anchor.rel = "noopener";
|
|
103
|
-
anchor.download = fileName;
|
|
104
|
-
anchor.style.display = "none";
|
|
105
|
-
doc.body.appendChild(anchor);
|
|
106
|
-
anchor.dispatchEvent(new win.MouseEvent("click"));
|
|
107
|
-
setTimeout(() => {
|
|
108
|
-
win.URL.revokeObjectURL(url2);
|
|
109
|
-
anchor.remove();
|
|
110
|
-
}, revokeTimeout);
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
const url = win.URL.createObjectURL(blob);
|
|
114
|
-
const popup = win.open(url, "_blank");
|
|
115
|
-
if (!popup) {
|
|
116
|
-
win.location.href = url;
|
|
117
|
-
}
|
|
118
|
-
setTimeout(() => {
|
|
119
|
-
win.URL.revokeObjectURL(url);
|
|
120
|
-
}, revokeTimeout);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// src/get-accept-attr.ts
|
|
124
|
-
function isMIMEType(v) {
|
|
125
|
-
return v === "audio/*" || v === "video/*" || v === "image/*" || v === "text/*" || /\w+\/[-+.\w]+/g.test(v);
|
|
126
|
-
}
|
|
127
|
-
function isExt(v) {
|
|
128
|
-
return /^.*\.[\w]+$/.test(v);
|
|
129
|
-
}
|
|
130
|
-
var isValidMIME = (v) => isMIMEType(v) || isExt(v);
|
|
131
|
-
function getAcceptAttrString(accept) {
|
|
132
|
-
if (accept == null) return;
|
|
133
|
-
if (typeof accept === "string") {
|
|
134
|
-
return accept;
|
|
135
|
-
}
|
|
136
|
-
if (Array.isArray(accept)) {
|
|
137
|
-
return accept.filter(isValidMIME).join(",");
|
|
138
|
-
}
|
|
139
|
-
return Object.entries(accept).reduce((a, [mimeType, ext]) => [...a, mimeType, ...ext], []).filter(isValidMIME).join(",");
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// src/get-file-data-url.ts
|
|
143
|
-
var getFileDataUrl = async (file) => {
|
|
144
|
-
const reader = new FileReader();
|
|
145
|
-
return new Promise((resolve, reject) => {
|
|
146
|
-
reader.onerror = () => {
|
|
147
|
-
reader.abort();
|
|
148
|
-
reject(new Error("There was an error reading a file"));
|
|
149
|
-
};
|
|
150
|
-
reader.onloadend = () => {
|
|
151
|
-
const { result } = reader;
|
|
152
|
-
if (result instanceof ArrayBuffer) {
|
|
153
|
-
reject(new Error("Expected DataURL as string from Blob/File, got ArrayBuffer"));
|
|
154
|
-
} else {
|
|
155
|
-
resolve(result || void 0);
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
reader.readAsDataURL(file);
|
|
159
|
-
});
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
// src/get-total-file-size.ts
|
|
163
|
-
var getTotalFileSize = (files) => {
|
|
164
|
-
return files.reduce((acc, file) => acc + file.size, 0);
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
// src/is-file-equal.ts
|
|
168
|
-
var isFileEqual = (file1, file2) => {
|
|
169
|
-
return file1.name === file2.name && file1.size === file2.size && file1.type === file2.type;
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
// src/is-valid-file-size.ts
|
|
173
|
-
var isDefined = (v) => v !== void 0 && v !== null;
|
|
174
|
-
function isValidFileSize(file, minSize, maxSize) {
|
|
175
|
-
if (isDefined(file.size)) {
|
|
176
|
-
if (isDefined(minSize) && isDefined(maxSize)) {
|
|
177
|
-
if (file.size > maxSize) return [false, "FILE_TOO_LARGE"];
|
|
178
|
-
if (file.size < minSize) return [false, "FILE_TOO_SMALL"];
|
|
179
|
-
} else if (isDefined(minSize) && file.size < minSize) {
|
|
180
|
-
return [false, "FILE_TOO_SMALL"];
|
|
181
|
-
} else if (isDefined(maxSize) && file.size > maxSize) {
|
|
182
|
-
return [false, "FILE_TOO_LARGE"];
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return [true, null];
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// src/mime-types.ts
|
|
189
|
-
var mimeTypes = "3g2_video/3gpp2[3gp,3gpp_video/3gpp[3mf_model/3mf[7z_application/x-7z-compressed[aac_audio/aac[ac_application/pkix-attr-cert[adp_audio/adpcm[adts_audio/aac[ai_application/postscript[aml_application/automationml-aml+xml[amlx_application/automationml-amlx+zip[amr_audio/amr[apk_application/vnd.android.package-archive[apng_image/apng[appcache,manifest_text/cache-manifest[appinstaller_application/appinstaller[appx_application/appx[appxbundle_application/appxbundle[asc_application/pgp-keys[atom_application/atom+xml[atomcat_application/atomcat+xml[atomdeleted_application/atomdeleted+xml[atomsvc_application/atomsvc+xml[au,snd_audio/basic[avi_video/x-msvideo[avci_image/avci[avcs_image/avcs[avif_image/avif[aw_application/applixware[bdoc_application/bdoc[bin,bpk,buffer,deb,deploy,dist,distz,dll,dmg,dms,dump,elc,exe,img,iso,lrf,mar,msi,msm,msp,pkg,so_application/octet-stream[bmp,dib_image/bmp[btf,btif_image/prs.btif[bz2_application/x-bzip2[c_text/x-c[ccxml_application/ccxml+xml[cdfx_application/cdfx+xml[cdmia_application/cdmi-capability[cdmic_application/cdmi-container[cdmid_application/cdmi-domain[cdmio_application/cdmi-object[cdmiq_application/cdmi-queue[cer_application/pkix-cert[cgm_image/cgm[cjs_application/node[class_application/java-vm[coffee,litcoffee_text/coffeescript[conf,def,in,ini,list,log,text,txt_text/plain[cpp,cxx,cc_text/x-c++src[cpl_application/cpl+xml[cpt_application/mac-compactpro[crl_application/pkix-crl[css_text/css[csv_text/csv[cu_application/cu-seeme[cwl_application/cwl[cww_application/prs.cww[davmount_application/davmount+xml[dbk_application/docbook+xml[doc_application/msword[docx_application/vnd.openxmlformats-officedocument.wordprocessingml.document[dsc_text/prs.lines.tag[dssc_application/dssc+der[dtd_application/xml-dtd[dwd_application/atsc-dwd+xml[ear,jar,war_application/java-archive[ecma_application/ecmascript[emf_image/emf[eml,mime_message/rfc822[emma_application/emma+xml[emotionml_application/emotionml+xml[eot_application/vnd.ms-fontobject[eps,ps_application/postscript[epub_application/epub+zip[exi_application/exi[exp_application/express[exr_image/aces[ez_application/andrew-inset[fdf_application/fdf[fdt_application/fdt+xml[fits_image/fits[flac_audio/flac[flv_video/x-flv[g3_image/g3fax[geojson_application/geo+json[gif_image/gif[glb_model/gltf-binary[gltf_model/gltf+json[gml_application/gml+xml[go_text/x-go[gpx_application/gpx+xml[gz_application/gzip[h_text/x-h[h261_video/h261[h263_video/h263[h264_video/h264[heic_image/heic[heics_image/heic-sequence[heif_image/heif[heifs_image/heif-sequence[htm,html,shtml_text/html[ico_image/x-icon[icns_image/x-icns[ics,ifb_text/calendar[iges,igs_model/iges[ink,inkml_application/inkml+xml[ipa_application/octet-stream[java_text/x-java-source[jp2,jpg2_image/jp2[jpeg,jpe,jpg_image/jpeg[jpf,jpx_image/jpx[jpm,jpgm_image/jpm[jpgv_video/jpeg[jph_image/jph[js,mjs_text/javascript[json_application/json[json5_application/json5[jsonld_application/ld+json[jsx_text/jsx[jxl_image/jxl[jxr_image/jxr[ktx_image/ktx[ktx2_image/ktx2[less_text/less[m1v,m2v,mpe,mpeg,mpg_video/mpeg[m4a_audio/mp4[m4v_video/x-m4v[md,markdown_text/markdown[mid,midi,kar,rmi_audio/midi[mkv_video/x-matroska[mp2,mp2a,mp3,mpga,m3a,m2a_audio/mpeg[mp4,mp4v,mpg4_video/mp4[mp4a_audio/mp4[mp4s,m4p_application/mp4[odp_application/vnd.oasis.opendocument.presentation[oda_application/oda[ods_application/vnd.oasis.opendocument.spreadsheet[odt_application/vnd.oasis.opendocument.text[oga,ogg,opus,spx_audio/ogg[ogv_video/ogg[ogx_application/ogg[otf_font/otf[p12,pfx_application/x-pkcs12[pdf_application/pdf[pem_application/x-pem-file[php_text/x-php[png_image/png[ppt_application/vnd.ms-powerpoint[pptx_application/vnd.openxmlformats-officedocument.presentationml.presentation[pskcxml_application/pskc+xml[psd_image/vnd.adobe.photoshop[py_text/x-python[qt,mov_video/quicktime[rar_application/vnd.rar[rdf_application/rdf+xml[rtf_text/rtf[sass_text/x-sass[scss_text/x-scss[sgm,sgml_text/sgml[sh_application/x-sh[svg,svgz_image/svg+xml[swf_application/x-shockwave-flash[tar_application/x-tar[tif,tiff_image/tiff[toml_application/toml[ts_video/mp2t[tsx_text/tsx[tsv_text/tab-separated-values[ttc_font/collection[ttf_font/ttf[vtt_text/vtt[wasm_application/wasm[wav_audio/wav[weba_audio/webm[webm_video/webm[webmanifest_application/manifest+json[webp_image/webp[wma_audio/x-ms-wma[wmv_video/x-ms-wmv[woff_font/woff[woff2_font/woff2[xls_application/vnd.ms-excel[xlsx_application/vnd.openxmlformats-officedocument.spreadsheetml.sheet[xml_application/xml[xz_application/x-xz[yaml,yml_text/yaml[zip_application/zip";
|
|
190
|
-
var mimeTypesMap = new Map(
|
|
191
|
-
mimeTypes.split("[").flatMap((mime) => {
|
|
192
|
-
const [extensions, mimeType] = mime.split("_");
|
|
193
|
-
return extensions.split(",").map((ext) => [ext, mimeType]);
|
|
194
|
-
})
|
|
195
|
-
);
|
|
196
|
-
|
|
197
|
-
// src/get-file-mime-type.ts
|
|
198
|
-
function getFileMimeType(name) {
|
|
199
|
-
const extension = name.split(".").pop();
|
|
200
|
-
return extension ? mimeTypesMap.get(extension) || null : null;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// src/is-valid-file-type.ts
|
|
204
|
-
function isFileAccepted(file, accept) {
|
|
205
|
-
if (file && accept) {
|
|
206
|
-
const types = Array.isArray(accept) ? accept : typeof accept === "string" ? accept.split(",") : [];
|
|
207
|
-
if (types.length === 0) return true;
|
|
208
|
-
const fileName = file.name || "";
|
|
209
|
-
const mimeType = (file.type || getFileMimeType(fileName) || "").toLowerCase();
|
|
210
|
-
const baseMimeType = mimeType.replace(/\/.*$/, "");
|
|
211
|
-
return types.some((type) => {
|
|
212
|
-
const validType = type.trim().toLowerCase();
|
|
213
|
-
if (validType.charAt(0) === ".") {
|
|
214
|
-
return fileName.toLowerCase().endsWith(validType);
|
|
215
|
-
}
|
|
216
|
-
if (validType.endsWith("/*")) {
|
|
217
|
-
return baseMimeType === validType.replace(/\/.*$/, "");
|
|
218
|
-
}
|
|
219
|
-
return mimeType === validType;
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
return true;
|
|
223
|
-
}
|
|
224
|
-
function isValidFileType(file, accept) {
|
|
225
|
-
const isAcceptable = file.type === "application/x-moz-file" || isFileAccepted(file, accept);
|
|
226
|
-
return [isAcceptable, isAcceptable ? null : "FILE_INVALID_TYPE"];
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export { dataURItoBlob, downloadFile, getAcceptAttrString, getFileDataUrl, getFileEntries, getFileMimeType, getTotalFileSize, isFileEqual, isValidFileSize, isValidFileType };
|
|
1
|
+
// src/index.ts
|
|
2
|
+
export * from "./data-transfer.mjs";
|
|
3
|
+
export * from "./data-url-to-blob.mjs";
|
|
4
|
+
export * from "./download-file.mjs";
|
|
5
|
+
export * from "./get-accept-attr.mjs";
|
|
6
|
+
export * from "./get-file-data-url.mjs";
|
|
7
|
+
export * from "./get-total-file-size.mjs";
|
|
8
|
+
export * from "./is-file-equal.mjs";
|
|
9
|
+
export * from "./is-valid-file-size.mjs";
|
|
10
|
+
export * from "./is-valid-file-type.mjs";
|
|
11
|
+
export * from "./get-file-mime-type.mjs";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/is-file-equal.ts
|
|
21
|
+
var is_file_equal_exports = {};
|
|
22
|
+
__export(is_file_equal_exports, {
|
|
23
|
+
isFileEqual: () => isFileEqual
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(is_file_equal_exports);
|
|
26
|
+
var isFileEqual = (file1, file2) => {
|
|
27
|
+
return file1.name === file2.name && file1.size === file2.size && file1.type === file2.type;
|
|
28
|
+
};
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
isFileEqual
|
|
32
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/is-valid-file-size.ts
|
|
21
|
+
var is_valid_file_size_exports = {};
|
|
22
|
+
__export(is_valid_file_size_exports, {
|
|
23
|
+
isValidFileSize: () => isValidFileSize
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(is_valid_file_size_exports);
|
|
26
|
+
var isDefined = (v) => v !== void 0 && v !== null;
|
|
27
|
+
function isValidFileSize(file, minSize, maxSize) {
|
|
28
|
+
if (isDefined(file.size)) {
|
|
29
|
+
if (isDefined(minSize) && isDefined(maxSize)) {
|
|
30
|
+
if (file.size > maxSize) return [false, "FILE_TOO_LARGE"];
|
|
31
|
+
if (file.size < minSize) return [false, "FILE_TOO_SMALL"];
|
|
32
|
+
} else if (isDefined(minSize) && file.size < minSize) {
|
|
33
|
+
return [false, "FILE_TOO_SMALL"];
|
|
34
|
+
} else if (isDefined(maxSize) && file.size > maxSize) {
|
|
35
|
+
return [false, "FILE_TOO_LARGE"];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return [true, null];
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
isValidFileSize
|
|
43
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/is-valid-file-size.ts
|
|
2
|
+
var isDefined = (v) => v !== void 0 && v !== null;
|
|
3
|
+
function isValidFileSize(file, minSize, maxSize) {
|
|
4
|
+
if (isDefined(file.size)) {
|
|
5
|
+
if (isDefined(minSize) && isDefined(maxSize)) {
|
|
6
|
+
if (file.size > maxSize) return [false, "FILE_TOO_LARGE"];
|
|
7
|
+
if (file.size < minSize) return [false, "FILE_TOO_SMALL"];
|
|
8
|
+
} else if (isDefined(minSize) && file.size < minSize) {
|
|
9
|
+
return [false, "FILE_TOO_SMALL"];
|
|
10
|
+
} else if (isDefined(maxSize) && file.size > maxSize) {
|
|
11
|
+
return [false, "FILE_TOO_LARGE"];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return [true, null];
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
isValidFileSize
|
|
18
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/is-valid-file-type.ts
|
|
21
|
+
var is_valid_file_type_exports = {};
|
|
22
|
+
__export(is_valid_file_type_exports, {
|
|
23
|
+
isValidFileType: () => isValidFileType
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(is_valid_file_type_exports);
|
|
26
|
+
var import_get_file_mime_type = require("./get-file-mime-type.cjs");
|
|
27
|
+
function isFileAccepted(file, accept) {
|
|
28
|
+
if (file && accept) {
|
|
29
|
+
const types = Array.isArray(accept) ? accept : typeof accept === "string" ? accept.split(",") : [];
|
|
30
|
+
if (types.length === 0) return true;
|
|
31
|
+
const fileName = file.name || "";
|
|
32
|
+
const mimeType = (file.type || (0, import_get_file_mime_type.getFileMimeType)(fileName) || "").toLowerCase();
|
|
33
|
+
const baseMimeType = mimeType.replace(/\/.*$/, "");
|
|
34
|
+
return types.some((type) => {
|
|
35
|
+
const validType = type.trim().toLowerCase();
|
|
36
|
+
if (validType.charAt(0) === ".") {
|
|
37
|
+
return fileName.toLowerCase().endsWith(validType);
|
|
38
|
+
}
|
|
39
|
+
if (validType.endsWith("/*")) {
|
|
40
|
+
return baseMimeType === validType.replace(/\/.*$/, "");
|
|
41
|
+
}
|
|
42
|
+
return mimeType === validType;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
function isValidFileType(file, accept) {
|
|
48
|
+
const isAcceptable = file.type === "application/x-moz-file" || isFileAccepted(file, accept);
|
|
49
|
+
return [isAcceptable, isAcceptable ? null : "FILE_INVALID_TYPE"];
|
|
50
|
+
}
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
isValidFileType
|
|
54
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/is-valid-file-type.ts
|
|
2
|
+
import { getFileMimeType } from "./get-file-mime-type.mjs";
|
|
3
|
+
function isFileAccepted(file, accept) {
|
|
4
|
+
if (file && accept) {
|
|
5
|
+
const types = Array.isArray(accept) ? accept : typeof accept === "string" ? accept.split(",") : [];
|
|
6
|
+
if (types.length === 0) return true;
|
|
7
|
+
const fileName = file.name || "";
|
|
8
|
+
const mimeType = (file.type || getFileMimeType(fileName) || "").toLowerCase();
|
|
9
|
+
const baseMimeType = mimeType.replace(/\/.*$/, "");
|
|
10
|
+
return types.some((type) => {
|
|
11
|
+
const validType = type.trim().toLowerCase();
|
|
12
|
+
if (validType.charAt(0) === ".") {
|
|
13
|
+
return fileName.toLowerCase().endsWith(validType);
|
|
14
|
+
}
|
|
15
|
+
if (validType.endsWith("/*")) {
|
|
16
|
+
return baseMimeType === validType.replace(/\/.*$/, "");
|
|
17
|
+
}
|
|
18
|
+
return mimeType === validType;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
function isValidFileType(file, accept) {
|
|
24
|
+
const isAcceptable = file.type === "application/x-moz-file" || isFileAccepted(file, accept);
|
|
25
|
+
return [isAcceptable, isAcceptable ? null : "FILE_INVALID_TYPE"];
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
isValidFileType
|
|
29
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const mimeTypes = "3g2_video/3gpp2[3gp,3gpp_video/3gpp[3mf_model/3mf[7z_application/x-7z-compressed[aac_audio/aac[ac_application/pkix-attr-cert[adp_audio/adpcm[adts_audio/aac[ai_application/postscript[aml_application/automationml-aml+xml[amlx_application/automationml-amlx+zip[amr_audio/amr[apk_application/vnd.android.package-archive[apng_image/apng[appcache,manifest_text/cache-manifest[appinstaller_application/appinstaller[appx_application/appx[appxbundle_application/appxbundle[asc_application/pgp-keys[atom_application/atom+xml[atomcat_application/atomcat+xml[atomdeleted_application/atomdeleted+xml[atomsvc_application/atomsvc+xml[au,snd_audio/basic[avi_video/x-msvideo[avci_image/avci[avcs_image/avcs[avif_image/avif[aw_application/applixware[bdoc_application/bdoc[bin,bpk,buffer,deb,deploy,dist,distz,dll,dmg,dms,dump,elc,exe,img,iso,lrf,mar,msi,msm,msp,pkg,so_application/octet-stream[bmp,dib_image/bmp[btf,btif_image/prs.btif[bz2_application/x-bzip2[c_text/x-c[ccxml_application/ccxml+xml[cdfx_application/cdfx+xml[cdmia_application/cdmi-capability[cdmic_application/cdmi-container[cdmid_application/cdmi-domain[cdmio_application/cdmi-object[cdmiq_application/cdmi-queue[cer_application/pkix-cert[cgm_image/cgm[cjs_application/node[class_application/java-vm[coffee,litcoffee_text/coffeescript[conf,def,in,ini,list,log,text,txt_text/plain[cpp,cxx,cc_text/x-c++src[cpl_application/cpl+xml[cpt_application/mac-compactpro[crl_application/pkix-crl[css_text/css[csv_text/csv[cu_application/cu-seeme[cwl_application/cwl[cww_application/prs.cww[davmount_application/davmount+xml[dbk_application/docbook+xml[doc_application/msword[docx_application/vnd.openxmlformats-officedocument.wordprocessingml.document[dsc_text/prs.lines.tag[dssc_application/dssc+der[dtd_application/xml-dtd[dwd_application/atsc-dwd+xml[ear,jar,war_application/java-archive[ecma_application/ecmascript[emf_image/emf[eml,mime_message/rfc822[emma_application/emma+xml[emotionml_application/emotionml+xml[eot_application/vnd.ms-fontobject[eps,ps_application/postscript[epub_application/epub+zip[exi_application/exi[exp_application/express[exr_image/aces[ez_application/andrew-inset[fdf_application/fdf[fdt_application/fdt+xml[fits_image/fits[flac_audio/flac[flv_video/x-flv[g3_image/g3fax[geojson_application/geo+json[gif_image/gif[glb_model/gltf-binary[gltf_model/gltf+json[gml_application/gml+xml[go_text/x-go[gpx_application/gpx+xml[gz_application/gzip[h_text/x-h[h261_video/h261[h263_video/h263[h264_video/h264[heic_image/heic[heics_image/heic-sequence[heif_image/heif[heifs_image/heif-sequence[htm,html,shtml_text/html[ico_image/x-icon[icns_image/x-icns[ics,ifb_text/calendar[iges,igs_model/iges[ink,inkml_application/inkml+xml[ipa_application/octet-stream[java_text/x-java-source[jp2,jpg2_image/jp2[jpeg,jpe,jpg_image/jpeg[jpf,jpx_image/jpx[jpm,jpgm_image/jpm[jpgv_video/jpeg[jph_image/jph[js,mjs_text/javascript[json_application/json[json5_application/json5[jsonld_application/ld+json[jsx_text/jsx[jxl_image/jxl[jxr_image/jxr[ktx_image/ktx[ktx2_image/ktx2[less_text/less[m1v,m2v,mpe,mpeg,mpg_video/mpeg[m4a_audio/mp4[m4v_video/x-m4v[md,markdown_text/markdown[mid,midi,kar,rmi_audio/midi[mkv_video/x-matroska[mp2,mp2a,mp3,mpga,m3a,m2a_audio/mpeg[mp4,mp4v,mpg4_video/mp4[mp4a_audio/mp4[mp4s,m4p_application/mp4[odp_application/vnd.oasis.opendocument.presentation[oda_application/oda[ods_application/vnd.oasis.opendocument.spreadsheet[odt_application/vnd.oasis.opendocument.text[oga,ogg,opus,spx_audio/ogg[ogv_video/ogg[ogx_application/ogg[otf_font/otf[p12,pfx_application/x-pkcs12[pdf_application/pdf[pem_application/x-pem-file[php_text/x-php[png_image/png[ppt_application/vnd.ms-powerpoint[pptx_application/vnd.openxmlformats-officedocument.presentationml.presentation[pskcxml_application/pskc+xml[psd_image/vnd.adobe.photoshop[py_text/x-python[qt,mov_video/quicktime[rar_application/vnd.rar[rdf_application/rdf+xml[rtf_text/rtf[sass_text/x-sass[scss_text/x-scss[sgm,sgml_text/sgml[sh_application/x-sh[svg,svgz_image/svg+xml[swf_application/x-shockwave-flash[tar_application/x-tar[tif,tiff_image/tiff[toml_application/toml[ts_video/mp2t[tsx_text/tsx[tsv_text/tab-separated-values[ttc_font/collection[ttf_font/ttf[vtt_text/vtt[wasm_application/wasm[wav_audio/wav[weba_audio/webm[webm_video/webm[webmanifest_application/manifest+json[webp_image/webp[wma_audio/x-ms-wma[wmv_video/x-ms-wmv[woff_font/woff[woff2_font/woff2[xls_application/vnd.ms-excel[xlsx_application/vnd.openxmlformats-officedocument.spreadsheetml.sheet[xml_application/xml[xz_application/x-xz[yaml,yml_text/yaml[zip_application/zip";
|
|
2
|
+
declare const mimeTypesMap: Map<string, string>;
|
|
3
|
+
|
|
4
|
+
export { mimeTypes, mimeTypesMap };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const mimeTypes = "3g2_video/3gpp2[3gp,3gpp_video/3gpp[3mf_model/3mf[7z_application/x-7z-compressed[aac_audio/aac[ac_application/pkix-attr-cert[adp_audio/adpcm[adts_audio/aac[ai_application/postscript[aml_application/automationml-aml+xml[amlx_application/automationml-amlx+zip[amr_audio/amr[apk_application/vnd.android.package-archive[apng_image/apng[appcache,manifest_text/cache-manifest[appinstaller_application/appinstaller[appx_application/appx[appxbundle_application/appxbundle[asc_application/pgp-keys[atom_application/atom+xml[atomcat_application/atomcat+xml[atomdeleted_application/atomdeleted+xml[atomsvc_application/atomsvc+xml[au,snd_audio/basic[avi_video/x-msvideo[avci_image/avci[avcs_image/avcs[avif_image/avif[aw_application/applixware[bdoc_application/bdoc[bin,bpk,buffer,deb,deploy,dist,distz,dll,dmg,dms,dump,elc,exe,img,iso,lrf,mar,msi,msm,msp,pkg,so_application/octet-stream[bmp,dib_image/bmp[btf,btif_image/prs.btif[bz2_application/x-bzip2[c_text/x-c[ccxml_application/ccxml+xml[cdfx_application/cdfx+xml[cdmia_application/cdmi-capability[cdmic_application/cdmi-container[cdmid_application/cdmi-domain[cdmio_application/cdmi-object[cdmiq_application/cdmi-queue[cer_application/pkix-cert[cgm_image/cgm[cjs_application/node[class_application/java-vm[coffee,litcoffee_text/coffeescript[conf,def,in,ini,list,log,text,txt_text/plain[cpp,cxx,cc_text/x-c++src[cpl_application/cpl+xml[cpt_application/mac-compactpro[crl_application/pkix-crl[css_text/css[csv_text/csv[cu_application/cu-seeme[cwl_application/cwl[cww_application/prs.cww[davmount_application/davmount+xml[dbk_application/docbook+xml[doc_application/msword[docx_application/vnd.openxmlformats-officedocument.wordprocessingml.document[dsc_text/prs.lines.tag[dssc_application/dssc+der[dtd_application/xml-dtd[dwd_application/atsc-dwd+xml[ear,jar,war_application/java-archive[ecma_application/ecmascript[emf_image/emf[eml,mime_message/rfc822[emma_application/emma+xml[emotionml_application/emotionml+xml[eot_application/vnd.ms-fontobject[eps,ps_application/postscript[epub_application/epub+zip[exi_application/exi[exp_application/express[exr_image/aces[ez_application/andrew-inset[fdf_application/fdf[fdt_application/fdt+xml[fits_image/fits[flac_audio/flac[flv_video/x-flv[g3_image/g3fax[geojson_application/geo+json[gif_image/gif[glb_model/gltf-binary[gltf_model/gltf+json[gml_application/gml+xml[go_text/x-go[gpx_application/gpx+xml[gz_application/gzip[h_text/x-h[h261_video/h261[h263_video/h263[h264_video/h264[heic_image/heic[heics_image/heic-sequence[heif_image/heif[heifs_image/heif-sequence[htm,html,shtml_text/html[ico_image/x-icon[icns_image/x-icns[ics,ifb_text/calendar[iges,igs_model/iges[ink,inkml_application/inkml+xml[ipa_application/octet-stream[java_text/x-java-source[jp2,jpg2_image/jp2[jpeg,jpe,jpg_image/jpeg[jpf,jpx_image/jpx[jpm,jpgm_image/jpm[jpgv_video/jpeg[jph_image/jph[js,mjs_text/javascript[json_application/json[json5_application/json5[jsonld_application/ld+json[jsx_text/jsx[jxl_image/jxl[jxr_image/jxr[ktx_image/ktx[ktx2_image/ktx2[less_text/less[m1v,m2v,mpe,mpeg,mpg_video/mpeg[m4a_audio/mp4[m4v_video/x-m4v[md,markdown_text/markdown[mid,midi,kar,rmi_audio/midi[mkv_video/x-matroska[mp2,mp2a,mp3,mpga,m3a,m2a_audio/mpeg[mp4,mp4v,mpg4_video/mp4[mp4a_audio/mp4[mp4s,m4p_application/mp4[odp_application/vnd.oasis.opendocument.presentation[oda_application/oda[ods_application/vnd.oasis.opendocument.spreadsheet[odt_application/vnd.oasis.opendocument.text[oga,ogg,opus,spx_audio/ogg[ogv_video/ogg[ogx_application/ogg[otf_font/otf[p12,pfx_application/x-pkcs12[pdf_application/pdf[pem_application/x-pem-file[php_text/x-php[png_image/png[ppt_application/vnd.ms-powerpoint[pptx_application/vnd.openxmlformats-officedocument.presentationml.presentation[pskcxml_application/pskc+xml[psd_image/vnd.adobe.photoshop[py_text/x-python[qt,mov_video/quicktime[rar_application/vnd.rar[rdf_application/rdf+xml[rtf_text/rtf[sass_text/x-sass[scss_text/x-scss[sgm,sgml_text/sgml[sh_application/x-sh[svg,svgz_image/svg+xml[swf_application/x-shockwave-flash[tar_application/x-tar[tif,tiff_image/tiff[toml_application/toml[ts_video/mp2t[tsx_text/tsx[tsv_text/tab-separated-values[ttc_font/collection[ttf_font/ttf[vtt_text/vtt[wasm_application/wasm[wav_audio/wav[weba_audio/webm[webm_video/webm[webmanifest_application/manifest+json[webp_image/webp[wma_audio/x-ms-wma[wmv_video/x-ms-wmv[woff_font/woff[woff2_font/woff2[xls_application/vnd.ms-excel[xlsx_application/vnd.openxmlformats-officedocument.spreadsheetml.sheet[xml_application/xml[xz_application/x-xz[yaml,yml_text/yaml[zip_application/zip";
|
|
2
|
+
declare const mimeTypesMap: Map<string, string>;
|
|
3
|
+
|
|
4
|
+
export { mimeTypes, mimeTypesMap };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/mime-types.ts
|
|
21
|
+
var mime_types_exports = {};
|
|
22
|
+
__export(mime_types_exports, {
|
|
23
|
+
mimeTypes: () => mimeTypes,
|
|
24
|
+
mimeTypesMap: () => mimeTypesMap
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(mime_types_exports);
|
|
27
|
+
var mimeTypes = "3g2_video/3gpp2[3gp,3gpp_video/3gpp[3mf_model/3mf[7z_application/x-7z-compressed[aac_audio/aac[ac_application/pkix-attr-cert[adp_audio/adpcm[adts_audio/aac[ai_application/postscript[aml_application/automationml-aml+xml[amlx_application/automationml-amlx+zip[amr_audio/amr[apk_application/vnd.android.package-archive[apng_image/apng[appcache,manifest_text/cache-manifest[appinstaller_application/appinstaller[appx_application/appx[appxbundle_application/appxbundle[asc_application/pgp-keys[atom_application/atom+xml[atomcat_application/atomcat+xml[atomdeleted_application/atomdeleted+xml[atomsvc_application/atomsvc+xml[au,snd_audio/basic[avi_video/x-msvideo[avci_image/avci[avcs_image/avcs[avif_image/avif[aw_application/applixware[bdoc_application/bdoc[bin,bpk,buffer,deb,deploy,dist,distz,dll,dmg,dms,dump,elc,exe,img,iso,lrf,mar,msi,msm,msp,pkg,so_application/octet-stream[bmp,dib_image/bmp[btf,btif_image/prs.btif[bz2_application/x-bzip2[c_text/x-c[ccxml_application/ccxml+xml[cdfx_application/cdfx+xml[cdmia_application/cdmi-capability[cdmic_application/cdmi-container[cdmid_application/cdmi-domain[cdmio_application/cdmi-object[cdmiq_application/cdmi-queue[cer_application/pkix-cert[cgm_image/cgm[cjs_application/node[class_application/java-vm[coffee,litcoffee_text/coffeescript[conf,def,in,ini,list,log,text,txt_text/plain[cpp,cxx,cc_text/x-c++src[cpl_application/cpl+xml[cpt_application/mac-compactpro[crl_application/pkix-crl[css_text/css[csv_text/csv[cu_application/cu-seeme[cwl_application/cwl[cww_application/prs.cww[davmount_application/davmount+xml[dbk_application/docbook+xml[doc_application/msword[docx_application/vnd.openxmlformats-officedocument.wordprocessingml.document[dsc_text/prs.lines.tag[dssc_application/dssc+der[dtd_application/xml-dtd[dwd_application/atsc-dwd+xml[ear,jar,war_application/java-archive[ecma_application/ecmascript[emf_image/emf[eml,mime_message/rfc822[emma_application/emma+xml[emotionml_application/emotionml+xml[eot_application/vnd.ms-fontobject[eps,ps_application/postscript[epub_application/epub+zip[exi_application/exi[exp_application/express[exr_image/aces[ez_application/andrew-inset[fdf_application/fdf[fdt_application/fdt+xml[fits_image/fits[flac_audio/flac[flv_video/x-flv[g3_image/g3fax[geojson_application/geo+json[gif_image/gif[glb_model/gltf-binary[gltf_model/gltf+json[gml_application/gml+xml[go_text/x-go[gpx_application/gpx+xml[gz_application/gzip[h_text/x-h[h261_video/h261[h263_video/h263[h264_video/h264[heic_image/heic[heics_image/heic-sequence[heif_image/heif[heifs_image/heif-sequence[htm,html,shtml_text/html[ico_image/x-icon[icns_image/x-icns[ics,ifb_text/calendar[iges,igs_model/iges[ink,inkml_application/inkml+xml[ipa_application/octet-stream[java_text/x-java-source[jp2,jpg2_image/jp2[jpeg,jpe,jpg_image/jpeg[jpf,jpx_image/jpx[jpm,jpgm_image/jpm[jpgv_video/jpeg[jph_image/jph[js,mjs_text/javascript[json_application/json[json5_application/json5[jsonld_application/ld+json[jsx_text/jsx[jxl_image/jxl[jxr_image/jxr[ktx_image/ktx[ktx2_image/ktx2[less_text/less[m1v,m2v,mpe,mpeg,mpg_video/mpeg[m4a_audio/mp4[m4v_video/x-m4v[md,markdown_text/markdown[mid,midi,kar,rmi_audio/midi[mkv_video/x-matroska[mp2,mp2a,mp3,mpga,m3a,m2a_audio/mpeg[mp4,mp4v,mpg4_video/mp4[mp4a_audio/mp4[mp4s,m4p_application/mp4[odp_application/vnd.oasis.opendocument.presentation[oda_application/oda[ods_application/vnd.oasis.opendocument.spreadsheet[odt_application/vnd.oasis.opendocument.text[oga,ogg,opus,spx_audio/ogg[ogv_video/ogg[ogx_application/ogg[otf_font/otf[p12,pfx_application/x-pkcs12[pdf_application/pdf[pem_application/x-pem-file[php_text/x-php[png_image/png[ppt_application/vnd.ms-powerpoint[pptx_application/vnd.openxmlformats-officedocument.presentationml.presentation[pskcxml_application/pskc+xml[psd_image/vnd.adobe.photoshop[py_text/x-python[qt,mov_video/quicktime[rar_application/vnd.rar[rdf_application/rdf+xml[rtf_text/rtf[sass_text/x-sass[scss_text/x-scss[sgm,sgml_text/sgml[sh_application/x-sh[svg,svgz_image/svg+xml[swf_application/x-shockwave-flash[tar_application/x-tar[tif,tiff_image/tiff[toml_application/toml[ts_video/mp2t[tsx_text/tsx[tsv_text/tab-separated-values[ttc_font/collection[ttf_font/ttf[vtt_text/vtt[wasm_application/wasm[wav_audio/wav[weba_audio/webm[webm_video/webm[webmanifest_application/manifest+json[webp_image/webp[wma_audio/x-ms-wma[wmv_video/x-ms-wmv[woff_font/woff[woff2_font/woff2[xls_application/vnd.ms-excel[xlsx_application/vnd.openxmlformats-officedocument.spreadsheetml.sheet[xml_application/xml[xz_application/x-xz[yaml,yml_text/yaml[zip_application/zip";
|
|
28
|
+
var mimeTypesMap = new Map(
|
|
29
|
+
mimeTypes.split("[").flatMap((mime) => {
|
|
30
|
+
const [extensions, mimeType] = mime.split("_");
|
|
31
|
+
return extensions.split(",").map((ext) => [ext, mimeType]);
|
|
32
|
+
})
|
|
33
|
+
);
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
mimeTypes,
|
|
37
|
+
mimeTypesMap
|
|
38
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/mime-types.ts
|
|
2
|
+
var mimeTypes = "3g2_video/3gpp2[3gp,3gpp_video/3gpp[3mf_model/3mf[7z_application/x-7z-compressed[aac_audio/aac[ac_application/pkix-attr-cert[adp_audio/adpcm[adts_audio/aac[ai_application/postscript[aml_application/automationml-aml+xml[amlx_application/automationml-amlx+zip[amr_audio/amr[apk_application/vnd.android.package-archive[apng_image/apng[appcache,manifest_text/cache-manifest[appinstaller_application/appinstaller[appx_application/appx[appxbundle_application/appxbundle[asc_application/pgp-keys[atom_application/atom+xml[atomcat_application/atomcat+xml[atomdeleted_application/atomdeleted+xml[atomsvc_application/atomsvc+xml[au,snd_audio/basic[avi_video/x-msvideo[avci_image/avci[avcs_image/avcs[avif_image/avif[aw_application/applixware[bdoc_application/bdoc[bin,bpk,buffer,deb,deploy,dist,distz,dll,dmg,dms,dump,elc,exe,img,iso,lrf,mar,msi,msm,msp,pkg,so_application/octet-stream[bmp,dib_image/bmp[btf,btif_image/prs.btif[bz2_application/x-bzip2[c_text/x-c[ccxml_application/ccxml+xml[cdfx_application/cdfx+xml[cdmia_application/cdmi-capability[cdmic_application/cdmi-container[cdmid_application/cdmi-domain[cdmio_application/cdmi-object[cdmiq_application/cdmi-queue[cer_application/pkix-cert[cgm_image/cgm[cjs_application/node[class_application/java-vm[coffee,litcoffee_text/coffeescript[conf,def,in,ini,list,log,text,txt_text/plain[cpp,cxx,cc_text/x-c++src[cpl_application/cpl+xml[cpt_application/mac-compactpro[crl_application/pkix-crl[css_text/css[csv_text/csv[cu_application/cu-seeme[cwl_application/cwl[cww_application/prs.cww[davmount_application/davmount+xml[dbk_application/docbook+xml[doc_application/msword[docx_application/vnd.openxmlformats-officedocument.wordprocessingml.document[dsc_text/prs.lines.tag[dssc_application/dssc+der[dtd_application/xml-dtd[dwd_application/atsc-dwd+xml[ear,jar,war_application/java-archive[ecma_application/ecmascript[emf_image/emf[eml,mime_message/rfc822[emma_application/emma+xml[emotionml_application/emotionml+xml[eot_application/vnd.ms-fontobject[eps,ps_application/postscript[epub_application/epub+zip[exi_application/exi[exp_application/express[exr_image/aces[ez_application/andrew-inset[fdf_application/fdf[fdt_application/fdt+xml[fits_image/fits[flac_audio/flac[flv_video/x-flv[g3_image/g3fax[geojson_application/geo+json[gif_image/gif[glb_model/gltf-binary[gltf_model/gltf+json[gml_application/gml+xml[go_text/x-go[gpx_application/gpx+xml[gz_application/gzip[h_text/x-h[h261_video/h261[h263_video/h263[h264_video/h264[heic_image/heic[heics_image/heic-sequence[heif_image/heif[heifs_image/heif-sequence[htm,html,shtml_text/html[ico_image/x-icon[icns_image/x-icns[ics,ifb_text/calendar[iges,igs_model/iges[ink,inkml_application/inkml+xml[ipa_application/octet-stream[java_text/x-java-source[jp2,jpg2_image/jp2[jpeg,jpe,jpg_image/jpeg[jpf,jpx_image/jpx[jpm,jpgm_image/jpm[jpgv_video/jpeg[jph_image/jph[js,mjs_text/javascript[json_application/json[json5_application/json5[jsonld_application/ld+json[jsx_text/jsx[jxl_image/jxl[jxr_image/jxr[ktx_image/ktx[ktx2_image/ktx2[less_text/less[m1v,m2v,mpe,mpeg,mpg_video/mpeg[m4a_audio/mp4[m4v_video/x-m4v[md,markdown_text/markdown[mid,midi,kar,rmi_audio/midi[mkv_video/x-matroska[mp2,mp2a,mp3,mpga,m3a,m2a_audio/mpeg[mp4,mp4v,mpg4_video/mp4[mp4a_audio/mp4[mp4s,m4p_application/mp4[odp_application/vnd.oasis.opendocument.presentation[oda_application/oda[ods_application/vnd.oasis.opendocument.spreadsheet[odt_application/vnd.oasis.opendocument.text[oga,ogg,opus,spx_audio/ogg[ogv_video/ogg[ogx_application/ogg[otf_font/otf[p12,pfx_application/x-pkcs12[pdf_application/pdf[pem_application/x-pem-file[php_text/x-php[png_image/png[ppt_application/vnd.ms-powerpoint[pptx_application/vnd.openxmlformats-officedocument.presentationml.presentation[pskcxml_application/pskc+xml[psd_image/vnd.adobe.photoshop[py_text/x-python[qt,mov_video/quicktime[rar_application/vnd.rar[rdf_application/rdf+xml[rtf_text/rtf[sass_text/x-sass[scss_text/x-scss[sgm,sgml_text/sgml[sh_application/x-sh[svg,svgz_image/svg+xml[swf_application/x-shockwave-flash[tar_application/x-tar[tif,tiff_image/tiff[toml_application/toml[ts_video/mp2t[tsx_text/tsx[tsv_text/tab-separated-values[ttc_font/collection[ttf_font/ttf[vtt_text/vtt[wasm_application/wasm[wav_audio/wav[weba_audio/webm[webm_video/webm[webmanifest_application/manifest+json[webp_image/webp[wma_audio/x-ms-wma[wmv_video/x-ms-wmv[woff_font/woff[woff2_font/woff2[xls_application/vnd.ms-excel[xlsx_application/vnd.openxmlformats-officedocument.spreadsheetml.sheet[xml_application/xml[xz_application/x-xz[yaml,yml_text/yaml[zip_application/zip";
|
|
3
|
+
var mimeTypesMap = new Map(
|
|
4
|
+
mimeTypes.split("[").flatMap((mime) => {
|
|
5
|
+
const [extensions, mimeType] = mime.split("_");
|
|
6
|
+
return extensions.split(",").map((ext) => [ext, mimeType]);
|
|
7
|
+
})
|
|
8
|
+
);
|
|
9
|
+
export {
|
|
10
|
+
mimeTypes,
|
|
11
|
+
mimeTypesMap
|
|
12
|
+
};
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type AnyString = string & {};
|
|
2
|
+
type FileError = "TOO_MANY_FILES" | "FILE_INVALID_TYPE" | "FILE_TOO_LARGE" | "FILE_TOO_SMALL" | "FILE_INVALID" | "FILE_EXISTS" | AnyString;
|
|
3
|
+
type ImageFileMimeType = "image/png" | "image/gif" | "image/jpeg" | "image/svg+xml" | "image/webp" | "image/avif" | "image/heic" | "image/bmp";
|
|
4
|
+
type ApplicationFileMimeType = "application/pdf" | "application/zip" | "application/json" | "application/xml" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "application/rtf" | "application/x-rar" | "application/x-7z-compressed" | "application/x-tar" | "application/vnd.microsoft.portable-executable";
|
|
5
|
+
type TextFileMimeType = "text/css" | "text/csv" | "text/html" | "text/markdown" | "text/plain";
|
|
6
|
+
type FontFileMimeType = "font/ttf" | "font/otf" | "font/woff" | "font/woff2" | "font/eot" | "font/svg";
|
|
7
|
+
type VideoFileMimeType = "video/mp4" | "video/webm" | "video/ogg" | "video/quicktime" | "video/x-msvideo";
|
|
8
|
+
type AudioFileMimeType = "audio/mpeg" | "audio/ogg" | "audio/wav" | "audio/webm" | "audio/aac" | "audio/flac" | "audio/x-m4a";
|
|
9
|
+
type FileMimeTypeGroup = "image/*" | "audio/*" | "video/*" | "text/*" | "application/*" | "font/*";
|
|
10
|
+
type FileMimeType = ImageFileMimeType | ApplicationFileMimeType | TextFileMimeType | FontFileMimeType | VideoFileMimeType | AudioFileMimeType | FileMimeTypeGroup | AnyString;
|
|
11
|
+
|
|
12
|
+
export type { ApplicationFileMimeType, AudioFileMimeType, FileError, FileMimeType, FileMimeTypeGroup, FontFileMimeType, ImageFileMimeType, TextFileMimeType, VideoFileMimeType };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type AnyString = string & {};
|
|
2
|
+
type FileError = "TOO_MANY_FILES" | "FILE_INVALID_TYPE" | "FILE_TOO_LARGE" | "FILE_TOO_SMALL" | "FILE_INVALID" | "FILE_EXISTS" | AnyString;
|
|
3
|
+
type ImageFileMimeType = "image/png" | "image/gif" | "image/jpeg" | "image/svg+xml" | "image/webp" | "image/avif" | "image/heic" | "image/bmp";
|
|
4
|
+
type ApplicationFileMimeType = "application/pdf" | "application/zip" | "application/json" | "application/xml" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "application/rtf" | "application/x-rar" | "application/x-7z-compressed" | "application/x-tar" | "application/vnd.microsoft.portable-executable";
|
|
5
|
+
type TextFileMimeType = "text/css" | "text/csv" | "text/html" | "text/markdown" | "text/plain";
|
|
6
|
+
type FontFileMimeType = "font/ttf" | "font/otf" | "font/woff" | "font/woff2" | "font/eot" | "font/svg";
|
|
7
|
+
type VideoFileMimeType = "video/mp4" | "video/webm" | "video/ogg" | "video/quicktime" | "video/x-msvideo";
|
|
8
|
+
type AudioFileMimeType = "audio/mpeg" | "audio/ogg" | "audio/wav" | "audio/webm" | "audio/aac" | "audio/flac" | "audio/x-m4a";
|
|
9
|
+
type FileMimeTypeGroup = "image/*" | "audio/*" | "video/*" | "text/*" | "application/*" | "font/*";
|
|
10
|
+
type FileMimeType = ImageFileMimeType | ApplicationFileMimeType | TextFileMimeType | FontFileMimeType | VideoFileMimeType | AudioFileMimeType | FileMimeTypeGroup | AnyString;
|
|
11
|
+
|
|
12
|
+
export type { ApplicationFileMimeType, AudioFileMimeType, FileError, FileMimeType, FileMimeTypeGroup, FontFileMimeType, ImageFileMimeType, TextFileMimeType, VideoFileMimeType };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
package/dist/types.mjs
ADDED
|
File without changes
|