UNPKG

vanillajs-browser-helpers

Version:

Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS in the browser

21 lines (20 loc) 787 B
/** * Make a unique list of Elements from a list of selectors and and function to use that selector. * * @param selector - The selector(s) to use with the given `findElements` function * @param findElements - The function to find elements * @returns The unique list of found elements * * @example * * ```ts * const byClassName = (selector) => document.getElementsByClassName(selector) * * // Using a single selector * findUniqueNodeCollection('my-elements', byClassName); * * // Using multiple selectors * findUniqueNodeCollection(['my-elements', 'sone-other-elements'], byClassName); * ``` */ export default function findUniqueNodeCollection(selector: string | string[], findElements: (name: string) => HTMLCollectionOf<Element> | NodeListOf<HTMLElement>): Element[];