UNPKG

soundcloud-sync

Version:

Sync your SoundCloud likes to local files

38 lines (37 loc) 1.4 kB
/** * Fetches data from a URL and optionally extracts matches using regular expressions. * * Behaviour: * - Without regexes: Returns complete response data as string * - With regexes: Returns array of capture groups for each regex * - Non-global patterns: Can return early when all patterns match * - Global patterns: Must read entire response * * Response size: * - Reports downloaded bytes * - Reports total size if Content-Length header is present * - For early returns, usually downloaded < total * * @param url - The URL to fetch data from * @param regexes - Optional array of RegExp to match against the response * @returns Promise resolving to either: * - string[][] - Array of capture groups for each regex * - string - Raw response data if no regexes provided * * @example * // Fetch complete response * const data = await webAgent('https://example.com'); * * @example * // Early return when pattern matches * const [[id]] = await webAgent('https://example.com', [/id="([^"]+)"/]); * console.log(id); // '123' * * @example * // Mixed patterns (must read full response) * const matches = await webAgent('https://example.com', [ * /id="([^"]+)"/, // Single match: ['123'] * /href="([^"]+)"/g // All matches: ['/', '/about', '/contact'] * ]); */ export default function webAgent(url: string, regexes?: RegExp[]): Promise<string | string[][]>;