UNPKG

ts-audio

Version:

`ts-audio` is an agnostic and easy-to-use library to work with the `AudioContext` API and create Playlists.

37 lines (36 loc) 1.51 kB
/** * Converts an object of weighted file paths into an array where each file appears * multiple times based on its weight. * * @example * weightedFiles({ 'song1.mp3': 2, 'song2.mp3': 1 }) * // returns ['song1.mp3', 'song1.mp3', 'song2.mp3'] * * @param {Object.<string, number>} files - Object with file paths as keys and weights as values * @returns {string[]} Array of file paths repeated according to their weights */ export declare const weightedFiles: (files: { [key: string]: number; }) => string[]; /** * Shuffles an array of strings using the Fisher-Yates algorithm. * Creates a new array instead of modifying the original. * * @example * shuffle(['a', 'b', 'c']) * // might return ['b', 'c', 'a'] * * @param {string[]} list - Array of strings to shuffle * @returns {string[]} New array with shuffled elements */ export declare const shuffle: (list: string[]) => string[]; /** * Preloads audio files in batches with a specified limit. * Uses a queue system to load files sequentially after the initial batch. * * @param {string[]} files - Array of file URLs to preload * @param {number} limit - Maximum number of files to load simultaneously * @param {Function} [api=fetch] - Function to use for fetching files * @param {Function} [done] - Callback function to execute when all files are loaded */ export declare const preloadFiles: (files: string[], limit: number, api?: (input: string, init?: RequestInit | undefined) => Promise<Response>, done?: () => void) => void;