applesauce-core 2.1.0 → 2.1.1

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.
@@ -16,8 +16,10 @@ export declare function isAudioURL(url: string | URL): boolean;
16
16
  export declare function isSameURL(a: string | URL, b: string | URL): boolean;
17
17
  /** Adds a protocol to a URL string if its missing one */
18
18
  export declare function ensureProtocol(url: string, protocol?: string): string;
19
- /** Converts a URL to a WebSocket URL */
19
+ /** Converts a domain or HTTP URL to a WebSocket URL */
20
20
  export declare function ensureWebSocketURL<T extends string | URL>(url: T): T;
21
+ /** Converts a domain or WS URL to a HTTP URL */
22
+ export declare function ensureHttpURL<T extends string | URL>(url: T): T;
21
23
  /**
22
24
  * Normalizes a string into a relay URL
23
25
  * Does not remove the trailing slash
@@ -3,7 +3,7 @@ export const getURLFilename = (url) => url.pathname.split("/").pop()?.toLocaleLo
3
3
  export const IMAGE_EXT = [".svg", ".gif", ".png", ".jpg", ".jpeg", ".webp", ".avif"];
4
4
  export const VIDEO_EXT = [".mp4", ".mkv", ".webm", ".mov"];
5
5
  export const STREAM_EXT = [".m3u8"];
6
- export const AUDIO_EXT = [".mp3", ".wav", ".ogg", ".aac"];
6
+ export const AUDIO_EXT = [".mp3", ".wav", ".ogg", ".aac", ".m4a"];
7
7
  /** Checks if a url is a image URL */
8
8
  export function isImageURL(url) {
9
9
  url = convertToUrl(url);
@@ -46,7 +46,7 @@ export function ensureProtocol(url, protocol = "https:") {
46
46
  return url;
47
47
  return protocol + "//" + url;
48
48
  }
49
- /** Converts a URL to a WebSocket URL */
49
+ /** Converts a domain or HTTP URL to a WebSocket URL */
50
50
  export function ensureWebSocketURL(url) {
51
51
  const p = typeof url === "string" ? new URL(ensureProtocol(url, "wss:")) : new URL(url);
52
52
  if (p.protocol === "http:")
@@ -59,6 +59,19 @@ export function ensureWebSocketURL(url) {
59
59
  // @ts-expect-error
60
60
  return typeof url === "string" ? p.toString() : p;
61
61
  }
62
+ /** Converts a domain or WS URL to a HTTP URL */
63
+ export function ensureHttpURL(url) {
64
+ const p = typeof url === "string" ? new URL(ensureProtocol(url, "http:")) : new URL(url);
65
+ if (p.protocol === "ws:")
66
+ p.protocol = "http:";
67
+ else if (p.protocol === "wss:")
68
+ p.protocol = "https:";
69
+ else
70
+ p.protocol = "https:";
71
+ // return a string if a string was passed in
72
+ // @ts-expect-error
73
+ return typeof url === "string" ? p.toString() : p;
74
+ }
62
75
  /**
63
76
  * Normalizes a string into a relay URL
64
77
  * Does not remove the trailing slash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-core",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",