Skip to content
View .md

Helpers ​

Import helper APIs from the azot package.

version ​

js
import { version } from "azot";

A string containing the version of the Azot app that is currently running.

js
version;
// => "5.0.0"

sleep() ​

sleep(ms: number) ​

js
import { sleep } from "azot";

Returns a Promise that resolves after the given number of milliseconds.

js
console.log("hello");
await sleep(1000);
console.log("hello one second later!");

abortable() ​

abortable(operation, signal?) ​

js
import { abortable } from "azot";

Awaits an operation that does not observe signal itself, rejecting promptly with signal.reason when the signal aborts.

js
const tracks = await abortable(input.getAudioTracks(), signal);

HTML ​

HTML text helpers.

HTML.decodeEntities(value: string) ​

js
import { HTML } from "azot";

Decodes named (&, ©) and numeric (', ') character references in a single pass. Unknown named entities, references without a trailing semicolon, and JavaScript escapes such as \u0026 or \/ are left intact. Invalid numeric references (zero, surrogates, out of range) decode to the replacement character, and C1 controls remap through the HTML numeric table (€ is €), matching browser behavior.

js
HTML.decodeEntities(""Fish & Chips"");
// => '"Fish & Chips"'

HTML.findJsonContainer(input: string, startIndex: number) ​

Finds the complete JSON object or array starting at startIndex, so page scraping can slice embedded state. Returns { text, start, end } with an exclusive end (input.slice(start, end) === text), or null when startIndex is not an opener or the container never closes.

js
HTML.findJsonContainer('prefix{"a":[1,2]}; trailing', 6);
// => { text: '{"a":[1,2]}', start: 6, end: 17 }

HTML.getMetaContent(html: string, ...names: string[]) ​

Reads the content attribute of the first meta tag in document order whose property (Open Graph style) or name attribute equals any of the given names. Returns the decoded, trimmed value, or undefined when no tag matches. Page-serialized values may embed the JavaScript escapes pages use to hide URLs in JSON state (\/, \u0026); those are decoded too.

js
HTML.getMetaContent(html, "og:video", "og:video:url");
// => "https://example.com/video.mp4"

HTML.getPageTitle(html: string) ​

Page title from Open Graph metadata, falling back to the decoded document <title>.

js
HTML.getPageTitle(html);
// => "Episode 12: Example Podcast"

HTML.collectMediaUrls(html: string, baseUrl: string) ​

Collects unique absolute media URLs embedded in an HTML page. Only matches URLs with an explicit media extension (.m3u8, .mpd, .mp4, .m4a, .mp3); extensionless manifests and relative paths are not found. Decodes HTML entities and the JSON escapes that hide URLs in embedded page state (\/, \u0026).

js
HTML.collectMediaUrls(html, pageUrl);
// => ["https://cdn.example.com/video.m3u8", "https://cdn.example.com/audio.mp3"]

Runtime validation ​

Import the host's Zod instance from azot to validate data returned by websites and APIs. Extensions do not need a separate zod dependency.

ts
import { z } from "azot";

const videoSchema = z.object({
  id: z.string(),
  source: z.url(),
});

const video = videoSchema.parse(await response.json());

Media Helpers ​

Use Input and UrlSource when a provider's resolve() needs to build a media resource manually.

ts
import { Input, UrlSource } from "azot";

const input = new Input({
  source: new UrlSource("https://example.com/video.m3u8", {
    requestInit: {
      headers: { referer: "https://example.com/watch" },
    },
  }),
});

Input uses all supported formats by default. UrlSource uses the extension-aware HTTP client, so cookies, default browser-like headers, and proxy configuration are applied consistently.

Released under the MIT License.