@putkoff/abstract-utilities 0.1.241 → 0.1.243

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/index.js CHANGED
@@ -2,9 +2,35 @@
2
2
 
3
3
  var react = require('react');
4
4
  var path = require('path');
5
+ var path$2 = require('path-browserify');
6
+ var fs = require('node:fs');
7
+ var fsp = require('node:fs/promises');
8
+ var path$1 = require('node:path');
5
9
  var jsxRuntime = require('react/jsx-runtime');
6
10
 
7
11
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
12
+ function _interopNamespaceDefault(e) {
13
+ var n = Object.create(null);
14
+ if (e) {
15
+ Object.keys(e).forEach(function (k) {
16
+ if (k !== 'default') {
17
+ var d = Object.getOwnPropertyDescriptor(e, k);
18
+ Object.defineProperty(n, k, d.get ? d : {
19
+ enumerable: true,
20
+ get: function () { return e[k]; }
21
+ });
22
+ }
23
+ });
24
+ }
25
+ n.default = e;
26
+ return Object.freeze(n);
27
+ }
28
+
29
+ var path__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(path$2);
30
+ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
31
+ var fsp__namespace = /*#__PURE__*/_interopNamespaceDefault(fsp);
32
+ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$1);
33
+
8
34
  function getSafeDocument() {
9
35
  return typeof document !== 'undefined' ? document : undefined;
10
36
  }
@@ -644,508 +670,6 @@ function url_to_path(urlStr, all_paths) {
644
670
  return null;
645
671
  }
646
672
 
