@hot-updater/plugin-core 0.36.8 → 0.36.11

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.
@@ -24,21 +24,28 @@ const COMPRESSION_FORMATS = {
24
24
  }
25
25
  };
26
26
  /**
27
+ * Finds the compression format matching a filename extension
28
+ * @param filename The filename to match
29
+ * @returns Compression format information, or undefined when nothing matches
30
+ */
31
+ function findCompressionFormat(filename) {
32
+ return Object.values(COMPRESSION_FORMATS).find((info) => filename.endsWith(info.fileExtension));
33
+ }
34
+ /**
27
35
  * Detects compression format from filename
28
36
  * @param filename The filename to detect format from
29
37
  * @returns Compression format information
30
38
  */
31
39
  function detectCompressionFormat(filename) {
32
- for (const info of Object.values(COMPRESSION_FORMATS)) if (filename.endsWith(info.fileExtension)) return info;
33
- return COMPRESSION_FORMATS.zip;
40
+ return findCompressionFormat(filename) ?? COMPRESSION_FORMATS.zip;
34
41
  }
35
42
  /**
36
43
  * Gets MIME type for a filename
37
44
  * @param filename The filename to get MIME type for
38
- * @returns MIME type string
45
+ * @returns MIME type string, or undefined when the filename is not an archive
39
46
  */
40
47
  function getCompressionMimeType(filename) {
41
- return detectCompressionFormat(filename).mimeType;
48
+ return findCompressionFormat(filename)?.mimeType;
42
49
  }
43
50
  /**
44
51
  * Gets Content-Type for a bundle file with 3-tier fallback
@@ -20,7 +20,7 @@ declare function detectCompressionFormat(filename: string): CompressionFormatInf
20
20
  /**
21
21
  * Gets MIME type for a filename
22
22
  * @param filename The filename to get MIME type for
23
- * @returns MIME type string
23
+ * @returns MIME type string, or undefined when the filename is not an archive
24
24
  */
25
25
  declare function getCompressionMimeType(filename: string): string | undefined;
26
26
  /**
@@ -20,7 +20,7 @@ declare function detectCompressionFormat(filename: string): CompressionFormatInf
20
20
  /**
21
21
  * Gets MIME type for a filename
22
22
  * @param filename The filename to get MIME type for
23
- * @returns MIME type string
23
+ * @returns MIME type string, or undefined when the filename is not an archive
24
24
  */
25
25
  declare function getCompressionMimeType(filename: string): string | undefined;
26
26
  /**
@@ -22,21 +22,28 @@ const COMPRESSION_FORMATS = {
22
22
  }
23
23
  };
24
24
  /**
25
+ * Finds the compression format matching a filename extension
26
+ * @param filename The filename to match
27
+ * @returns Compression format information, or undefined when nothing matches
28
+ */
29
+ function findCompressionFormat(filename) {
30
+ return Object.values(COMPRESSION_FORMATS).find((info) => filename.endsWith(info.fileExtension));
31
+ }
32
+ /**
25
33
  * Detects compression format from filename
26
34
  * @param filename The filename to detect format from
27
35
  * @returns Compression format information
28
36
  */
29
37
  function detectCompressionFormat(filename) {
30
- for (const info of Object.values(COMPRESSION_FORMATS)) if (filename.endsWith(info.fileExtension)) return info;
31
- return COMPRESSION_FORMATS.zip;
38
+ return findCompressionFormat(filename) ?? COMPRESSION_FORMATS.zip;
32
39
  }
33
40
  /**
34
41
  * Gets MIME type for a filename
35
42
  * @param filename The filename to get MIME type for
36
- * @returns MIME type string
43
+ * @returns MIME type string, or undefined when the filename is not an archive
37
44
  */
38
45
  function getCompressionMimeType(filename) {
39
- return detectCompressionFormat(filename).mimeType;
46
+ return findCompressionFormat(filename)?.mimeType;
40
47
  }
41
48
  /**
42
49
  * Gets Content-Type for a bundle file with 3-tier fallback
@@ -1,6 +1,6 @@
1
1
  //#region src/createStorageKeyBuilder.ts
2
2
  const createStorageKeyBuilder = (basePath) => (...args) => {
3
- return [basePath || "", ...args].filter(Boolean).join("/");
3
+ return [basePath?.replace(/^\/+|\/+$/g, "") ?? "", ...args].filter(Boolean).join("/");
4
4
  };
5
5
  //#endregion
6
6
  exports.createStorageKeyBuilder = createStorageKeyBuilder;
@@ -1,6 +1,6 @@
1
1
  //#region src/createStorageKeyBuilder.ts
2
2
  const createStorageKeyBuilder = (basePath) => (...args) => {
3
- return [basePath || "", ...args].filter(Boolean).join("/");
3
+ return [basePath?.replace(/^\/+|\/+$/g, "") ?? "", ...args].filter(Boolean).join("/");
4
4
  };
5
5
  //#endregion
6
6
  export { createStorageKeyBuilder };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/plugin-core",
3
- "version": "0.36.8",
3
+ "version": "0.36.11",
4
4
  "type": "module",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "sideEffects": false,
@@ -45,14 +45,14 @@
45
45
  "es-toolkit": "^1.32.0",
46
46
  "mime": "^4.0.4",
47
47
  "verkit": "0.3.2",
48
- "@hot-updater/core": "0.36.8",
49
- "@hot-updater/js": "0.36.8"
48
+ "@hot-updater/core": "0.36.11",
49
+ "@hot-updater/js": "0.36.11"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/node": "^20",
53
53
  "@typescript/native": "npm:typescript@7.0.2",
54
54
  "typescript": "npm:@typescript/typescript6@6.0.2",
55
- "@hot-updater/test-utils": "0.36.8"
55
+ "@hot-updater/test-utils": "0.36.11"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "tsdown",