@wxn0brp/falcon-frame 0.9.7 → 0.9.8

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.
@@ -0,0 +1,7 @@
1
+ export declare const mimeTypes: Record<string, string>;
2
+ /**
3
+ * Registers a MIME type for a file extension
4
+ */
5
+ export declare function registerMimeType(extension: string, contentType: string): void;
6
+ export declare function isTextualContentType(contentType: string): boolean;
7
+ export declare function getContentType(filePath: string, utf8?: boolean): string;
@@ -0,0 +1,71 @@
1
+ import path from "path";
2
+ export const mimeTypes = {
3
+ ".html": "text/html",
4
+ ".xhtml": "application/xhtml+xml",
5
+ ".css": "text/css",
6
+ ".js": "application/javascript",
7
+ ".mjs": "application/javascript",
8
+ ".cjs": "application/javascript",
9
+ ".json": "application/json",
10
+ ".json5": "application/json5",
11
+ ".yaml": "application/yaml",
12
+ ".yml": "application/yaml",
13
+ ".toml": "application/toml",
14
+ ".xml": "application/xml",
15
+ ".csv": "text/csv",
16
+ ".md": "text/markdown",
17
+ ".vtt": "text/vtt",
18
+ ".map": "application/json",
19
+ ".webmanifest": "application/manifest+json",
20
+ ".png": "image/png",
21
+ ".apng": "image/apng",
22
+ ".jpg": "image/jpeg",
23
+ ".jpeg": "image/jpeg",
24
+ ".gif": "image/gif",
25
+ ".svg": "image/svg+xml",
26
+ ".ico": "image/x-icon",
27
+ ".webp": "image/webp",
28
+ ".avif": "image/avif",
29
+ ".bmp": "image/bmp",
30
+ ".tiff": "image/tiff",
31
+ ".txt": "text/plain",
32
+ ".pdf": "application/pdf",
33
+ ".wasm": "application/wasm",
34
+ ".wav": "audio/wav",
35
+ ".mp3": "audio/mpeg",
36
+ ".ogg": "audio/ogg",
37
+ ".aac": "audio/aac",
38
+ ".weba": "audio/webm",
39
+ ".flac": "audio/flac",
40
+ ".opus": "audio/opus",
41
+ ".m4a": "audio/mp4",
42
+ ".mp4": "video/mp4",
43
+ ".m4v": "video/mp4",
44
+ ".webm": "video/webm",
45
+ ".ogv": "video/ogg",
46
+ ".m3u8": "application/vnd.apple.mpegurl",
47
+ ".woff": "font/woff",
48
+ ".woff2": "font/woff2",
49
+ ".ttf": "font/ttf",
50
+ ".otf": "font/otf",
51
+ ".eot": "application/vnd.ms-fontobject",
52
+ };
53
+ /**
54
+ * Registers a MIME type for a file extension
55
+ */
56
+ export function registerMimeType(extension, contentType) {
57
+ const ext = extension.trim().toLowerCase();
58
+ mimeTypes[ext.startsWith(".") ? ext : "." + ext] = contentType;
59
+ }
60
+ const textualTypeRe = /^(?:text\/|application\/(?:json5?|javascript|xml|yaml|toml)$|[\w.-]+\/[\w.-]+\+(?:json|xml)$)/;
61
+ export function isTextualContentType(contentType) {
62
+ const type = contentType.split(";")[0].trim().toLowerCase();
63
+ return type === "image/svg+xml" || textualTypeRe.test(type);
64
+ }
65
+ export function getContentType(filePath, utf8 = true) {
66
+ let contentType = mimeTypes[path.extname(filePath).toLowerCase()] ??
67
+ "application/octet-stream";
68
+ if (utf8 && !contentType.includes(";") && isTextualContentType(contentType))
69
+ contentType += "; charset=utf-8";
70
+ return contentType;
71
+ }
package/dist/helpers.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Cookies, FFRequest } from "./types.js";
2
+ export { getContentType } from "./encoding.js";
2
3
  export declare function parseCookies(cookieHeader: string): Cookies;
3
4
  export declare function getIP(req: FFRequest): string;
4
- export declare function getContentType(filePath: string, utf8?: boolean): string;
5
5
  export declare const ensureLeadingDot: (str: string) => string;
package/dist/helpers.js CHANGED
@@ -1,4 +1,4 @@
1
- import path from "path";
1
+ export { getContentType } from "./encoding.js";
2
2
  export function parseCookies(cookieHeader) {
3
3
  const cookies = Object.create(null);
4
4
  cookieHeader.split(";").forEach(cookie => {
@@ -17,32 +17,4 @@ export function getIP(req) {
17
17
  }
18
18
  return req.socket.remoteAddress || "";
19
19
  }
20
- const mimeTypes = {
21
- ".html": "text/html",
22
- ".css": "text/css",
23
- ".js": "application/javascript",
24
- ".json": "application/json",
25
- ".json5": "application/json5",
26
- ".yaml": "application/yaml",
27
- ".yml": "application/yaml",
28
- ".toml": "application/toml",
29
- ".png": "image/png",
30
- ".jpg": "image/jpeg",
31
- ".jpeg": "image/jpeg",
32
- ".gif": "image/gif",
33
- ".svg": "image/svg+xml",
34
- ".ico": "image/x-icon",
35
- ".txt": "text/plain",
36
- ".pdf": "application/pdf",
37
- };
38
- function _getContentType(filePath) {
39
- const ext = path.extname(filePath).toLowerCase();
40
- return mimeTypes[ext] || "application/octet-stream";
41
- }
42
- export function getContentType(filePath, utf8 = false) {
43
- let contentType = _getContentType(filePath);
44
- if (utf8)
45
- contentType += "; charset=utf-8";
46
- return contentType;
47
- }
48
20
  export const ensureLeadingDot = (str) => str.startsWith(".") ? str : "." + str;
package/dist/res.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { createReadStream } from "fs";
2
2
  import http from "http";
3
3
  import path from "path";
4
- import { ensureLeadingDot, getContentType } from "./helpers.js";
4
+ import { ensureLeadingDot } from "./helpers.js";
5
+ import { getContentType } from "./encoding.js";
5
6
  export class FFResponse extends http.ServerResponse {
6
7
  _ended = false;
7
8
  FF;
@@ -98,7 +99,7 @@ export class FFResponse extends http.ServerResponse {
98
99
  */
99
100
  sendFile(filePath, contentType) {
100
101
  if (contentType === "utf8")
101
- contentType = getContentType(filePath);
102
+ contentType = getContentType(filePath, true);
102
103
  this.ct(contentType || getContentType(filePath));
103
104
  createReadStream(filePath).pipe(this);
104
105
  this._ended = true;
package/dist/static.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
- import { ensureLeadingDot, getContentType } from "./helpers.js";
3
+ import { ensureLeadingDot } from "./helpers.js";
4
+ import { getContentType } from "./encoding.js";
4
5
  export function handleSingleFile(filePath, opts) {
5
6
  opts = {
6
7
  utf8: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/falcon-frame",
3
- "version": "0.9.7",
3
+ "version": "0.9.8",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "wxn0brP",