647
- function assertPath(path) {
648
- if (typeof path !== 'string') {
649
- throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
650
- }
651
- }
652
-
653
- // Resolves . and .. elements in a path with directory names
654
- function normalizeStringPosix(path, allowAboveRoot) {
655
- var res = '';
656
- var lastSegmentLength = 0;
657
- var lastSlash = -1;
658
- var dots = 0;
659
- var code;
660
- for (var i = 0; i <= path.length; ++i) {
661
- if (i < path.length)
662
- code = path.charCodeAt(i);
663
- else if (code === 47 /*/*/)
664
- break;
665
- else
666
- code = 47 /*/*/;
667
- if (code === 47 /*/*/) {
668
- if (lastSlash === i - 1 || dots === 1) ; else if (lastSlash !== i - 1 && dots === 2) {
669
- if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) {
670
- if (res.length > 2) {
671
- var lastSlashIndex = res.lastIndexOf('/');
672
- if (lastSlashIndex !== res.length - 1) {
673
- if (lastSlashIndex === -1) {
674
- res = '';
675
- lastSegmentLength = 0;
676
- } else {
677
- res = res.slice(0, lastSlashIndex);
678
- lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
679
- }
680
- lastSlash = i;
681
- dots = 0;
682
- continue;
683
- }
684
- } else if (res.length === 2 || res.length === 1) {
685
- res = '';
686
- lastSegmentLength = 0;
687
- lastSlash = i;
688
- dots = 0;
689
- continue;
690
- }
691
- }
692
- if (allowAboveRoot) {
693
- if (res.length > 0)
694
- res += '/..';
695
- else
696
- res = '..';
697
- lastSegmentLength = 2;
698
- }
699
- } else {
700
- if (res.length > 0)
701
- res += '/' + path.slice(lastSlash + 1, i);
702
- else
703
- res = path.slice(lastSlash + 1, i);
704
- lastSegmentLength = i - lastSlash - 1;
705
- }
706
- lastSlash = i;
707
- dots = 0;
708
- } else if (code === 46 /*.*/ && dots !== -1) {
709
- ++dots;
710
- } else {
711
- dots = -1;
712
- }
713
- }
714
- return res;
715
- }
716
-
717
- function _format(sep, pathObject) {
718
- var dir = pathObject.dir || pathObject.root;
719
- var base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '');
720
- if (!dir) {
721
- return base;
722
- }
723
- if (dir === pathObject.root) {
724
- return dir + base;
725
- }
726
- return dir + sep + base;
727
- }
728
-
729
- var posix = {
730
- // path.resolve([from ...], to)
731
- resolve: function resolve() {
732
- var resolvedPath = '';
733
- var resolvedAbsolute = false;
734
- var cwd;
735
-
736
- for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
737
- var path;
738
- if (i >= 0)
739
- path = arguments[i];
740
- else {
741
- if (cwd === undefined)
742
- cwd = process.cwd();
743
- path = cwd;
744
- }
745
-
746
- assertPath(path);
747
-
748
- // Skip empty entries
749
- if (path.length === 0) {
750
- continue;
751
- }
752
-
753
- resolvedPath = path + '/' + resolvedPath;
754
- resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/;
755
- }
756
-
757
- // At this point the path should be resolved to a full absolute path, but
758
- // handle relative paths to be safe (might happen when process.cwd() fails)
759
-
760
- // Normalize the path
761
- resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
762
-
763
- if (resolvedAbsolute) {
764
- if (resolvedPath.length > 0)
765
- return '/' + resolvedPath;
766
- else
767
- return '/';
768
- } else if (resolvedPath.length > 0) {
769
- return resolvedPath;
770
- } else {
771
- return '.';
772
- }
773
- },
774
-
775
- normalize: function normalize(path) {
776
- assertPath(path);
777
-
778
- if (path.length === 0) return '.';
779
-
780
- var isAbsolute = path.charCodeAt(0) === 47 /*/*/;
781
- var trailingSeparator = path.charCodeAt(path.length - 1) === 47 /*/*/;
782
-
783
- // Normalize the path
784
- path = normalizeStringPosix(path, !isAbsolute);
785
-
786
- if (path.length === 0 && !isAbsolute) path = '.';
787
- if (path.length > 0 && trailingSeparator) path += '/';
788
-
789
- if (isAbsolute) return '/' + path;
790
- return path;
791
- },
792
-
793
- isAbsolute: function isAbsolute(path) {
794
- assertPath(path);
795
- return path.length > 0 && path.charCodeAt(0) === 47 /*/*/;
796
- },
797
-
798
- join: function join() {
799
- if (arguments.length === 0)
800
- return '.';
801
- var joined;
802
- for (var i = 0; i < arguments.length; ++i) {
803
- var arg = arguments[i];
804
- assertPath(arg);
805
- if (arg.length > 0) {
806
- if (joined === undefined)
807
- joined = arg;
808
- else
809
- joined += '/' + arg;
810
- }
811
- }
812
- if (joined === undefined)
813
- return '.';
814
- return posix.normalize(joined);
815
- },
816
-
817
- relative: function relative(from, to) {
818
- assertPath(from);
819
- assertPath(to);
820
-
821
- if (from === to) return '';
822
-
823
- from = posix.resolve(from);
824
- to = posix.resolve(to);
825
-
826
- if (from === to) return '';
827
-
828
- // Trim any leading backslashes
829
- var fromStart = 1;
830
- for (; fromStart < from.length; ++fromStart) {
831
- if (from.charCodeAt(fromStart) !== 47 /*/*/)
832
- break;
833
- }
834
- var fromEnd = from.length;
835
- var fromLen = fromEnd - fromStart;
836
-
837
- // Trim any leading backslashes
838
- var toStart = 1;
839
- for (; toStart < to.length; ++toStart) {
840
- if (to.charCodeAt(toStart) !== 47 /*/*/)
841
- break;
842
- }
843
- var toEnd = to.length;
844
- var toLen = toEnd - toStart;
845
-
846
- // Compare paths to find the longest common path from root
847
- var length = fromLen < toLen ? fromLen : toLen;
848
- var lastCommonSep = -1;
849
- var i = 0;
850
- for (; i <= length; ++i) {
851
- if (i === length) {
852
- if (toLen > length) {
853
- if (to.charCodeAt(toStart + i) === 47 /*/*/) {
854
- // We get here if `from` is the exact base path for `to`.
855
- // For example: from='/foo/bar'; to='/foo/bar/baz'
856
- return to.slice(toStart + i + 1);
857
- } else if (i === 0) {
858
- // We get here if `from` is the root
859
- // For example: from='/'; to='/foo'
860
- return to.slice(toStart + i);
861
- }
862
- } else if (fromLen > length) {
863
- if (from.charCodeAt(fromStart + i) === 47 /*/*/) {
864
- // We get here if `to` is the exact base path for `from`.
865
- // For example: from='/foo/bar/baz'; to='/foo/bar'
866
- lastCommonSep = i;
867
- } else if (i === 0) {
868
- // We get here if `to` is the root.
869
- // For example: from='/foo'; to='/'
870
- lastCommonSep = 0;
871
- }
872
- }
873
- break;
874
- }
875
- var fromCode = from.charCodeAt(fromStart + i);
876
- var toCode = to.charCodeAt(toStart + i);
877
- if (fromCode !== toCode)
878
- break;
879
- else if (fromCode === 47 /*/*/)
880
- lastCommonSep = i;
881
- }
882
-
883
- var out = '';
884
- // Generate the relative path based on the path difference between `to`
885
- // and `from`
886
- for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
887
- if (i === fromEnd || from.charCodeAt(i) === 47 /*/*/) {
888
- if (out.length === 0)
889
- out += '..';
890
- else
891
- out += '/..';
892
- }
893
- }
894
-
895
- // Lastly, append the rest of the destination (`to`) path that comes after
896
- // the common path parts
897
- if (out.length > 0)
898
- return out + to.slice(toStart + lastCommonSep);
899
- else {
900
- toStart += lastCommonSep;
901
- if (to.charCodeAt(toStart) === 47 /*/*/)
902
- ++toStart;
903
- return to.slice(toStart);
904
- }
905
- },
906
-
907
- _makeLong: function _makeLong(path) {
908
- return path;
909
- },
910
-
911
- dirname: function dirname(path) {
912
- assertPath(path);
913
- if (path.length === 0) return '.';
914
- var code = path.charCodeAt(0);
915
- var hasRoot = code === 47 /*/*/;
916
- var end = -1;
917
- var matchedSlash = true;
918
- for (var i = path.length - 1; i >= 1; --i) {
919
- code = path.charCodeAt(i);
920
- if (code === 47 /*/*/) {
921
- if (!matchedSlash) {
922
- end = i;
923
- break;
924
- }
925
- } else {
926
- // We saw the first non-path separator
927
- matchedSlash = false;
928
- }
929
- }
930
-
931
- if (end === -1) return hasRoot ? '/' : '.';
932
- if (hasRoot && end === 1) return '//';
933
- return path.slice(0, end);
934
- },
935
-
936
- basename: function basename(path, ext) {
937
- if (ext !== undefined && typeof ext !== 'string') throw new TypeError('"ext" argument must be a string');
938
- assertPath(path);
939
-
940
- var start = 0;
941
- var end = -1;
942
- var matchedSlash = true;
943
- var i;
944
-
945
- if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
946
- if (ext.length === path.length && ext === path) return '';
947
- var extIdx = ext.length - 1;
948
- var firstNonSlashEnd = -1;
949
- for (i = path.length - 1; i >= 0; --i) {
950
- var code = path.charCodeAt(i);
951
- if (code === 47 /*/*/) {
952
- // If we reached a path separator that was not part of a set of path
953
- // separators at the end of the string, stop now
954
- if (!matchedSlash) {
955
- start = i + 1;
956
- break;
957
- }
958
- } else {
959
- if (firstNonSlashEnd === -1) {
960
- // We saw the first non-path separator, remember this index in case
961
- // we need it if the extension ends up not matching
962
- matchedSlash = false;
963
- firstNonSlashEnd = i + 1;
964
- }
965
- if (extIdx >= 0) {
966
- // Try to match the explicit extension
967
- if (code === ext.charCodeAt(extIdx)) {
968
- if (--extIdx === -1) {
969
- // We matched the extension, so mark this as the end of our path
970
- // component
971
- end = i;
972
- }
973
- } else {
974
- // Extension does not match, so our result is the entire path
975
- // component
976
- extIdx = -1;
977
- end = firstNonSlashEnd;
978
- }
979
- }
980
- }
981
- }
982
-
983
- if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length;
984
- return path.slice(start, end);
985
- } else {
986
- for (i = path.length - 1; i >= 0; --i) {
987
- if (path.charCodeAt(i) === 47 /*/*/) {
988
- // If we reached a path separator that was not part of a set of path
989
- // separators at the end of the string, stop now
990
- if (!matchedSlash) {
991
- start = i + 1;
992
- break;
993
- }
994
- } else if (end === -1) {
995
- // We saw the first non-path separator, mark this as the end of our
996
- // path component
997
- matchedSlash = false;
998
- end = i + 1;
999
- }
1000
- }
1001
-
1002
- if (end === -1) return '';
1003
- return path.slice(start, end);
1004
- }
1005
- },
1006
-
1007
- extname: function extname(path) {
1008
- assertPath(path);
1009
- var startDot = -1;
1010
- var startPart = 0;
1011
- var end = -1;
1012
- var matchedSlash = true;
1013
- // Track the state of characters (if any) we see before our first dot and
1014
- // after any path separator we find
1015
- var preDotState = 0;
1016
- for (var i = path.length - 1; i >= 0; --i) {
1017
- var code = path.charCodeAt(i);
1018
- if (code === 47 /*/*/) {
1019
- // If we reached a path separator that was not part of a set of path
1020
- // separators at the end of the string, stop now
1021
- if (!matchedSlash) {
1022
- startPart = i + 1;
1023
- break;
1024
- }
1025
- continue;
1026
- }
1027
- if (end === -1) {
1028
- // We saw the first non-path separator, mark this as the end of our
1029
- // extension
1030
- matchedSlash = false;
1031
- end = i + 1;
1032
- }
1033
- if (code === 46 /*.*/) {
1034
- // If this is our first dot, mark it as the start of our extension
1035
- if (startDot === -1)
1036
- startDot = i;
1037
- else if (preDotState !== 1)
1038
- preDotState = 1;
1039
- } else if (startDot !== -1) {
1040
- // We saw a non-dot and non-path separator before our dot, so we should
1041
- // have a good chance at having a non-empty extension
1042
- preDotState = -1;
1043
- }
1044
- }
1045
-
1046
- if (startDot === -1 || end === -1 ||
1047
- // We saw a non-dot character immediately before the dot
1048
- preDotState === 0 ||
1049
- // The (right-most) trimmed path component is exactly '..'
1050
- preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
1051
- return '';
1052
- }
1053
- return path.slice(startDot, end);
1054
- },
1055
-
1056
- format: function format(pathObject) {
1057
- if (pathObject === null || typeof pathObject !== 'object') {
1058
- throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
1059
- }
1060
- return _format('/', pathObject);
1061
- },
1062
-
1063
- parse: function parse(path) {
1064
- assertPath(path);
1065
-
1066
- var ret = { root: '', dir: '', base: '', ext: '', name: '' };
1067
- if (path.length === 0) return ret;
1068
- var code = path.charCodeAt(0);
1069
- var isAbsolute = code === 47 /*/*/;
1070
- var start;
1071
- if (isAbsolute) {
1072
- ret.root = '/';
1073
- start = 1;
1074
- } else {
1075
- start = 0;
1076
- }
1077
- var startDot = -1;
1078
- var startPart = 0;
1079
- var end = -1;
1080
- var matchedSlash = true;
1081
- var i = path.length - 1;
1082
-
1083
- // Track the state of characters (if any) we see before our first dot and
1084
- // after any path separator we find
1085
- var preDotState = 0;
1086
-
1087
- // Get non-dir info
1088
- for (; i >= start; --i) {
1089
- code = path.charCodeAt(i);
1090
- if (code === 47 /*/*/) {
1091
- // If we reached a path separator that was not part of a set of path
1092
- // separators at the end of the string, stop now
1093
- if (!matchedSlash) {
1094
- startPart = i + 1;
1095
- break;
1096
- }
1097
- continue;
1098
- }
1099
- if (end === -1) {
1100
- // We saw the first non-path separator, mark this as the end of our
1101
- // extension
1102
- matchedSlash = false;
1103
- end = i + 1;
1104
- }
1105
- if (code === 46 /*.*/) {
1106
- // If this is our first dot, mark it as the start of our extension
1107
- if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;
1108
- } else if (startDot !== -1) {
1109
- // We saw a non-dot and non-path separator before our dot, so we should
1110
- // have a good chance at having a non-empty extension
1111
- preDotState = -1;
1112
- }
1113
- }
1114
-
1115
- if (startDot === -1 || end === -1 ||
1116
- // We saw a non-dot character immediately before the dot
1117
- preDotState === 0 ||
1118
- // The (right-most) trimmed path component is exactly '..'
1119
- preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
1120
- if (end !== -1) {
1121
- if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end);
1122
- }
1123
- } else {
1124
- if (startPart === 0 && isAbsolute) {
1125
- ret.name = path.slice(1, startDot);
1126
- ret.base = path.slice(1, end);
1127
- } else {
1128
- ret.name = path.slice(startPart, startDot);
1129
- ret.base = path.slice(startPart, end);
1130
- }
1131
- ret.ext = path.slice(startDot, end);
1132
- }
1133
-
1134
- if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = '/';
1135
-
1136
- return ret;
1137
- },
1138
-
1139
- sep: '/',
1140
- delimiter: ':',
1141
- win32: null,
1142
- posix: null
1143
- };
1144
-
1145
- posix.posix = posix;
1146
-
1147
- var pathBrowserify = posix;
1148
-
1149
673
  function ensure_list(obj) {
1150
674
  const objArray = Array.isArray(obj) ? obj : [obj];
1151
675
  return objArray;
@@ -1279,6 +803,313 @@ function getAlphas() {
1279
803
  return 'abcdefghijklmnopqrstuvwxyz';
1280
804
  }
1281
805
 
806
+ /** ---- Data: large but explicit, mirrors your Python mapping ---- */
807
+ const MIME_TYPES = {
808
+ image: {
809
+ ".jpg": "image/jpeg",
810
+ ".jpeg": "image/jpeg",
811
+ ".png": "image/png",
812
+ ".gif": "image/gif",
813
+ ".bmp": "image/bmp",
814
+ ".tiff": "image/tiff",
815
+ ".webp": "image/webp",
816
+ ".svg": "image/svg+xml",
817
+ ".ico": "image/vnd.microsoft.icon",
818
+ ".heic": "image/heic",
819
+ ".psd": "image/vnd.adobe.photoshop",
820
+ ".raw": "image/x-raw",
821
+ },
822
+ video: {
823
+ ".mp4": "video/mp4",
824
+ ".webm": "video/webm",
825
+ ".ogg": "video/ogg",
826
+ ".mov": "video/quicktime",
827
+ ".avi": "video/x-msvideo",
828
+ ".mkv": "video/x-matroska",
829
+ ".flv": "video/x-flv",
830
+ ".wmv": "video/x-ms-wmv",
831
+ ".3gp": "video/3gpp",
832
+ ".ts": "video/mp2t",
833
+ ".mpeg": "video/mpeg",
834
+ ".mpg": "video/mpg",
835
+ },
836
+ audio: {
837
+ ".mp3": "audio/mpeg",
838
+ ".wav": "audio/wav",
839
+ ".flac": "audio/flac",
840
+ ".aac": "audio/aac",
841
+ ".ogg": "audio/ogg",
842
+ ".m4a": "audio/mp4",
843
+ ".opus": "audio/opus",
844
+ },
845
+ document: {
846
+ ".pdf": "application/pdf",
847
+ ".doc": "application/msword",
848
+ ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
849
+ ".odt": "application/vnd.oasis.opendocument.text",
850
+ ".txt": "text/plain",
851
+ ".rtf": "application/rtf",
852
+ ".md": "text/markdown",
853
+ ".markdown": "text/markdown",
854
+ ".tex": "application/x-tex",
855
+ ".log": "text/plain",
856
+ ".json": "application/json",
857
+ ".xml": "application/xml",
858
+ ".yaml": "application/x-yaml",
859
+ ".yml": "application/x-yaml",
860
+ ".ini": "text/plain",
861
+ ".cfg": "text/plain",
862
+ ".toml": "application/toml",
863
+ ".csv": "text/csv",
864
+ ".tsv": "text/tab-separated-values",
865
+ },
866
+ presentation: {
867
+ ".ppt": "application/vnd.ms-powerpoint",
868
+ ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
869
+ ".odp": "application/vnd.oasis.opendocument.presentation",
870
+ },
871
+ spreadsheet: {
872
+ ".xls": "application/vnd.ms-excel",
873
+ ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
874
+ ".ods": "application/vnd.oasis.opendocument.spreadsheet",
875
+ ".csv": "text/csv",
876
+ ".tsv": "text/tab-separated-values",
877
+ },
878
+ code: {
879
+ ".py": "text/x-python",
880
+ ".java": "text/x-java-source",
881
+ ".c": "text/x-c",
882
+ ".cpp": "text/x-c++",
883
+ ".h": "text/x-c",
884
+ ".hpp": "text/x-c++",
885
+ ".js": "application/javascript",
886
+ ".cjs": "application/javascript",
887
+ ".mjs": "application/javascript",
888
+ ".jsx": "application/javascript",
889
+ ".ts": "application/typescript",
890
+ ".tsx": "application/typescript",
891
+ ".rb": "text/x-ruby",
892
+ ".php": "application/x-php",
893
+ ".go": "text/x-go",
894
+ ".rs": "text/rust",
895
+ ".swift": "text/x-swift",
896
+ ".kt": "text/x-kotlin",
897
+ ".sh": "application/x-shellscript",
898
+ ".bash": "application/x-shellscript",
899
+ ".ps1": "application/x-powershell",
900
+ ".sql": "application/sql",
901
+ ".yml": "application/x-yaml",
902
+ ".coffee": "text/coffeescript",
903
+ ".lua": "text/x-lua",
904
+ },
905
+ archive: {
906
+ ".zip": "application/zip",
907
+ ".tar": "application/x-tar",
908
+ ".gz": "application/gzip",
909
+ ".tgz": "application/gzip",
910
+ ".bz2": "application/x-bzip2",
911
+ ".xz": "application/x-xz",
912
+ ".rar": "application/vnd.rar",
913
+ ".7z": "application/x-7z-compressed",
914
+ ".iso": "application/x-iso9660-image",
915
+ ".dmg": "application/x-apple-diskimage",
916
+ ".jar": "application/java-archive",
917
+ ".war": "application/java-archive",
918
+ ".whl": "application/python-wheel",
919
+ ".egg": "application/python-egg",
920
+ },
921
+ font: {
922
+ ".ttf": "font/ttf",
923
+ ".otf": "font/otf",
924
+ ".woff": "font/woff",
925
+ ".woff2": "font/woff2",
926
+ ".eot": "application/vnd.ms-fontobject",
927
+ },
928
+ executable: {
929
+ ".exe": "application/vnd.microsoft.portable-executable",
930
+ ".dll": "application/vnd.microsoft.portable-executable",
931
+ ".bin": "application/octet-stream",
932
+ ".deb": "application/vnd.debian.binary-package",
933
+ ".rpm": "application/x-rpm",
934
+ },
935
+ };
936
+ /** Mirror of MEDIA_TYPES in Python: category -> Set of extensions */
937
+ const MEDIA_TYPES = Object.fromEntries(Object.entries(MIME_TYPES).map(([cat, mapping]) => [
938
+ cat,
939
+ new Set(Object.keys(mapping)),
940
+ ]));
941
+ /** ---- Helpers ---- */
942
+ function toCategorySet(categories) {
943
+ const allCats = new Set(Object.keys(MIME_TYPES));
944
+ if (!categories) {
945
+ // all categories
946
+ return new Set(allCats);
947
+ }
948
+ const out = new Set();
949
+ for (const c of categories) {
950
+ const key = String(c);
951
+ if (allCats.has(key))
952
+ out.add(key);
953
+ }
954
+ return out.size ? out : new Set(allCats);
955
+ }
956
+ function normalizeCategories(categories, opts) {
957
+ var _a;
958
+ 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;
959
+ return toCategorySet(selected);
960
+ }
961
+ function extOf(input) {
962
+ // Behaves like pathlib.Path(...).suffix.lower(): last extension only; lowercased.
963
+ let ext = path__namespace.extname(input || "");
964
+ if (!ext && input && input.startsWith(".")) {
965
+ // user passed ".jpg" directly
966
+ ext = input;
967
+ }
968
+ return (ext || "").toLowerCase();
969
+ }
970
+ function unionExts(categories) {
971
+ const out = new Set();
972
+ for (const c of categories) {
973
+ const set = MEDIA_TYPES[c];
974
+ for (const e of set)
975
+ out.add(e);
976
+ }
977
+ return out;
978
+ }
979
+ /** ---- API (Python parity) ---- */
980
+ /**
981
+ * Return a sub-map of MEDIA_TYPES for the given categories.
982
+ * If categories is falsy, returns all categories.
983
+ */
984
+ function getMediaMap(categories, opts) {
985
+ const cats = normalizeCategories(categories, opts);
986
+ const result = {};
987
+ for (const c of cats)
988
+ result[c] = new Set(MEDIA_TYPES[c]);
989
+ return result;
990
+ }
991
+ /**
992
+ * Return a flat, sorted list of all extensions for the given categories.
993
+ */
994
+ function getMediaExts(categories, opts) {
995
+ const cats = normalizeCategories(categories, opts);
996
+ return Array.from(unionExts(cats)).sort();
997
+ }
998
+ /**
999
+ * Given a file path or extension, return its media category (e.g. "image") or null.
1000
+ * Mirrors Python's confirm_type.
1001
+ */
1002
+ function confirmType(pathOrExt, categories, opts) {
1003
+ const cats = normalizeCategories(categories, opts);
1004
+ const ext = extOf(pathOrExt);
1005
+ // Preserve object insertion order like Python dict iteration
1006
+ for (const [category, exts] of Object.entries(MEDIA_TYPES)) {
1007
+ if (!cats.has(category))
1008
+ continue;
1009
+ if (ext && exts.has(ext))
1010
+ return category;
1011
+ }
1012
+ return null;
1013
+ }
1014
+ /**
1015
+ * True if the given file path or extension belongs to one of the categories.
1016
+ */
1017
+ function isMediaType(pathOrExt, categories, opts) {
1018
+ return confirmType(pathOrExt, categories, opts) !== null;
1019
+ }
1020
+ /**
1021
+ * Look up the MIME type by extension; fall back to 'application/octet-stream'.
1022
+ */
1023
+ function getMimeType(pathOrExt) {
1024
+ const ext = extOf(pathOrExt);
1025
+ for (const mapping of Object.values(MIME_TYPES)) {
1026
+ if (ext && mapping[ext]) {
1027
+ return mapping[ext];
1028
+ }
1029
+ }
1030
+ return "application/octet-stream";
1031
+ }
1032
+ /**
1033
+ * Recursively collect files under `directory` whose extension is in `categories`.
1034
+ * Synchronous version.
1035
+ */
1036
+ function getAllFileTypesSync(directory, categories, opts) {
1037
+ const base = directory;
1038
+ let stat;
1039
+ try {
1040
+ stat = fs__namespace.statSync(base);
1041
+ }
1042
+ catch (_a) {
1043
+ return [];
1044
+ }
1045
+ if (!stat.isDirectory())
1046
+ return [];
1047
+ const cats = normalizeCategories(categories, opts);
1048
+ const wanted = unionExts(cats);
1049
+ const results = [];
1050
+ function walkSync(dir) {
1051
+ const entries = fs__namespace.readdirSync(dir, { withFileTypes: true });
1052
+ for (const ent of entries) {
1053
+ const full = path__namespace.join(dir, ent.name);
1054
+ if (ent.isDirectory()) {
1055
+ walkSync(full);
1056
+ }
1057
+ else if (ent.isFile()) {
1058
+ const ext = path__namespace.extname(ent.name).toLowerCase();
1059
+ if (wanted.has(ext))
1060
+ results.push(full);
1061
+ }
1062
+ }
1063
+ }
1064
+ walkSync(base);
1065
+ return results;
1066
+ }
1067
+ /**
1068
+ * Recursively collect files under `directory` whose extension is in `categories`.
1069
+ * Async/Promise version.
1070
+ */
1071
+ function getAllFileTypes(directory, categories, opts) {
1072
+ return __awaiter(this, void 0, void 0, function* () {
1073
+ let stat;
1074
+ try {
1075
+ stat = yield fsp__namespace.stat(directory);
1076
+ }
1077
+ catch (_a) {
1078
+ return [];
1079
+ }
1080
+ if (!stat.isDirectory())
1081
+ return [];
1082
+ const cats = normalizeCategories(categories, opts);
1083
+ const wanted = unionExts(cats);
1084
+ const results = [];
1085
+ function walkAsync(dir) {
1086
+ return __awaiter(this, void 0, void 0, function* () {
1087
+ const entries = yield fsp__namespace.readdir(dir, { withFileTypes: true });
1088
+ for (const ent of entries) {
1089
+ const full = path__namespace.join(dir, ent.name);
1090
+ if (ent.isDirectory()) {
1091
+ yield walkAsync(full);
1092
+ }
1093
+ else if (ent.isFile()) {
1094
+ const ext = path__namespace.extname(ent.name).toLowerCase();
1095
+ if (wanted.has(ext))
1096
+ results.push(full);
1097
+ }
1098
+ }
1099
+ });
1100
+ }
1101
+ yield walkAsync(directory);
1102
+ return results;
1103
+ });
1104
+ }
1105
+ /** Optional convenience re-exports that mirror your Python names */
1106
+ const get_all_file_types = getAllFileTypes;
1107
+ const get_media_map = getMediaMap;
1108
+ const get_media_exts = getMediaExts;
1109
+ const confirm_type = confirmType;
1110
+ const is_media_type = isMediaType;
1111
+ const get_mime_type = getMimeType;
1112
+
1282
1113
  function getSubstring(obj, maxLength = null, minLength = null) {
1283
1114
  const objLength = obj.length;
1284
1115
  const effectiveMaxLength = maxLength !== null && maxLength !== void 0 ? maxLength : objLength; // Use nullish coalescing for clarity
@@ -1461,28 +1292,28 @@ function getAbsolutePath() {
1461
1292
  function get_dirname(filePath) {
1462
1293
  if (!filePath)
1463
1294
  return '';
1464
- return pathBrowserify.dirname(filePath);
1295
+ return path__namespace$1.dirname(filePath);
1465
1296
  }
1466
1297
  function get_basename(filePath) {
1467
1298
  if (!filePath)
1468
1299
  return '';
1469
- return pathBrowserify.basename(filePath);
1300
+ return path__namespace$1.basename(filePath);
1470
1301
  }
1471
1302
  function get_filename(file_path) {
1472
- const ext = pathBrowserify.extname(file_path);
1473
- return pathBrowserify.basename(file_path, ext);
1303
+ const ext = path__namespace$1.extname(file_path);
1304
+ return path__namespace$1.basename(file_path, ext);
1474
1305
  }
1475
1306
  function get_extname(filePath) {
1476
1307
  if (!filePath)
1477
1308
  return '';
1478
- return pathBrowserify.extname(filePath);
1309
+ return path__namespace$1.extname(filePath);
1479
1310
  }
1480
1311
  function get_splitext(filePath) {
1481
1312
  if (!filePath)
1482
1313
  return { filename: '', extname: '' };
1483
- const ext = pathBrowserify.extname(filePath);
1314
+ const ext = path__namespace$1.extname(filePath);
1484
1315
  // Get the basename without the extension
1485
- const filename = pathBrowserify.basename(filePath, ext);
1316
+ const filename = path__namespace$1.basename(filePath, ext);
1486
1317
  return { filename, ext };
1487
1318
  }
1488
1319
  /**
@@ -1540,11 +1371,11 @@ function sanitizeFilename(filename) {
1540
1371
  .replace(/^-|-$/, ''); // Remove leading/trailing hyphens
1541
1372
  }
1542
1373
  function get_relative_path(directory, fullPath) {
1543
- return pathBrowserify.relative(directory, fullPath);
1374
+ return path__namespace$1.relative(directory, fullPath);
1544
1375
  }
1545
1376
  // Safer resolver that strips .. at the front only, but prefer server-side checks.
1546
1377
  function get_safe_path(p) {
1547
- return pathBrowserify.normalize(p).replace(/^(\.\.[/\\])+/, '');
1378
+ return path__namespace$1.normalize(p).replace(/^(\.\.[/\\])+/, '');
1548
1379
  }
1549
1380
  function make_sanitized_path(...paths) {
1550
1381
  let real_path = '';
@@ -1871,6 +1702,8 @@ exports.Checkbox = Checkbox;
1871
1702
  exports.DEV_PREFIX = DEV_PREFIX;
1872
1703
  exports.DOMAIN_NAME = DOMAIN_NAME;
1873
1704
  exports.Input = Input;
1705
+ exports.MEDIA_TYPES = MEDIA_TYPES;
1706
+ exports.MIME_TYPES = MIME_TYPES;
1874
1707
  exports.PROD_PREFIX = PROD_PREFIX;
1875
1708
  exports.PROTOCOL = PROTOCOL;
1876
1709
  exports.SUB_DIR = SUB_DIR;
@@ -1893,6 +1726,8 @@ exports.capitalize_str = capitalize_str;
1893
1726
  exports.checkResponse = checkResponse;
1894
1727
  exports.cleanArray = cleanArray;
1895
1728
  exports.cleanText = cleanText;
1729
+ exports.confirmType = confirmType;
1730
+ exports.confirm_type = confirm_type;
1896
1731
  exports.create_list_string = create_list_string;
1897
1732
  exports.currentUsername = currentUsername;
1898
1733
  exports.currentUsernames = currentUsernames;
@@ -1932,6 +1767,8 @@ exports.geTypeUtilsDirectory = geTypeUtilsDirectory;
1932
1767
  exports.get = get;
1933
1768
  exports.getAbsDir = getAbsDir;
1934
1769
  exports.getAbsPath = getAbsPath;
1770
+ exports.getAllFileTypes = getAllFileTypes;
1771
+ exports.getAllFileTypesSync = getAllFileTypesSync;
1935
1772
  exports.getAlphaNum = getAlphaNum;
1936
1773
  exports.getAlphas = getAlphas;
1937
1774
  exports.getAuthorizationHeader = getAuthorizationHeader;
@@ -1955,7 +1792,10 @@ exports.getHeaders = getHeaders;
1955
1792
  exports.getHooksUtilsDirectory = getHooksUtilsDirectory;
1956
1793
  exports.getHtmlDirectory = getHtmlDirectory;
1957
1794
  exports.getLibUtilsDirectory = getLibUtilsDirectory;
1795
+ exports.getMediaExts = getMediaExts;
1796
+ exports.getMediaMap = getMediaMap;
1958
1797
  exports.getMethod = getMethod;
1798
+ exports.getMimeType = getMimeType;
1959
1799
  exports.getNums = getNums;
1960
1800
  exports.getPublicDir = getPublicDir;
1961
1801
  exports.getResult = getResult;
@@ -1969,6 +1809,7 @@ exports.getSubstring = getSubstring;
1969
1809
  exports.getToken = getToken;
1970
1810
  exports.getWindowHost = getWindowHost;
1971
1811
  exports.getWindowProp = getWindowProp;
1812
+ exports.get_all_file_types = get_all_file_types;
1972
1813
  exports.get_basename = get_basename;
1973
1814
  exports.get_dirname = get_dirname;
1974
1815
  exports.get_extname = get_extname;
@@ -1977,6 +1818,9 @@ exports.get_full_path = get_full_path;
1977
1818
  exports.get_full_url = get_full_url;
1978
1819
  exports.get_key_value = get_key_value;
1979
1820
  exports.get_keyword_string = get_keyword_string;
1821
+ exports.get_media_exts = get_media_exts;
1822
+ exports.get_media_map = get_media_map;
1823
+ exports.get_mime_type = get_mime_type;
1980
1824
  exports.get_relative_path = get_relative_path;
1981
1825
  exports.get_result = get_result;
1982
1826
  exports.get_safe_path = get_safe_path;
@@ -1986,10 +1830,12 @@ exports.get_window_location = get_window_location;
1986
1830
  exports.get_window_parts = get_window_parts;
1987
1831
  exports.get_window_pathname = get_window_pathname;
1988
1832
  exports.isLoggedIn = isLoggedIn;
1833
+ exports.isMediaType = isMediaType;
1989
1834
  exports.isNum = isNum;
1990
1835
  exports.isStrInString = isStrInString;
1991
1836
  exports.isTokenExpired = isTokenExpired;
1992
1837
  exports.isType = isType;
1838
+ exports.is_media_type = is_media_type;
1993
1839
  exports.makePath = makePath;
1994
1840
  exports.make_path = make_path;
1995
1841
  exports.make_sanitized_path = make_sanitized_path;