@putkoff/abstract-utilities 1.0.135 → 1.0.142
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/cjs/browser.js +34 -0
- package/dist/cjs/browser.js.map +1 -0
- package/dist/cjs/client.js +1 -4
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/functions.js +2 -10
- package/dist/cjs/functions.js.map +1 -1
- package/dist/cjs/index.js +2 -10
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/mime_utils-C53pEVr1.js +835 -0
- package/dist/cjs/mime_utils-C53pEVr1.js.map +1 -0
- package/dist/cjs/print_utils-D85MeEz4.js +1948 -0
- package/dist/cjs/print_utils-D85MeEz4.js.map +1 -0
- package/dist/cjs/print_utils-DA-vFdOl.js +1907 -0
- package/dist/cjs/print_utils-DA-vFdOl.js.map +1 -0
- package/dist/cjs/readJsonFile.browser-BsrKPMhm.js +34 -0
- package/dist/cjs/readJsonFile.browser-BsrKPMhm.js.map +1 -0
- package/dist/cjs/readJsonFile.node-DqCxMX38.js +19 -0
- package/dist/cjs/readJsonFile.node-DqCxMX38.js.map +1 -0
- package/dist/cjs/server.js +9 -331
- package/dist/cjs/server.js.map +1 -1
- package/dist/esm/browser.js +31 -0
- package/dist/esm/browser.js.map +1 -0
- package/dist/esm/client.js +1 -4
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/functions.js +2 -5
- package/dist/esm/functions.js.map +1 -1
- package/dist/esm/index.js +2 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/mime_utils-D3LjiFgN.js +815 -0
- package/dist/esm/mime_utils-D3LjiFgN.js.map +1 -0
- package/dist/esm/print_utils-DHCwLBDO.js +1667 -0
- package/dist/esm/print_utils-DHCwLBDO.js.map +1 -0
- package/dist/esm/print_utils-DlZVeNG9.js +1706 -0
- package/dist/esm/print_utils-DlZVeNG9.js.map +1 -0
- package/dist/esm/readJsonFile.browser-C9FwYiRq.js +31 -0
- package/dist/esm/readJsonFile.browser-C9FwYiRq.js.map +1 -0
- package/dist/esm/readJsonFile.node-Dg_ttFdy.js +17 -0
- package/dist/esm/readJsonFile.node-Dg_ttFdy.js.map +1 -0
- package/dist/esm/server.js +9 -296
- package/dist/esm/server.js.map +1 -1
- package/dist/types/browser/index.d.ts +1 -0
- package/dist/types/browser/mediaTypes.fs.d.ts +0 -0
- package/dist/types/browser/src/index.d.ts +1 -0
- package/dist/types/browser/src/read_utils/imports.d.ts +0 -0
- package/dist/types/browser/src/read_utils/index.d.ts +1 -0
- package/dist/types/browser/src/read_utils/src/index.d.ts +1 -0
- package/dist/types/browser/src/read_utils/src/readJsonFile.browser.d.ts +6 -0
- package/dist/types/functions/read_utils/src/index.d.ts +0 -2
- package/dist/types/functions/read_utils/src/readJsonFile.browser.d.ts +5 -0
- package/dist/types/functions/type_utils/src/mime_utils.d.ts +4 -25
- package/dist/types/server/src/index.d.ts +1 -1
- package/dist/types/server/src/mediaTypes.core.d.ts +37 -0
- package/dist/types/server/src/mime_utils.d.ts +4 -25
- package/dist/types/server/src/read_utils/imports.d.ts +0 -0
- package/dist/types/server/src/read_utils/index.d.ts +1 -0
- package/dist/types/server/src/read_utils/src/index.d.ts +1 -0
- package/dist/types/server/src/read_utils/src/readJsonFile.node.d.ts +1 -0
- package/package.json +1 -1
package/dist/esm/server.js
CHANGED
|
@@ -1,305 +1,18 @@
|
|
|
1
1
|
import 'server-only';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import * as path from 'node:path';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
import { isAbsolute, resolve } from 'path';
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
/** ---- Data: large but explicit, mirrors your Python mapping ---- */
|
|
8
|
-
const MIME_TYPES = {
|
|
9
|
-
image: {
|
|
10
|
-
".jpg": "image/jpeg",
|
|
11
|
-
".jpeg": "image/jpeg",
|
|
12
|
-
".png": "image/png",
|
|
13
|
-
".gif": "image/gif",
|
|
14
|
-
".bmp": "image/bmp",
|
|
15
|
-
".tiff": "image/tiff",
|
|
16
|
-
".webp": "image/webp",
|
|
17
|
-
".svg": "image/svg+xml",
|
|
18
|
-
".ico": "image/vnd.microsoft.icon",
|
|
19
|
-
".heic": "image/heic",
|
|
20
|
-
".psd": "image/vnd.adobe.photoshop",
|
|
21
|
-
".raw": "image/x-raw",
|
|
22
|
-
},
|
|
23
|
-
video: {
|
|
24
|
-
".mp4": "video/mp4",
|
|
25
|
-
".webm": "video/webm",
|
|
26
|
-
".ogg": "video/ogg",
|
|
27
|
-
".mov": "video/quicktime",
|
|
28
|
-
".avi": "video/x-msvideo",
|
|
29
|
-
".mkv": "video/x-matroska",
|
|
30
|
-
".flv": "video/x-flv",
|
|
31
|
-
".wmv": "video/x-ms-wmv",
|
|
32
|
-
".3gp": "video/3gpp",
|
|
33
|
-
".ts": "video/mp2t",
|
|
34
|
-
".mpeg": "video/mpeg",
|
|
35
|
-
".mpg": "video/mpg",
|
|
36
|
-
},
|
|
37
|
-
audio: {
|
|
38
|
-
".mp3": "audio/mpeg",
|
|
39
|
-
".wav": "audio/wav",
|
|
40
|
-
".flac": "audio/flac",
|
|
41
|
-
".aac": "audio/aac",
|
|
42
|
-
".ogg": "audio/ogg",
|
|
43
|
-
".m4a": "audio/mp4",
|
|
44
|
-
".opus": "audio/opus",
|
|
45
|
-
},
|
|
46
|
-
document: {
|
|
47
|
-
".pdf": "application/pdf",
|
|
48
|
-
".doc": "application/msword",
|
|
49
|
-
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
50
|
-
".odt": "application/vnd.oasis.opendocument.text",
|
|
51
|
-
".txt": "text/plain",
|
|
52
|
-
".rtf": "application/rtf",
|
|
53
|
-
".md": "text/markdown",
|
|
54
|
-
".markdown": "text/markdown",
|
|
55
|
-
".tex": "application/x-tex",
|
|
56
|
-
".log": "text/plain",
|
|
57
|
-
".json": "application/json",
|
|
58
|
-
".xml": "application/xml",
|
|
59
|
-
".yaml": "application/x-yaml",
|
|
60
|
-
".yml": "application/x-yaml",
|
|
61
|
-
".ini": "text/plain",
|
|
62
|
-
".cfg": "text/plain",
|
|
63
|
-
".toml": "application/toml",
|
|
64
|
-
".csv": "text/csv",
|
|
65
|
-
".tsv": "text/tab-separated-values",
|
|
66
|
-
},
|
|
67
|
-
presentation: {
|
|
68
|
-
".ppt": "application/vnd.ms-powerpoint",
|
|
69
|
-
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
70
|
-
".odp": "application/vnd.oasis.opendocument.presentation",
|
|
71
|
-
},
|
|
72
|
-
spreadsheet: {
|
|
73
|
-
".xls": "application/vnd.ms-excel",
|
|
74
|
-
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
75
|
-
".ods": "application/vnd.oasis.opendocument.spreadsheet",
|
|
76
|
-
".csv": "text/csv",
|
|
77
|
-
".tsv": "text/tab-separated-values",
|
|
78
|
-
},
|
|
79
|
-
code: {
|
|
80
|
-
".py": "text/x-python",
|
|
81
|
-
".java": "text/x-java-source",
|
|
82
|
-
".c": "text/x-c",
|
|
83
|
-
".cpp": "text/x-c++",
|
|
84
|
-
".h": "text/x-c",
|
|
85
|
-
".hpp": "text/x-c++",
|
|
86
|
-
".js": "application/javascript",
|
|
87
|
-
".cjs": "application/javascript",
|
|
88
|
-
".mjs": "application/javascript",
|
|
89
|
-
".jsx": "application/javascript",
|
|
90
|
-
".ts": "application/typescript",
|
|
91
|
-
".tsx": "application/typescript",
|
|
92
|
-
".rb": "text/x-ruby",
|
|
93
|
-
".php": "application/x-php",
|
|
94
|
-
".go": "text/x-go",
|
|
95
|
-
".rs": "text/rust",
|
|
96
|
-
".swift": "text/x-swift",
|
|
97
|
-
".kt": "text/x-kotlin",
|
|
98
|
-
".sh": "application/x-shellscript",
|
|
99
|
-
".bash": "application/x-shellscript",
|
|
100
|
-
".ps1": "application/x-powershell",
|
|
101
|
-
".sql": "application/sql",
|
|
102
|
-
".yml": "application/x-yaml",
|
|
103
|
-
".coffee": "text/coffeescript",
|
|
104
|
-
".lua": "text/x-lua",
|
|
105
|
-
},
|
|
106
|
-
archive: {
|
|
107
|
-
".zip": "application/zip",
|
|
108
|
-
".tar": "application/x-tar",
|
|
109
|
-
".gz": "application/gzip",
|
|
110
|
-
".tgz": "application/gzip",
|
|
111
|
-
".bz2": "application/x-bzip2",
|
|
112
|
-
".xz": "application/x-xz",
|
|
113
|
-
".rar": "application/vnd.rar",
|
|
114
|
-
".7z": "application/x-7z-compressed",
|
|
115
|
-
".iso": "application/x-iso9660-image",
|
|
116
|
-
".dmg": "application/x-apple-diskimage",
|
|
117
|
-
".jar": "application/java-archive",
|
|
118
|
-
".war": "application/java-archive",
|
|
119
|
-
".whl": "application/python-wheel",
|
|
120
|
-
".egg": "application/python-egg",
|
|
121
|
-
},
|
|
122
|
-
font: {
|
|
123
|
-
".ttf": "font/ttf",
|
|
124
|
-
".otf": "font/otf",
|
|
125
|
-
".woff": "font/woff",
|
|
126
|
-
".woff2": "font/woff2",
|
|
127
|
-
".eot": "application/vnd.ms-fontobject",
|
|
128
|
-
},
|
|
129
|
-
executable: {
|
|
130
|
-
".exe": "application/vnd.microsoft.portable-executable",
|
|
131
|
-
".dll": "application/vnd.microsoft.portable-executable",
|
|
132
|
-
".bin": "application/octet-stream",
|
|
133
|
-
".deb": "application/vnd.debian.binary-package",
|
|
134
|
-
".rpm": "application/x-rpm",
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
/** Mirror of MEDIA_TYPES in Python: category -> Set of extensions */
|
|
138
|
-
const MEDIA_TYPES = Object.fromEntries(Object.entries(MIME_TYPES).map(([cat, mapping]) => [
|
|
139
|
-
cat,
|
|
140
|
-
new Set(Object.keys(mapping)),
|
|
141
|
-
]));
|
|
142
|
-
/** ---- Helpers ---- */
|
|
143
|
-
function toCategorySet(categories) {
|
|
144
|
-
const allCats = new Set(Object.keys(MIME_TYPES));
|
|
145
|
-
if (!categories) {
|
|
146
|
-
// all categories
|
|
147
|
-
return new Set(allCats);
|
|
148
|
-
}
|
|
149
|
-
const out = new Set();
|
|
150
|
-
for (const c of categories) {
|
|
151
|
-
const key = String(c);
|
|
152
|
-
if (allCats.has(key))
|
|
153
|
-
out.add(key);
|
|
154
|
-
}
|
|
155
|
-
return out.size ? out : new Set(allCats);
|
|
156
|
-
}
|
|
157
|
-
function normalizeCategories(categories, opts) {
|
|
158
|
-
const selected = categories ?? opts?.media_types ?? null;
|
|
159
|
-
return toCategorySet(selected);
|
|
160
|
-
}
|
|
161
|
-
function extOf(input) {
|
|
162
|
-
// Behaves like pathlib.Path(...).suffix.lower(): last extension only; lowercased.
|
|
163
|
-
let ext = path.extname(input || "");
|
|
164
|
-
if (!ext && input && input.startsWith(".")) {
|
|
165
|
-
// user passed ".jpg" directly
|
|
166
|
-
ext = input;
|
|
167
|
-
}
|
|
168
|
-
return (ext || "").toLowerCase();
|
|
169
|
-
}
|
|
170
|
-
function unionExts(categories) {
|
|
171
|
-
const out = new Set();
|
|
172
|
-
for (const c of categories) {
|
|
173
|
-
const set = MEDIA_TYPES[c];
|
|
174
|
-
for (const e of set)
|
|
175
|
-
out.add(e);
|
|
176
|
-
}
|
|
177
|
-
return out;
|
|
178
|
-
}
|
|
179
|
-
/** ---- API (Python parity) ---- */
|
|
180
|
-
/**
|
|
181
|
-
* Return a sub-map of MEDIA_TYPES for the given categories.
|
|
182
|
-
* If categories is falsy, returns all categories.
|
|
183
|
-
*/
|
|
184
|
-
function getMediaMap(categories, opts) {
|
|
185
|
-
const cats = normalizeCategories(categories, opts);
|
|
186
|
-
const result = {};
|
|
187
|
-
for (const c of cats)
|
|
188
|
-
result[c] = new Set(MEDIA_TYPES[c]);
|
|
189
|
-
return result;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Return a flat, sorted list of all extensions for the given categories.
|
|
193
|
-
*/
|
|
194
|
-
function getMediaExts(categories, opts) {
|
|
195
|
-
const cats = normalizeCategories(categories, opts);
|
|
196
|
-
return Array.from(unionExts(cats)).sort();
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Given a file path or extension, return its media category (e.g. "image") or null.
|
|
200
|
-
* Mirrors Python's confirm_type.
|
|
201
|
-
*/
|
|
202
|
-
function confirmType(pathOrExt, categories, opts) {
|
|
203
|
-
const cats = normalizeCategories(categories, opts);
|
|
204
|
-
const ext = extOf(pathOrExt);
|
|
205
|
-
// Preserve object insertion order like Python dict iteration
|
|
206
|
-
for (const [category, exts] of Object.entries(MEDIA_TYPES)) {
|
|
207
|
-
if (!cats.has(category))
|
|
208
|
-
continue;
|
|
209
|
-
if (ext && exts.has(ext))
|
|
210
|
-
return category;
|
|
211
|
-
}
|
|
212
|
-
return null;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* True if the given file path or extension belongs to one of the categories.
|
|
216
|
-
*/
|
|
217
|
-
function isMediaType(pathOrExt, categories, opts) {
|
|
218
|
-
return confirmType(pathOrExt, categories, opts) !== null;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Look up the MIME type by extension; fall back to 'application/octet-stream'.
|
|
222
|
-
*/
|
|
223
|
-
function getMimeType(pathOrExt) {
|
|
224
|
-
const ext = extOf(pathOrExt);
|
|
225
|
-
for (const mapping of Object.values(MIME_TYPES)) {
|
|
226
|
-
if (ext && mapping[ext]) {
|
|
227
|
-
return mapping[ext];
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return "application/octet-stream";
|
|
231
|
-
}
|
|
232
|
-
function getAllFileTypesSync(directory, categories, opts) {
|
|
233
|
-
// 🧩 Skip entirely if fs isn't available
|
|
234
|
-
if (!fs || !path)
|
|
235
|
-
return [];
|
|
236
|
-
try {
|
|
237
|
-
const stat = fs.statSync(directory);
|
|
238
|
-
if (!stat.isDirectory())
|
|
239
|
-
return [];
|
|
240
|
-
const cats = normalizeCategories(categories, opts);
|
|
241
|
-
const wanted = unionExts(cats);
|
|
242
|
-
const results = [];
|
|
243
|
-
function walkSync(dir) {
|
|
244
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
245
|
-
for (const ent of entries) {
|
|
246
|
-
const full = path.join(dir, ent.name);
|
|
247
|
-
if (ent.isDirectory()) {
|
|
248
|
-
walkSync(full);
|
|
249
|
-
}
|
|
250
|
-
else if (ent.isFile()) {
|
|
251
|
-
const ext = path.extname(ent.name).toLowerCase();
|
|
252
|
-
if (wanted.has(ext))
|
|
253
|
-
results.push(full);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
walkSync(directory);
|
|
258
|
-
return results;
|
|
259
|
-
}
|
|
260
|
-
catch {
|
|
261
|
-
return [];
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
async function getAllFileTypes(directory, categories, opts) {
|
|
265
|
-
// 🧩 Skip entirely if fsp isn't available
|
|
266
|
-
if (!fsp || !path)
|
|
267
|
-
return [];
|
|
5
|
+
function readJsonFileNode(relativeOrAbsolutePath) {
|
|
268
6
|
try {
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const wanted = unionExts(cats);
|
|
274
|
-
const results = [];
|
|
275
|
-
async function walkAsync(dir) {
|
|
276
|
-
const entries = await fsp.readdir(dir, { withFileTypes: true });
|
|
277
|
-
for (const ent of entries) {
|
|
278
|
-
const full = path.join(dir, ent.name);
|
|
279
|
-
if (ent.isDirectory()) {
|
|
280
|
-
await walkAsync(full);
|
|
281
|
-
}
|
|
282
|
-
else if (ent.isFile()) {
|
|
283
|
-
const ext = path.extname(ent.name).toLowerCase();
|
|
284
|
-
if (wanted.has(ext))
|
|
285
|
-
results.push(full);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
await walkAsync(directory);
|
|
290
|
-
return results;
|
|
7
|
+
const filePath = isAbsolute(relativeOrAbsolutePath)
|
|
8
|
+
? relativeOrAbsolutePath
|
|
9
|
+
: resolve(process.cwd(), relativeOrAbsolutePath);
|
|
10
|
+
return JSON.parse(readFileSync(filePath, "utf8"));
|
|
291
11
|
}
|
|
292
12
|
catch {
|
|
293
|
-
return
|
|
13
|
+
return null;
|
|
294
14
|
}
|
|
295
15
|
}
|
|
296
|
-
/** Optional convenience re-exports that mirror your Python names */
|
|
297
|
-
const get_all_file_types = getAllFileTypes;
|
|
298
|
-
const get_media_map = getMediaMap;
|
|
299
|
-
const get_media_exts = getMediaExts;
|
|
300
|
-
const confirm_type = confirmType;
|
|
301
|
-
const is_media_type = isMediaType;
|
|
302
|
-
const get_mime_type = getMimeType;
|
|
303
16
|
|
|
304
|
-
export {
|
|
17
|
+
export { readJsonFileNode };
|
|
305
18
|
//# sourceMappingURL=server.js.map
|
package/dist/esm/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sources":["../../src/server/src/mime_utils.ts"],"sourcesContent":["// mediaTypes.ts\nimport * as fs from \"node:fs\";\nimport * as fsp from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\n/** ---- Types ---- */\nexport type MimeByExt = Record<string, string>;\nexport type MediaMap = Record<string, MimeByExt>;\nexport type MediaCategory = keyof typeof MIME_TYPES;\n\nexport interface MediaOptions {\n /** Alias to mirror the Python **kwargs['media_types'] behavior */\n media_types?: Iterable<string> | string[] | null;\n}\n\n/** ---- Data: large but explicit, mirrors your Python mapping ---- */\nexport const MIME_TYPES = {\n image: {\n \".jpg\": \"image/jpeg\",\n \".jpeg\": \"image/jpeg\",\n \".png\": \"image/png\",\n \".gif\": \"image/gif\",\n \".bmp\": \"image/bmp\",\n \".tiff\": \"image/tiff\",\n \".webp\": \"image/webp\",\n \".svg\": \"image/svg+xml\",\n \".ico\": \"image/vnd.microsoft.icon\",\n \".heic\": \"image/heic\",\n \".psd\": \"image/vnd.adobe.photoshop\",\n \".raw\": \"image/x-raw\",\n },\n video: {\n \".mp4\": \"video/mp4\",\n \".webm\": \"video/webm\",\n \".ogg\": \"video/ogg\",\n \".mov\": \"video/quicktime\",\n \".avi\": \"video/x-msvideo\",\n \".mkv\": \"video/x-matroska\",\n \".flv\": \"video/x-flv\",\n \".wmv\": \"video/x-ms-wmv\",\n \".3gp\": \"video/3gpp\",\n \".ts\": \"video/mp2t\",\n \".mpeg\": \"video/mpeg\",\n \".mpg\": \"video/mpg\",\n },\n audio: {\n \".mp3\": \"audio/mpeg\",\n \".wav\": \"audio/wav\",\n \".flac\": \"audio/flac\",\n \".aac\": \"audio/aac\",\n \".ogg\": \"audio/ogg\",\n \".m4a\": \"audio/mp4\",\n \".opus\": \"audio/opus\",\n },\n document: {\n \".pdf\": \"application/pdf\",\n \".doc\": \"application/msword\",\n \".docx\":\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n \".odt\": \"application/vnd.oasis.opendocument.text\",\n \".txt\": \"text/plain\",\n \".rtf\": \"application/rtf\",\n \".md\": \"text/markdown\",\n \".markdown\": \"text/markdown\",\n \".tex\": \"application/x-tex\",\n \".log\": \"text/plain\",\n \".json\": \"application/json\",\n \".xml\": \"application/xml\",\n \".yaml\": \"application/x-yaml\",\n \".yml\": \"application/x-yaml\",\n \".ini\": \"text/plain\",\n \".cfg\": \"text/plain\",\n \".toml\": \"application/toml\",\n \".csv\": \"text/csv\",\n \".tsv\": \"text/tab-separated-values\",\n },\n presentation: {\n \".ppt\": \"application/vnd.ms-powerpoint\",\n \".pptx\":\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n \".odp\": \"application/vnd.oasis.opendocument.presentation\",\n },\n spreadsheet: {\n \".xls\": \"application/vnd.ms-excel\",\n \".xlsx\":\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n \".ods\": \"application/vnd.oasis.opendocument.spreadsheet\",\n \".csv\": \"text/csv\",\n \".tsv\": \"text/tab-separated-values\",\n },\n code: {\n \".py\": \"text/x-python\",\n \".java\": \"text/x-java-source\",\n \".c\": \"text/x-c\",\n \".cpp\": \"text/x-c++\",\n \".h\": \"text/x-c\",\n \".hpp\": \"text/x-c++\",\n \".js\": \"application/javascript\",\n \".cjs\": \"application/javascript\",\n \".mjs\": \"application/javascript\",\n \".jsx\": \"application/javascript\",\n \".ts\": \"application/typescript\",\n \".tsx\": \"application/typescript\",\n \".rb\": \"text/x-ruby\",\n \".php\": \"application/x-php\",\n \".go\": \"text/x-go\",\n \".rs\": \"text/rust\",\n \".swift\": \"text/x-swift\",\n \".kt\": \"text/x-kotlin\",\n \".sh\": \"application/x-shellscript\",\n \".bash\": \"application/x-shellscript\",\n \".ps1\": \"application/x-powershell\",\n \".sql\": \"application/sql\",\n \".yml\": \"application/x-yaml\",\n \".coffee\": \"text/coffeescript\",\n \".lua\": \"text/x-lua\",\n },\n archive: {\n \".zip\": \"application/zip\",\n \".tar\": \"application/x-tar\",\n \".gz\": \"application/gzip\",\n \".tgz\": \"application/gzip\",\n \".bz2\": \"application/x-bzip2\",\n \".xz\": \"application/x-xz\",\n \".rar\": \"application/vnd.rar\",\n \".7z\": \"application/x-7z-compressed\",\n \".iso\": \"application/x-iso9660-image\",\n \".dmg\": \"application/x-apple-diskimage\",\n \".jar\": \"application/java-archive\",\n \".war\": \"application/java-archive\",\n \".whl\": \"application/python-wheel\",\n \".egg\": \"application/python-egg\",\n },\n font: {\n \".ttf\": \"font/ttf\",\n \".otf\": \"font/otf\",\n \".woff\": \"font/woff\",\n \".woff2\": \"font/woff2\",\n \".eot\": \"application/vnd.ms-fontobject\",\n },\n executable: {\n \".exe\": \"application/vnd.microsoft.portable-executable\",\n \".dll\": \"application/vnd.microsoft.portable-executable\",\n \".bin\": \"application/octet-stream\",\n \".deb\": \"application/vnd.debian.binary-package\",\n \".rpm\": \"application/x-rpm\",\n },\n} as const;\n\n/** Mirror of MEDIA_TYPES in Python: category -> Set of extensions */\nexport const MEDIA_TYPES: Record<MediaCategory, Set<string>> = Object.fromEntries(\n Object.entries(MIME_TYPES).map(([cat, mapping]) => [\n cat,\n new Set(Object.keys(mapping)),\n ])\n) as Record<MediaCategory, Set<string>>;\n\n/** ---- Helpers ---- */\nfunction toCategorySet(\n categories?: Iterable<string> | string[] | null,\n): Set<MediaCategory> {\n const allCats = new Set(Object.keys(MIME_TYPES)) as Set<string>;\n if (!categories) {\n // all categories\n return new Set(allCats) as Set<MediaCategory>;\n }\n const out = new Set<MediaCategory>();\n for (const c of categories as Iterable<string>) {\n const key = String(c) as MediaCategory;\n if (allCats.has(key)) out.add(key);\n }\n return out.size ? out : (new Set(allCats) as Set<MediaCategory>);\n}\n\nfunction normalizeCategories<T extends MediaOptions | undefined>(\n categories?: Iterable<string> | string[] | null,\n opts?: T,\n): Set<MediaCategory> {\n const selected = categories ?? opts?.media_types ?? null;\n return toCategorySet(selected);\n}\n\nfunction extOf(input: string): string {\n // Behaves like pathlib.Path(...).suffix.lower(): last extension only; lowercased.\n let ext = path.extname(input || \"\");\n if (!ext && input && input.startsWith(\".\")) {\n // user passed \".jpg\" directly\n ext = input;\n }\n return (ext || \"\").toLowerCase();\n}\n\nfunction unionExts(categories: Set<MediaCategory>): Set<string> {\n const out = new Set<string>();\n for (const c of categories) {\n const set = MEDIA_TYPES[c];\n for (const e of set) out.add(e);\n }\n return out;\n}\n\n/** ---- API (Python parity) ---- */\n\n/**\n * Return a sub-map of MEDIA_TYPES for the given categories.\n * If categories is falsy, returns all categories.\n */\nexport function getMediaMap(\n categories?: Iterable<string> | string[] | null,\n opts?: MediaOptions,\n): Partial<Record<MediaCategory, Set<string>>> {\n const cats = normalizeCategories(categories, opts);\n const result: Partial<Record<MediaCategory, Set<string>>> = {};\n for (const c of cats) result[c] = new Set(MEDIA_TYPES[c]);\n return result;\n}\n\n/**\n * Return a flat, sorted list of all extensions for the given categories.\n */\nexport function getMediaExts(\n categories?: Iterable<string> | string[] | null,\n opts?: MediaOptions,\n): string[] {\n const cats = normalizeCategories(categories, opts);\n return Array.from(unionExts(cats)).sort();\n}\n\n/**\n * Given a file path or extension, return its media category (e.g. \"image\") or null.\n * Mirrors Python's confirm_type.\n */\nexport function confirmType(\n pathOrExt: string,\n categories?: Iterable<string> | string[] | null,\n opts?: MediaOptions,\n): MediaCategory | null {\n const cats = normalizeCategories(categories, opts);\n const ext = extOf(pathOrExt);\n // Preserve object insertion order like Python dict iteration\n for (const [category, exts] of Object.entries(MEDIA_TYPES) as [\n MediaCategory,\n Set<string>,\n ][]) {\n if (!cats.has(category)) continue;\n if (ext && exts.has(ext)) return category;\n }\n return null;\n}\n\n/**\n * True if the given file path or extension belongs to one of the categories.\n */\nexport function isMediaType(\n pathOrExt: string,\n categories?: Iterable<string> | string[] | null,\n opts?: MediaOptions,\n): boolean {\n return confirmType(pathOrExt, categories, opts) !== null;\n}\n\n/**\n * Look up the MIME type by extension; fall back to 'application/octet-stream'.\n */\nexport function getMimeType(pathOrExt: string): string {\n const ext = extOf(pathOrExt);\n for (const mapping of Object.values(MIME_TYPES)) {\n if (ext && mapping[ext as keyof typeof mapping]) {\n return mapping[ext as keyof typeof mapping] as string;\n }\n }\n return \"application/octet-stream\";\n}\n\nexport function getAllFileTypesSync(\n directory: string,\n categories?: Iterable<string> | string[] | null,\n opts?: MediaOptions,\n): string[] {\n // 🧩 Skip entirely if fs isn't available\n if (!fs || !path) return [];\n\n try {\n const stat = fs.statSync(directory);\n if (!stat.isDirectory()) return [];\n\n const cats = normalizeCategories(categories, opts);\n const wanted = unionExts(cats);\n const results: string[] = [];\n\n function walkSync(dir: string) {\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n for (const ent of entries) {\n const full = path.join(dir, ent.name);\n if (ent.isDirectory()) {\n walkSync(full);\n } else if (ent.isFile()) {\n const ext = path.extname(ent.name).toLowerCase();\n if (wanted.has(ext)) results.push(full);\n }\n }\n }\n\n walkSync(directory);\n return results;\n } catch {\n return [];\n }\n}\n\nexport async function getAllFileTypes(\n directory: string,\n categories?: Iterable<string> | string[] | null,\n opts?: MediaOptions,\n): Promise<string[]> {\n // 🧩 Skip entirely if fsp isn't available\n if (!fsp || !path) return [];\n\n try {\n const stat = await fsp.stat(directory);\n if (!stat.isDirectory()) return [];\n\n const cats = normalizeCategories(categories, opts);\n const wanted = unionExts(cats);\n const results: string[] = [];\n\n async function walkAsync(dir: string): Promise<void> {\n const entries = await fsp.readdir(dir, { withFileTypes: true });\n for (const ent of entries) {\n const full = path.join(dir, ent.name);\n if (ent.isDirectory()) {\n await walkAsync(full);\n } else if (ent.isFile()) {\n const ext = path.extname(ent.name).toLowerCase();\n if (wanted.has(ext)) results.push(full);\n }\n }\n }\n\n await walkAsync(directory);\n return results;\n } catch {\n return [];\n }\n}\n\n\n/** Optional convenience re-exports that mirror your Python names */\nexport const get_all_file_types = getAllFileTypes;\nexport const get_media_map = getMediaMap;\nexport const get_media_exts = getMediaExts;\nexport const confirm_type = confirmType;\nexport const is_media_type = isMediaType;\nexport const get_mime_type = getMimeType;\n"],"names":[],"mappings":";;;;;AAAA;AAeA;AACO,MAAM,UAAU,GAAG;AACxB,IAAA,KAAK,EAAE;AACL,QAAA,MAAM,EAAE,YAAY;AACpB,QAAA,OAAO,EAAE,YAAY;AACrB,QAAA,MAAM,EAAE,WAAW;AACnB,QAAA,MAAM,EAAE,WAAW;AACnB,QAAA,MAAM,EAAE,WAAW;AACnB,QAAA,OAAO,EAAE,YAAY;AACrB,QAAA,OAAO,EAAE,YAAY;AACrB,QAAA,MAAM,EAAE,eAAe;AACvB,QAAA,MAAM,EAAE,0BAA0B;AAClC,QAAA,OAAO,EAAE,YAAY;AACrB,QAAA,MAAM,EAAE,2BAA2B;AACnC,QAAA,MAAM,EAAE,aAAa;AACtB,KAAA;AACD,IAAA,KAAK,EAAE;AACL,QAAA,MAAM,EAAE,WAAW;AACnB,QAAA,OAAO,EAAE,YAAY;AACrB,QAAA,MAAM,EAAE,WAAW;AACnB,QAAA,MAAM,EAAE,iBAAiB;AACzB,QAAA,MAAM,EAAE,iBAAiB;AACzB,QAAA,MAAM,EAAE,kBAAkB;AAC1B,QAAA,MAAM,EAAE,aAAa;AACrB,QAAA,MAAM,EAAE,gB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C3B,MAAM,aAAa,GAAG;AACtB,MAAM,cAAc,GAAG;AACvB,MAAM,YAAY,GAAG;AACrB,MAAM,aAAa,GAAG;AACtB,MAAM,aAAa,GAAG;;;;"}
|
|
1
|
+
{"version":3,"file":"server.js","sources":["../../src/server/src/read_utils/src/readJsonFile.node.ts"],"sourcesContent":["import { readFileSync } from \"fs\";\nimport { resolve, isAbsolute } from \"path\";\n\nexport function readJsonFileNode<T = any>(\n relativeOrAbsolutePath: string\n): T | null {\n try {\n const filePath = isAbsolute(relativeOrAbsolutePath)\n ? relativeOrAbsolutePath\n : resolve(process.cwd(), relativeOrAbsolutePath);\n\n return JSON.parse(readFileSync(filePath, \"utf8\")) as T;\n } catch {\n return null;\n }\n}\n"],"names":[],"mappings":";;;;AAGM,SAAU,gBAAgB,CAC9B,sBAA8B,EAAA;AAE9B,IAAA,IAAI;AACF,QAAA,MAAM,QAAQ,GAAG,UAAU,CAAC,sBAAsB;AAChD,cAAE;cACA,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,sBAAsB,CAAC;QAElD,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAM;IACxD;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,IAAI;IACb;AACF;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src';
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './read_utils';
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './readJsonFile.browser';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safely walk `globalThis` (or window/document) by a chain of property names.
|
|
3
|
+
* Returns `undefined` if any step is missing.
|
|
4
|
+
*/
|
|
5
|
+
export declare function safeGlobalProp<T = any>(...path: string[]): T | undefined;
|
|
6
|
+
export declare function readJsonFileBrowser<T = any>(url: string): Promise<T | null>;
|
|
@@ -1 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safely walk `globalThis` (or window/document) by a chain of property names.
|
|
3
|
+
* Returns `undefined` if any step is missing.
|
|
4
|
+
*/
|
|
5
|
+
export declare function safeGlobalProp<T = any>(...path: string[]): T | undefined;
|
|
1
6
|
export declare function readJsonFileBrowser<T = any>(url: string): Promise<T | null>;
|
|
@@ -3,10 +3,9 @@ export type MimeByExt = Record<string, string>;
|
|
|
3
3
|
export type MediaMap = Record<string, MimeByExt>;
|
|
4
4
|
export type MediaCategory = keyof typeof MIME_TYPES;
|
|
5
5
|
export interface MediaOptions {
|
|
6
|
-
/** Alias to mirror the Python **kwargs['media_types'] behavior */
|
|
7
6
|
media_types?: Iterable<string> | string[] | null;
|
|
8
7
|
}
|
|
9
|
-
/** ---- Data
|
|
8
|
+
/** ---- Data ---- */
|
|
10
9
|
export declare const MIME_TYPES: {
|
|
11
10
|
readonly image: {
|
|
12
11
|
readonly ".jpg": "image/jpeg";
|
|
@@ -136,35 +135,15 @@ export declare const MIME_TYPES: {
|
|
|
136
135
|
readonly ".rpm": "application/x-rpm";
|
|
137
136
|
};
|
|
138
137
|
};
|
|
139
|
-
/**
|
|
138
|
+
/** category -> Set of extensions */
|
|
140
139
|
export declare const MEDIA_TYPES: Record<MediaCategory, Set<string>>;
|
|
141
|
-
/** ---- API
|
|
142
|
-
/**
|
|
143
|
-
* Return a sub-map of MEDIA_TYPES for the given categories.
|
|
144
|
-
* If categories is falsy, returns all categories.
|
|
145
|
-
*/
|
|
140
|
+
/** ---- API ---- */
|
|
146
141
|
export declare function getMediaMap(categories?: Iterable<string> | string[] | null, opts?: MediaOptions): Partial<Record<MediaCategory, Set<string>>>;
|
|
147
|
-
/**
|
|
148
|
-
* Return a flat, sorted list of all extensions for the given categories.
|
|
149
|
-
*/
|
|
150
142
|
export declare function getMediaExts(categories?: Iterable<string> | string[] | null, opts?: MediaOptions): string[];
|
|
151
|
-
/**
|
|
152
|
-
* Given a file path or extension, return its media category (e.g. "image") or null.
|
|
153
|
-
* Mirrors Python's confirm_type.
|
|
154
|
-
*/
|
|
155
143
|
export declare function confirmType(pathOrExt: string, categories?: Iterable<string> | string[] | null, opts?: MediaOptions): MediaCategory | null;
|
|
156
|
-
/**
|
|
157
|
-
* True if the given file path or extension belongs to one of the categories.
|
|
158
|
-
*/
|
|
159
144
|
export declare function isMediaType(pathOrExt: string, categories?: Iterable<string> | string[] | null, opts?: MediaOptions): boolean;
|
|
160
|
-
/**
|
|
161
|
-
* Look up the MIME type by extension; fall back to 'application/octet-stream'.
|
|
162
|
-
*/
|
|
163
145
|
export declare function getMimeType(pathOrExt: string): string;
|
|
164
|
-
|
|
165
|
-
export declare function getAllFileTypes(directory: string, categories?: Iterable<string> | string[] | null, opts?: MediaOptions): Promise<string[]>;
|
|
166
|
-
/** Optional convenience re-exports that mirror your Python names */
|
|
167
|
-
export declare const get_all_file_types: typeof getAllFileTypes;
|
|
146
|
+
/** snake_case aliases */
|
|
168
147
|
export declare const get_media_map: typeof getMediaMap;
|
|
169
148
|
export declare const get_media_exts: typeof getMediaExts;
|
|
170
149
|
export declare const confirm_type: typeof confirmType;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import 'server-only';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './read_utils';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** ---- Types ---- */
|
|
2
|
+
export type MimeByExt = Record<string, string>;
|
|
3
|
+
export type MediaMap = Record<string, MimeByExt>;
|
|
4
|
+
export type MediaCategory = keyof typeof MIME_TYPES;
|
|
5
|
+
export interface MediaOptions {
|
|
6
|
+
media_types?: Iterable<string> | string[] | null;
|
|
7
|
+
}
|
|
8
|
+
/** ---- MIME TYPES ---- */
|
|
9
|
+
export declare const MIME_TYPES: {
|
|
10
|
+
readonly image: {
|
|
11
|
+
readonly ".jpg": "image/jpeg";
|
|
12
|
+
readonly ".png": "image/png";
|
|
13
|
+
readonly ".webp": "image/webp";
|
|
14
|
+
};
|
|
15
|
+
readonly video: {
|
|
16
|
+
readonly ".mp4": "video/mp4";
|
|
17
|
+
readonly ".webm": "video/webm";
|
|
18
|
+
};
|
|
19
|
+
readonly audio: {
|
|
20
|
+
readonly ".mp3": "audio/mpeg";
|
|
21
|
+
readonly ".wav": "audio/wav";
|
|
22
|
+
};
|
|
23
|
+
readonly document: {
|
|
24
|
+
readonly ".pdf": "application/pdf";
|
|
25
|
+
readonly ".txt": "text/plain";
|
|
26
|
+
};
|
|
27
|
+
readonly code: {
|
|
28
|
+
readonly ".ts": "application/typescript";
|
|
29
|
+
readonly ".js": "application/javascript";
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/** ---- Derived ---- */
|
|
33
|
+
export declare const MEDIA_TYPES: Record<MediaCategory, Set<string>>;
|
|
34
|
+
/** ---- API ---- */
|
|
35
|
+
export declare function confirmType(pathOrExt: string, categories?: Iterable<string> | string[] | null): MediaCategory | null;
|
|
36
|
+
export declare function isMediaType(pathOrExt: string, categories?: Iterable<string> | string[] | null): boolean;
|
|
37
|
+
export declare function getMimeType(pathOrExt: string): string;
|
|
@@ -3,10 +3,9 @@ export type MimeByExt = Record<string, string>;
|
|
|
3
3
|
export type MediaMap = Record<string, MimeByExt>;
|
|
4
4
|
export type MediaCategory = keyof typeof MIME_TYPES;
|
|
5
5
|
export interface MediaOptions {
|
|
6
|
-
/** Alias to mirror the Python **kwargs['media_types'] behavior */
|
|
7
6
|
media_types?: Iterable<string> | string[] | null;
|
|
8
7
|
}
|
|
9
|
-
/** ---- Data
|
|
8
|
+
/** ---- Data ---- */
|
|
10
9
|
export declare const MIME_TYPES: {
|
|
11
10
|
readonly image: {
|
|
12
11
|
readonly ".jpg": "image/jpeg";
|
|
@@ -136,35 +135,15 @@ export declare const MIME_TYPES: {
|
|
|
136
135
|
readonly ".rpm": "application/x-rpm";
|
|
137
136
|
};
|
|
138
137
|
};
|
|
139
|
-
/**
|
|
138
|
+
/** category -> Set of extensions */
|
|
140
139
|
export declare const MEDIA_TYPES: Record<MediaCategory, Set<string>>;
|
|
141
|
-
/** ---- API
|
|
142
|
-
/**
|
|
143
|
-
* Return a sub-map of MEDIA_TYPES for the given categories.
|
|
144
|
-
* If categories is falsy, returns all categories.
|
|
145
|
-
*/
|
|
140
|
+
/** ---- API ---- */
|
|
146
141
|
export declare function getMediaMap(categories?: Iterable<string> | string[] | null, opts?: MediaOptions): Partial<Record<MediaCategory, Set<string>>>;
|
|
147
|
-
/**
|
|
148
|
-
* Return a flat, sorted list of all extensions for the given categories.
|
|
149
|
-
*/
|
|
150
142
|
export declare function getMediaExts(categories?: Iterable<string> | string[] | null, opts?: MediaOptions): string[];
|
|
151
|
-
/**
|
|
152
|
-
* Given a file path or extension, return its media category (e.g. "image") or null.
|
|
153
|
-
* Mirrors Python's confirm_type.
|
|
154
|
-
*/
|
|
155
143
|
export declare function confirmType(pathOrExt: string, categories?: Iterable<string> | string[] | null, opts?: MediaOptions): MediaCategory | null;
|
|
156
|
-
/**
|
|
157
|
-
* True if the given file path or extension belongs to one of the categories.
|
|
158
|
-
*/
|
|
159
144
|
export declare function isMediaType(pathOrExt: string, categories?: Iterable<string> | string[] | null, opts?: MediaOptions): boolean;
|
|
160
|
-
/**
|
|
161
|
-
* Look up the MIME type by extension; fall back to 'application/octet-stream'.
|
|
162
|
-
*/
|
|
163
145
|
export declare function getMimeType(pathOrExt: string): string;
|
|
164
|
-
|
|
165
|
-
export declare function getAllFileTypes(directory: string, categories?: Iterable<string> | string[] | null, opts?: MediaOptions): Promise<string[]>;
|
|
166
|
-
/** Optional convenience re-exports that mirror your Python names */
|
|
167
|
-
export declare const get_all_file_types: typeof getAllFileTypes;
|
|
146
|
+
/** snake_case aliases */
|
|
168
147
|
export declare const get_media_map: typeof getMediaMap;
|
|
169
148
|
export declare const get_media_exts: typeof getMediaExts;
|
|
170
149
|
export declare const confirm_type: typeof confirmType;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './readJsonFile.node';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function readJsonFileNode<T = any>(relativeOrAbsolutePath: string): T | null;
|