@techmely/utils
Version:
Collection of helpful JavaScript / TypeScript utils
69 lines (65 loc) • 2.46 kB
JavaScript
/*!
* @techmely/utils
* Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com>
* MIT Licensed
*/
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/getMineTypeFromExtension.ts
var getMineTypeFromExtension_exports = {};
__export(getMineTypeFromExtension_exports, {
MimeType: () => MimeType,
getMimeTypeFromExtension: () => getMimeTypeFromExtension,
mimeTable: () => mimeTable
});
module.exports = __toCommonJS(getMineTypeFromExtension_exports);
var MimeType = /* @__PURE__ */ ((MimeType2) => {
MimeType2["JPG"] = "image/jpeg";
MimeType2["GIF"] = "image/gif";
MimeType2["PNG"] = "image/png";
MimeType2["MP4"] = "video/mp4";
MimeType2["QuickTime"] = "video/quicktime";
MimeType2["AVI"] = "video/x-msvideo";
MimeType2["WMV"] = "video/x-ms-wmv";
MimeType2["HEIC"] = "image/heic";
return MimeType2;
})(MimeType || {});
var mimeTable = [
{ ext: ["gif"], type: "image/gif" /* GIF */ },
{ ext: ["jpe", "jpeg", "jpg"], type: "image/jpeg" /* JPG */ },
{ ext: ["png"], type: "image/png" /* PNG */ },
{ ext: ["qt", "mov"], type: "video/quicktime" /* QuickTime */ },
{ ext: ["mp4", "mp4v", "mpg4", "m4v"], type: "video/mp4" /* MP4 */ },
{ ext: ["avi"], type: "video/x-msvideo" /* AVI */ },
{ ext: ["wmv"], type: "video/x-ms-wmv" /* WMV */ },
{ ext: ["heic"], type: "image/heic" /* HEIC */ }
];
var getMimeTypeFromExtension = (extension) => {
const result = mimeTable.find(({ ext }) => ext.includes(extension));
if (!result) {
throw new Error(`'${extension}' is not a valid extension`);
}
return result.type;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MimeType,
getMimeTypeFromExtension,
mimeTable
});