@lvce-editor/file-search-worker 2.0.0 → 2.2.0

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.
@@ -924,6 +924,68 @@ class FileNotFoundError extends Error {
924
924
  }
925
925
  }
926
926
 
927
+ const ApplicationJson = 'application/json';
928
+ const AudioMpeg = 'audio/mpeg';
929
+ const FontTtf = 'font/ttf';
930
+ const ImagePng = 'image/png';
931
+ const ImageSvgXml = 'image/svg+xml';
932
+ const TextCss = 'text/css';
933
+ const TextHtml = 'text/html';
934
+ const TextJavaScript = 'text/javascript';
935
+ const TextPlain = 'text/plain';
936
+ const VideoWebm = 'video/webm';
937
+
938
+ const getMimeType = fileExtension => {
939
+ switch (fileExtension) {
940
+ case '.html':
941
+ return TextHtml;
942
+ case '.css':
943
+ return TextCss;
944
+ case '.ttf':
945
+ return FontTtf;
946
+ case '.js':
947
+ case '.mjs':
948
+ case '.ts':
949
+ return TextJavaScript;
950
+ case '.svg':
951
+ return ImageSvgXml;
952
+ case '.png':
953
+ return ImagePng;
954
+ case '.json':
955
+ case '.map':
956
+ return ApplicationJson;
957
+ case '.mp3':
958
+ return AudioMpeg;
959
+ case '.webm':
960
+ return VideoWebm;
961
+ case '.txt':
962
+ return TextPlain;
963
+ default:
964
+ return '';
965
+ }
966
+ };
967
+
968
+ const dirname = (pathSeparator, path) => {
969
+ const index = path.lastIndexOf(pathSeparator);
970
+ if (index === -1) {
971
+ return path;
972
+ }
973
+ return path.slice(0, index);
974
+ };
975
+ const extname = path => {
976
+ const index = path.lastIndexOf('.');
977
+ if (index === -1) {
978
+ return '';
979
+ }
980
+ return path.slice(index);
981
+ };
982
+
983
+ const getContentType = uri => {
984
+ const extension = extname(uri);
985
+ const mime = getMimeType(extension);
986
+ return mime;
987
+ };
988
+
927
989
  // TODO move this to an extension?
928
990
 
929
991
  const state$2 = {
@@ -1019,30 +1081,19 @@ const readDirWithFileTypes = uri => {
1019
1081
  }
1020
1082
  return dirents;
1021
1083
  };
1022
- const getContentType = uri => {
1023
- if (uri.endsWith('.png')) {
1024
- return 'image/png';
1025
- }
1026
- if (uri.endsWith('.svg')) {
1027
- return 'image/svg+xml';
1028
- }
1029
- // TODO support more
1030
- return '';
1031
- };
1032
- const getBlobUrl = uri => {
1084
+ const getBlob = uri => {
1033
1085
  const content = readFile(uri);
1034
1086
  const contentType = getContentType(uri);
1035
1087
  const blob = new Blob([content], {
1036
1088
  type: contentType
1037
1089
  });
1090
+ return blob;
1091
+ };
1092
+ const getBlobUrl = uri => {
1093
+ const blob = getBlob(uri);
1038
1094
  const url = URL.createObjectURL(blob);
1039
1095
  return url;
1040
1096
  };
1041
- const getBlob = uri => {
1042
- const content = readFile(uri);
1043
- const blob = new Blob([content]);
1044
- return blob;
1045
- };
1046
1097
  const chmod = () => {
1047
1098
  throw new Error('[memfs] chmod not implemented');
1048
1099
  };
@@ -1125,14 +1176,6 @@ const getChildHandles = async handle => {
1125
1176
  return handles;
1126
1177
  };
1127
1178
 
1128
- const dirname = (pathSeparator, path) => {
1129
- const index = path.lastIndexOf(pathSeparator);
1130
- if (index === -1) {
1131
- return path;
1132
- }
1133
- return path.slice(0, index);
1134
- };
1135
-
1136
1179
  const instanceOfAny = (object, constructors) => constructors.some(c => object instanceof c);
1137
1180
  let idbProxyableTypes;
1138
1181
  let cursorAdvanceMethods;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-search-worker",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "",
5
5
  "main": "dist/fileSearchWorkerMain.js",
6
6
  "type": "module",