@putkoff/abstract-utilities 1.0.113 → 1.0.124
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/client.js +1 -11
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/functions.js +4 -14
- package/dist/cjs/functions.js.map +1 -1
- package/dist/cjs/index.js +4 -14
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/{print_utils-DzyRoj6m.js → print_utils-DhPs0s0W.js} +6 -16
- package/dist/cjs/print_utils-DhPs0s0W.js.map +1 -0
- package/dist/cjs/safe_storage-B6MYZDKg.js +941 -0
- package/dist/cjs/safe_storage-B6MYZDKg.js.map +1 -0
- package/dist/esm/client.js +1 -11
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/functions.js +2 -12
- package/dist/esm/functions.js.map +1 -1
- package/dist/esm/index.js +2 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/{print_utils-qqcMhSul.js → print_utils-gTxtZBM7.js} +2 -12
- package/dist/esm/print_utils-gTxtZBM7.js.map +1 -0
- package/dist/esm/safe_storage-D4QfcTw0.js +897 -0
- package/dist/esm/safe_storage-D4QfcTw0.js.map +1 -0
- package/dist/types/client/auth/index.d.ts +1 -1
- package/dist/types/client/auth/src/index.d.ts +1 -1
- package/dist/types/client/fetch/src/fetch_auth.d.ts +1 -1
- package/dist/types/client/fetch/src/index.d.ts +1 -1
- package/dist/types/client/index.d.ts +2 -2
- package/dist/types/client/ui_utils/index.d.ts +1 -1
- package/dist/types/client/ui_utils/src/index.d.ts +4 -4
- package/dist/types/functions/auth_utils/imports.d.ts +2 -2
- package/dist/types/functions/auth_utils/index.d.ts +1 -1
- package/dist/types/functions/auth_utils/src/index.d.ts +1 -1
- package/dist/types/functions/auth_utils/src/jwt_core.d.ts +1 -1
- package/dist/types/functions/auth_utils/src/token_utils (Copy).d.ts +1 -1
- package/dist/types/functions/auth_utils/src/token_utils.d.ts +1 -1
- package/dist/types/functions/config_utils/imports.d.ts +3 -3
- package/dist/types/functions/config_utils/index.d.ts +1 -1
- package/dist/types/functions/config_utils/src/config_utils.d.ts +1 -1
- package/dist/types/functions/config_utils/src/index.d.ts +1 -1
- package/dist/types/functions/constants_utils/index.d.ts +1 -1
- package/dist/types/functions/constants_utils/src/index.d.ts +1 -1
- package/dist/types/functions/env_utils/imports.d.ts +1 -1
- package/dist/types/functions/env_utils/index.d.ts +1 -1
- package/dist/types/functions/env_utils/src/index.d.ts +1 -1
- package/dist/types/functions/fetch_utils/imports.d.ts +2 -2
- package/dist/types/functions/fetch_utils/index.d.ts +1 -1
- package/dist/types/functions/fetch_utils/src/index.d.ts +3 -3
- package/dist/types/functions/fetch_utils/src/utils.d.ts +1 -1
- package/dist/types/functions/inspect_utils/index.d.ts +2 -2
- package/dist/types/functions/inspect_utils/src/index.d.ts +1 -1
- package/dist/types/functions/math_utils/conversions.d.ts +1 -1
- package/dist/types/functions/math_utils/index.d.ts +6 -6
- package/dist/types/functions/path_utils/imports.d.ts +2 -2
- package/dist/types/functions/path_utils/index.d.ts +1 -1
- package/dist/types/functions/path_utils/src/index.d.ts +6 -6
- package/dist/types/functions/print_utils/imports.d.ts +1 -1
- package/dist/types/functions/print_utils/index.d.ts +1 -1
- package/dist/types/functions/print_utils/src/index.d.ts +1 -1
- package/dist/types/functions/read_utils/imports.d.ts +1 -1
- package/dist/types/functions/read_utils/index.d.ts +1 -1
- package/dist/types/functions/read_utils/src/index.d.ts +3 -3
- package/dist/types/functions/rndm_utils/imports.d.ts +0 -1
- package/dist/types/functions/rndm_utils/index.d.ts +1 -1
- package/dist/types/functions/rndm_utils/src/index.d.ts +1 -1
- package/dist/types/functions/safe_utils/imports.d.ts +1 -1
- package/dist/types/functions/safe_utils/index.d.ts +1 -1
- package/dist/types/functions/safe_utils/src/index.d.ts +4 -4
- package/dist/types/functions/size_utils/index.d.ts +1 -1
- package/dist/types/functions/size_utils/src/index.d.ts +1 -1
- package/dist/types/functions/string_utils/index.d.ts +1 -1
- package/dist/types/functions/string_utils/src/index.d.ts +2 -2
- package/dist/types/functions/type_utils/imports.d.ts +0 -1
- package/dist/types/functions/type_utils/index.d.ts +1 -1
- package/dist/types/functions/type_utils/src/imports.d.ts +0 -1
- package/dist/types/functions/type_utils/src/index.d.ts +6 -6
- package/dist/types/functions/variable_utils/imports.d.ts +1 -1
- package/dist/types/functions/variable_utils/index.d.ts +1 -1
- package/dist/types/functions/variable_utils/src/index.d.ts +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/server/index.d.ts +1 -1
- package/dist/types/server/src/index.d.ts +1 -1
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/path-browserify.d.ts +2 -3
- package/dist/types/types/src/index.d.ts +4 -4
- package/dist/types/utils/imports.d.ts +1 -1
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/src/index.d.ts +2 -2
- package/package.json +2 -2
- package/dist/cjs/print_utils-DzyRoj6m.js.map +0 -1
- package/dist/cjs/safe_storage-CJgWghnh.js +0 -15986
- package/dist/cjs/safe_storage-CJgWghnh.js.map +0 -1
- package/dist/esm/print_utils-qqcMhSul.js.map +0 -1
- package/dist/esm/safe_storage-CMuv35Vo.js +0 -15941
- package/dist/esm/safe_storage-CMuv35Vo.js.map +0 -1
- package/dist/types/client/auth/index.js +0 -3
- package/dist/types/client/auth/src/index.js +0 -3
- package/dist/types/client/auth/src/token_client.js +0 -73
- package/dist/types/client/fetch/src/fetch_auth.js +0 -26
- package/dist/types/client/fetch/src/index.js +0 -2
- package/dist/types/client/index.js +0 -4
- package/dist/types/client/ui_utils/index.js +0 -2
- package/dist/types/client/ui_utils/src/button.js +0 -34
- package/dist/types/client/ui_utils/src/checkbox.js +0 -18
- package/dist/types/client/ui_utils/src/index.js +0 -4
- package/dist/types/client/ui_utils/src/input.js +0 -18
- package/dist/types/client/ui_utils/src/spinner.js +0 -5
- package/dist/types/functions/auth_utils/imports.js +0 -1
- package/dist/types/functions/auth_utils/index.js +0 -1
- package/dist/types/functions/auth_utils/src/index.js +0 -1
- package/dist/types/functions/auth_utils/src/jwt_core.js +0 -25
- package/dist/types/functions/auth_utils/src/token_utils (Copy).js +0 -25
- package/dist/types/functions/auth_utils/src/token_utils.js +0 -105
- package/dist/types/functions/config_utils/imports.js +0 -2
- package/dist/types/functions/config_utils/index.js +0 -1
- package/dist/types/functions/config_utils/src/config_utils.js +0 -83
- package/dist/types/functions/config_utils/src/index.js +0 -1
- package/dist/types/functions/constants_utils/index.js +0 -1
- package/dist/types/functions/constants_utils/src/constants.js +0 -7
- package/dist/types/functions/constants_utils/src/index.js +0 -1
- package/dist/types/functions/env_utils/imports.js +0 -1
- package/dist/types/functions/env_utils/index.js +0 -1
- package/dist/types/functions/env_utils/src/index.js +0 -1
- package/dist/types/functions/env_utils/src/window_utils.js +0 -47
- package/dist/types/functions/fetch_utils/imports.js +0 -1
- package/dist/types/functions/fetch_utils/index.js +0 -1
- package/dist/types/functions/fetch_utils/src/fetch_utils.js +0 -70
- package/dist/types/functions/fetch_utils/src/index.js +0 -3
- package/dist/types/functions/fetch_utils/src/url_utils.js +0 -86
- package/dist/types/functions/fetch_utils/src/utils.js +0 -102
- package/dist/types/functions/index.js +0 -17
- package/dist/types/functions/inspect_utils/imports.js +0 -1
- package/dist/types/functions/inspect_utils/index.js +0 -2
- package/dist/types/functions/inspect_utils/src/caller_utils.js +0 -28
- package/dist/types/functions/inspect_utils/src/index.js +0 -1
- package/dist/types/functions/math_utils/bigint_utils.js +0 -36
- package/dist/types/functions/math_utils/constants.js +0 -37
- package/dist/types/functions/math_utils/conversions.js +0 -129
- package/dist/types/functions/math_utils/index.js +0 -6
- package/dist/types/functions/math_utils/safe_math.js +0 -35
- package/dist/types/functions/math_utils/scaleInterfaces.js +0 -3
- package/dist/types/functions/math_utils/time_utils.js +0 -4
- package/dist/types/functions/path_utils/imports.js +0 -27
- package/dist/types/functions/path_utils/index.js +0 -1
- package/dist/types/functions/path_utils/src/base_dirs.js +0 -17
- package/dist/types/functions/path_utils/src/function_dirs.js +0 -42
- package/dist/types/functions/path_utils/src/index.js +0 -6
- package/dist/types/functions/path_utils/src/misc_dirs.js +0 -15
- package/dist/types/functions/path_utils/src/path_utils.js +0 -160
- package/dist/types/functions/path_utils/src/paths.js +0 -12
- package/dist/types/functions/path_utils/src/src_dirs.js +0 -25
- package/dist/types/functions/print_utils/imports.js +0 -1
- package/dist/types/functions/print_utils/index.js +0 -1
- package/dist/types/functions/print_utils/src/index.js +0 -1
- package/dist/types/functions/print_utils/src/print_utils.js +0 -14
- package/dist/types/functions/read_utils/imports.js +0 -1
- package/dist/types/functions/read_utils/index.js +0 -1
- package/dist/types/functions/read_utils/src/index.js +0 -3
- package/dist/types/functions/read_utils/src/readJsonFile.browser.js +0 -26
- package/dist/types/functions/read_utils/src/readJsonFile.js +0 -35
- package/dist/types/functions/read_utils/src/readJsonFile.node.js +0 -13
- package/dist/types/functions/rndm_utils/imports.js +0 -1
- package/dist/types/functions/rndm_utils/index.js +0 -1
- package/dist/types/functions/rndm_utils/src/index.js +0 -1
- package/dist/types/functions/rndm_utils/src/utils.js +0 -12
- package/dist/types/functions/safe_utils/imports.js +0 -1
- package/dist/types/functions/safe_utils/index.js +0 -1
- package/dist/types/functions/safe_utils/src/index.js +0 -4
- package/dist/types/functions/safe_utils/src/safe_document.js +0 -12
- package/dist/types/functions/safe_utils/src/safe_globals.js +0 -14
- package/dist/types/functions/safe_utils/src/safe_storage.js +0 -50
- package/dist/types/functions/safe_utils/src/safe_window.js +0 -42
- package/dist/types/functions/size_utils/index.js +0 -1
- package/dist/types/functions/size_utils/src/index.js +0 -1
- package/dist/types/functions/size_utils/src/sizeUtils.js +0 -44
- package/dist/types/functions/string_utils/index.js +0 -1
- package/dist/types/functions/string_utils/src/index.js +0 -2
- package/dist/types/functions/string_utils/src/quote_utils.js +0 -17
- package/dist/types/functions/string_utils/src/string_utils.js +0 -186
- package/dist/types/functions/type_utils/imports.js +0 -1
- package/dist/types/functions/type_utils/index.js +0 -1
- package/dist/types/functions/type_utils/src/clean_utils.js +0 -38
- package/dist/types/functions/type_utils/src/ensure_utils.js +0 -84
- package/dist/types/functions/type_utils/src/imports.js +0 -1
- package/dist/types/functions/type_utils/src/index.js +0 -6
- package/dist/types/functions/type_utils/src/json_utils.js +0 -93
- package/dist/types/functions/type_utils/src/list_utils.js +0 -83
- package/dist/types/functions/type_utils/src/mime_utils.js +0 -314
- package/dist/types/functions/type_utils/src/null_utils.js +0 -21
- package/dist/types/functions/type_utils/src/type_utils.js +0 -39
- package/dist/types/functions/variable_utils/imports.js +0 -1
- package/dist/types/functions/variable_utils/index.js +0 -1
- package/dist/types/functions/variable_utils/src/index.js +0 -1
- package/dist/types/functions/variable_utils/src/variable_utils.js +0 -34
- package/dist/types/index.js +0 -2
- package/dist/types/server/index.js +0 -2
- package/dist/types/server/src/index.js +0 -2
- package/dist/types/server/src/mime_utils.js +0 -314
- package/dist/types/types/index.js +0 -1
- package/dist/types/types/path-browserify.js +0 -1
- package/dist/types/types/src/Files.js +0 -1
- package/dist/types/types/src/index.js +0 -4
- package/dist/types/types/src/login.js +0 -1
- package/dist/types/types/src/logout.js +0 -1
- package/dist/types/types/src/utils.js +0 -1
- package/dist/types/utils/imports.js +0 -1
- package/dist/types/utils/index.js +0 -1
- package/dist/types/utils/src/Input.js +0 -2
- package/dist/types/utils/src/config.js +0 -27
- package/dist/types/utils/src/index.js +0 -2
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
// mediaTypes.ts
|
|
11
|
-
import * as fs from "node:fs";
|
|
12
|
-
import * as fsp from "node:fs/promises";
|
|
13
|
-
import * as path from "node:path";
|
|
14
|
-
/** ---- Data: large but explicit, mirrors your Python mapping ---- */
|
|
15
|
-
export const MIME_TYPES = {
|
|
16
|
-
image: {
|
|
17
|
-
".jpg": "image/jpeg",
|
|
18
|
-
".jpeg": "image/jpeg",
|
|
19
|
-
".png": "image/png",
|
|
20
|
-
".gif": "image/gif",
|
|
21
|
-
".bmp": "image/bmp",
|
|
22
|
-
".tiff": "image/tiff",
|
|
23
|
-
".webp": "image/webp",
|
|
24
|
-
".svg": "image/svg+xml",
|
|
25
|
-
".ico": "image/vnd.microsoft.icon",
|
|
26
|
-
".heic": "image/heic",
|
|
27
|
-
".psd": "image/vnd.adobe.photoshop",
|
|
28
|
-
".raw": "image/x-raw",
|
|
29
|
-
},
|
|
30
|
-
video: {
|
|
31
|
-
".mp4": "video/mp4",
|
|
32
|
-
".webm": "video/webm",
|
|
33
|
-
".ogg": "video/ogg",
|
|
34
|
-
".mov": "video/quicktime",
|
|
35
|
-
".avi": "video/x-msvideo",
|
|
36
|
-
".mkv": "video/x-matroska",
|
|
37
|
-
".flv": "video/x-flv",
|
|
38
|
-
".wmv": "video/x-ms-wmv",
|
|
39
|
-
".3gp": "video/3gpp",
|
|
40
|
-
".ts": "video/mp2t",
|
|
41
|
-
".mpeg": "video/mpeg",
|
|
42
|
-
".mpg": "video/mpg",
|
|
43
|
-
},
|
|
44
|
-
audio: {
|
|
45
|
-
".mp3": "audio/mpeg",
|
|
46
|
-
".wav": "audio/wav",
|
|
47
|
-
".flac": "audio/flac",
|
|
48
|
-
".aac": "audio/aac",
|
|
49
|
-
".ogg": "audio/ogg",
|
|
50
|
-
".m4a": "audio/mp4",
|
|
51
|
-
".opus": "audio/opus",
|
|
52
|
-
},
|
|
53
|
-
document: {
|
|
54
|
-
".pdf": "application/pdf",
|
|
55
|
-
".doc": "application/msword",
|
|
56
|
-
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
57
|
-
".odt": "application/vnd.oasis.opendocument.text",
|
|
58
|
-
".txt": "text/plain",
|
|
59
|
-
".rtf": "application/rtf",
|
|
60
|
-
".md": "text/markdown",
|
|
61
|
-
".markdown": "text/markdown",
|
|
62
|
-
".tex": "application/x-tex",
|
|
63
|
-
".log": "text/plain",
|
|
64
|
-
".json": "application/json",
|
|
65
|
-
".xml": "application/xml",
|
|
66
|
-
".yaml": "application/x-yaml",
|
|
67
|
-
".yml": "application/x-yaml",
|
|
68
|
-
".ini": "text/plain",
|
|
69
|
-
".cfg": "text/plain",
|
|
70
|
-
".toml": "application/toml",
|
|
71
|
-
".csv": "text/csv",
|
|
72
|
-
".tsv": "text/tab-separated-values",
|
|
73
|
-
},
|
|
74
|
-
presentation: {
|
|
75
|
-
".ppt": "application/vnd.ms-powerpoint",
|
|
76
|
-
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
77
|
-
".odp": "application/vnd.oasis.opendocument.presentation",
|
|
78
|
-
},
|
|
79
|
-
spreadsheet: {
|
|
80
|
-
".xls": "application/vnd.ms-excel",
|
|
81
|
-
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
82
|
-
".ods": "application/vnd.oasis.opendocument.spreadsheet",
|
|
83
|
-
".csv": "text/csv",
|
|
84
|
-
".tsv": "text/tab-separated-values",
|
|
85
|
-
},
|
|
86
|
-
code: {
|
|
87
|
-
".py": "text/x-python",
|
|
88
|
-
".java": "text/x-java-source",
|
|
89
|
-
".c": "text/x-c",
|
|
90
|
-
".cpp": "text/x-c++",
|
|
91
|
-
".h": "text/x-c",
|
|
92
|
-
".hpp": "text/x-c++",
|
|
93
|
-
".js": "application/javascript",
|
|
94
|
-
".cjs": "application/javascript",
|
|
95
|
-
".mjs": "application/javascript",
|
|
96
|
-
".jsx": "application/javascript",
|
|
97
|
-
".ts": "application/typescript",
|
|
98
|
-
".tsx": "application/typescript",
|
|
99
|
-
".rb": "text/x-ruby",
|
|
100
|
-
".php": "application/x-php",
|
|
101
|
-
".go": "text/x-go",
|
|
102
|
-
".rs": "text/rust",
|
|
103
|
-
".swift": "text/x-swift",
|
|
104
|
-
".kt": "text/x-kotlin",
|
|
105
|
-
".sh": "application/x-shellscript",
|
|
106
|
-
".bash": "application/x-shellscript",
|
|
107
|
-
".ps1": "application/x-powershell",
|
|
108
|
-
".sql": "application/sql",
|
|
109
|
-
".yml": "application/x-yaml",
|
|
110
|
-
".coffee": "text/coffeescript",
|
|
111
|
-
".lua": "text/x-lua",
|
|
112
|
-
},
|
|
113
|
-
archive: {
|
|
114
|
-
".zip": "application/zip",
|
|
115
|
-
".tar": "application/x-tar",
|
|
116
|
-
".gz": "application/gzip",
|
|
117
|
-
".tgz": "application/gzip",
|
|
118
|
-
".bz2": "application/x-bzip2",
|
|
119
|
-
".xz": "application/x-xz",
|
|
120
|
-
".rar": "application/vnd.rar",
|
|
121
|
-
".7z": "application/x-7z-compressed",
|
|
122
|
-
".iso": "application/x-iso9660-image",
|
|
123
|
-
".dmg": "application/x-apple-diskimage",
|
|
124
|
-
".jar": "application/java-archive",
|
|
125
|
-
".war": "application/java-archive",
|
|
126
|
-
".whl": "application/python-wheel",
|
|
127
|
-
".egg": "application/python-egg",
|
|
128
|
-
},
|
|
129
|
-
font: {
|
|
130
|
-
".ttf": "font/ttf",
|
|
131
|
-
".otf": "font/otf",
|
|
132
|
-
".woff": "font/woff",
|
|
133
|
-
".woff2": "font/woff2",
|
|
134
|
-
".eot": "application/vnd.ms-fontobject",
|
|
135
|
-
},
|
|
136
|
-
executable: {
|
|
137
|
-
".exe": "application/vnd.microsoft.portable-executable",
|
|
138
|
-
".dll": "application/vnd.microsoft.portable-executable",
|
|
139
|
-
".bin": "application/octet-stream",
|
|
140
|
-
".deb": "application/vnd.debian.binary-package",
|
|
141
|
-
".rpm": "application/x-rpm",
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
/** Mirror of MEDIA_TYPES in Python: category -> Set of extensions */
|
|
145
|
-
export const MEDIA_TYPES = Object.fromEntries(Object.entries(MIME_TYPES).map(([cat, mapping]) => [
|
|
146
|
-
cat,
|
|
147
|
-
new Set(Object.keys(mapping)),
|
|
148
|
-
]));
|
|
149
|
-
/** ---- Helpers ---- */
|
|
150
|
-
function toCategorySet(categories) {
|
|
151
|
-
const allCats = new Set(Object.keys(MIME_TYPES));
|
|
152
|
-
if (!categories) {
|
|
153
|
-
// all categories
|
|
154
|
-
return new Set(allCats);
|
|
155
|
-
}
|
|
156
|
-
const out = new Set();
|
|
157
|
-
for (const c of categories) {
|
|
158
|
-
const key = String(c);
|
|
159
|
-
if (allCats.has(key))
|
|
160
|
-
out.add(key);
|
|
161
|
-
}
|
|
162
|
-
return out.size ? out : new Set(allCats);
|
|
163
|
-
}
|
|
164
|
-
function normalizeCategories(categories, opts) {
|
|
165
|
-
var _a;
|
|
166
|
-
const selected = (_a = categories !== null && categories !== void 0 ? categories : opts === null || opts === void 0 ? void 0 : opts.media_types) !== null && _a !== void 0 ? _a : null;
|
|
167
|
-
return toCategorySet(selected);
|
|
168
|
-
}
|
|
169
|
-
function extOf(input) {
|
|
170
|
-
// Behaves like pathlib.Path(...).suffix.lower(): last extension only; lowercased.
|
|
171
|
-
let ext = path.extname(input || "");
|
|
172
|
-
if (!ext && input && input.startsWith(".")) {
|
|
173
|
-
// user passed ".jpg" directly
|
|
174
|
-
ext = input;
|
|
175
|
-
}
|
|
176
|
-
return (ext || "").toLowerCase();
|
|
177
|
-
}
|
|
178
|
-
function unionExts(categories) {
|
|
179
|
-
const out = new Set();
|
|
180
|
-
for (const c of categories) {
|
|
181
|
-
const set = MEDIA_TYPES[c];
|
|
182
|
-
for (const e of set)
|
|
183
|
-
out.add(e);
|
|
184
|
-
}
|
|
185
|
-
return out;
|
|
186
|
-
}
|
|
187
|
-
/** ---- API (Python parity) ---- */
|
|
188
|
-
/**
|
|
189
|
-
* Return a sub-map of MEDIA_TYPES for the given categories.
|
|
190
|
-
* If categories is falsy, returns all categories.
|
|
191
|
-
*/
|
|
192
|
-
export function getMediaMap(categories, opts) {
|
|
193
|
-
const cats = normalizeCategories(categories, opts);
|
|
194
|
-
const result = {};
|
|
195
|
-
for (const c of cats)
|
|
196
|
-
result[c] = new Set(MEDIA_TYPES[c]);
|
|
197
|
-
return result;
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Return a flat, sorted list of all extensions for the given categories.
|
|
201
|
-
*/
|
|
202
|
-
export function getMediaExts(categories, opts) {
|
|
203
|
-
const cats = normalizeCategories(categories, opts);
|
|
204
|
-
return Array.from(unionExts(cats)).sort();
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Given a file path or extension, return its media category (e.g. "image") or null.
|
|
208
|
-
* Mirrors Python's confirm_type.
|
|
209
|
-
*/
|
|
210
|
-
export function confirmType(pathOrExt, categories, opts) {
|
|
211
|
-
const cats = normalizeCategories(categories, opts);
|
|
212
|
-
const ext = extOf(pathOrExt);
|
|
213
|
-
// Preserve object insertion order like Python dict iteration
|
|
214
|
-
for (const [category, exts] of Object.entries(MEDIA_TYPES)) {
|
|
215
|
-
if (!cats.has(category))
|
|
216
|
-
continue;
|
|
217
|
-
if (ext && exts.has(ext))
|
|
218
|
-
return category;
|
|
219
|
-
}
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* True if the given file path or extension belongs to one of the categories.
|
|
224
|
-
*/
|
|
225
|
-
export function isMediaType(pathOrExt, categories, opts) {
|
|
226
|
-
return confirmType(pathOrExt, categories, opts) !== null;
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Look up the MIME type by extension; fall back to 'application/octet-stream'.
|
|
230
|
-
*/
|
|
231
|
-
export function getMimeType(pathOrExt) {
|
|
232
|
-
const ext = extOf(pathOrExt);
|
|
233
|
-
for (const mapping of Object.values(MIME_TYPES)) {
|
|
234
|
-
if (ext && mapping[ext]) {
|
|
235
|
-
return mapping[ext];
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return "application/octet-stream";
|
|
239
|
-
}
|
|
240
|
-
export function getAllFileTypesSync(directory, categories, opts) {
|
|
241
|
-
// 🧩 Skip entirely if fs isn't available
|
|
242
|
-
if (!fs || !path)
|
|
243
|
-
return [];
|
|
244
|
-
try {
|
|
245
|
-
const stat = fs.statSync(directory);
|
|
246
|
-
if (!stat.isDirectory())
|
|
247
|
-
return [];
|
|
248
|
-
const cats = normalizeCategories(categories, opts);
|
|
249
|
-
const wanted = unionExts(cats);
|
|
250
|
-
const results = [];
|
|
251
|
-
function walkSync(dir) {
|
|
252
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
253
|
-
for (const ent of entries) {
|
|
254
|
-
const full = path.join(dir, ent.name);
|
|
255
|
-
if (ent.isDirectory()) {
|
|
256
|
-
walkSync(full);
|
|
257
|
-
}
|
|
258
|
-
else if (ent.isFile()) {
|
|
259
|
-
const ext = path.extname(ent.name).toLowerCase();
|
|
260
|
-
if (wanted.has(ext))
|
|
261
|
-
results.push(full);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
walkSync(directory);
|
|
266
|
-
return results;
|
|
267
|
-
}
|
|
268
|
-
catch (_a) {
|
|
269
|
-
return [];
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
export function getAllFileTypes(directory, categories, opts) {
|
|
273
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
274
|
-
// 🧩 Skip entirely if fsp isn't available
|
|
275
|
-
if (!fsp || !path)
|
|
276
|
-
return [];
|
|
277
|
-
try {
|
|
278
|
-
const stat = yield fsp.stat(directory);
|
|
279
|
-
if (!stat.isDirectory())
|
|
280
|
-
return [];
|
|
281
|
-
const cats = normalizeCategories(categories, opts);
|
|
282
|
-
const wanted = unionExts(cats);
|
|
283
|
-
const results = [];
|
|
284
|
-
function walkAsync(dir) {
|
|
285
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
286
|
-
const entries = yield fsp.readdir(dir, { withFileTypes: true });
|
|
287
|
-
for (const ent of entries) {
|
|
288
|
-
const full = path.join(dir, ent.name);
|
|
289
|
-
if (ent.isDirectory()) {
|
|
290
|
-
yield walkAsync(full);
|
|
291
|
-
}
|
|
292
|
-
else if (ent.isFile()) {
|
|
293
|
-
const ext = path.extname(ent.name).toLowerCase();
|
|
294
|
-
if (wanted.has(ext))
|
|
295
|
-
results.push(full);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
yield walkAsync(directory);
|
|
301
|
-
return results;
|
|
302
|
-
}
|
|
303
|
-
catch (_a) {
|
|
304
|
-
return [];
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
/** Optional convenience re-exports that mirror your Python names */
|
|
309
|
-
export const get_all_file_types = getAllFileTypes;
|
|
310
|
-
export const get_media_map = getMediaMap;
|
|
311
|
-
export const get_media_exts = getMediaExts;
|
|
312
|
-
export const confirm_type = confirmType;
|
|
313
|
-
export const is_media_type = isMediaType;
|
|
314
|
-
export const get_mime_type = getMimeType;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// Function to handle undefined or null values
|
|
2
|
-
export function getIfNone(obj, fallback) {
|
|
3
|
-
return obj !== undefined && obj !== null && obj !== '' ? obj : fallback;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Merges non-null values from multiple dictionaries.
|
|
7
|
-
*/
|
|
8
|
-
export function mergeNotNullValues(dictA, dictB, dictC, dictD, dictE) {
|
|
9
|
-
var _a, _b, _c, _d;
|
|
10
|
-
const result = {};
|
|
11
|
-
for (const key of Object.keys(dictA)) {
|
|
12
|
-
result[key] = (_d = (_c = (_b = (_a = dictA[key]) !== null && _a !== void 0 ? _a : dictB === null || dictB === void 0 ? void 0 : dictB[key]) !== null && _b !== void 0 ? _b : dictC === null || dictC === void 0 ? void 0 : dictC[key]) !== null && _c !== void 0 ? _c : dictD === null || dictD === void 0 ? void 0 : dictD[key]) !== null && _d !== void 0 ? _d : dictE === null || dictE === void 0 ? void 0 : dictE[key];
|
|
13
|
-
}
|
|
14
|
-
return result;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Converts an empty object to null.
|
|
18
|
-
*/
|
|
19
|
-
export function emptyObjectToNull(value) {
|
|
20
|
-
return value && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length === 0 ? null : value;
|
|
21
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { ensure_string } from './ensure_utils';
|
|
2
|
-
export function isType(obj, type) {
|
|
3
|
-
if (typeof obj === type) {
|
|
4
|
-
return true;
|
|
5
|
-
}
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
export function isStrInString(obj, string) {
|
|
9
|
-
const obj_str = ensure_string(obj).toLowerCase;
|
|
10
|
-
string = ensure_string(string).toLowerCase;
|
|
11
|
-
if (string.includes(obj_str)) {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
export function getChar(i, string) {
|
|
17
|
-
if (string.length >= i) {
|
|
18
|
-
return ensure_string(string)[i];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export function getAlphaNum(obj) {
|
|
22
|
-
const is_num = isNum(obj);
|
|
23
|
-
const alphas = getAlphas();
|
|
24
|
-
if (is_num) {
|
|
25
|
-
return getChar(obj, alphas);
|
|
26
|
-
}
|
|
27
|
-
if (isStrInString(obj, alphas)) {
|
|
28
|
-
return getChar(obj, alphas);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export function getNums() {
|
|
32
|
-
return '0123456789';
|
|
33
|
-
}
|
|
34
|
-
export function isNum(obj) {
|
|
35
|
-
return !Number.isNaN(Number(obj));
|
|
36
|
-
}
|
|
37
|
-
export function getAlphas() {
|
|
38
|
-
return 'abcdefghijklmnopqrstuvwxyz';
|
|
39
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { eatAll } from './../string_utils';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './src';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './variable_utils';
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { eatAll } from './../imports';
|
|
2
|
-
/**
|
|
3
|
-
* Processes keywords by checking if keywords is a string and splitting it.
|
|
4
|
-
* Then cleans each keyword using `eatAll` with a set of characters to remove.
|
|
5
|
-
*
|
|
6
|
-
* @param keywords - The keywords as a comma-separated string or as an array.
|
|
7
|
-
* @returns An array of cleaned keywords.
|
|
8
|
-
*/
|
|
9
|
-
export function processKeywords(keywords) {
|
|
10
|
-
let keywordArray;
|
|
11
|
-
// If keywords is a string, split it on commas
|
|
12
|
-
if (typeof keywords === "string") {
|
|
13
|
-
keywordArray = keywords.split(",");
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
keywordArray = keywords;
|
|
17
|
-
}
|
|
18
|
-
// Clean each keyword by removing unwanted characters
|
|
19
|
-
return keywordArray.map(keyword => eatAll(keyword, [",", "\n", "\t", " ", "#"]));
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Constructs a keyword string where each keyword is prefixed with a hash (#).
|
|
23
|
-
*
|
|
24
|
-
* @param keywords - An array of keywords.
|
|
25
|
-
* @returns A string with each keyword prefixed by '#'.
|
|
26
|
-
*/
|
|
27
|
-
export function get_keyword_string(keywords) {
|
|
28
|
-
keywords = processKeywords(keywords);
|
|
29
|
-
let allString = "";
|
|
30
|
-
for (const keyword of keywords) {
|
|
31
|
-
allString += ` #${keyword}`;
|
|
32
|
-
}
|
|
33
|
-
return allString;
|
|
34
|
-
}
|
package/dist/types/index.js
DELETED