PageSourceSearch

https://octopus.com/blog/js/modules/query.js

js octopus.com collected 2026-10-01 09:25:46 UTC 744 bytes, 37 lines download raw bytes

1// @ts-check
2
3/**
4 *
5 * @param {string} query
6 * @param {HTMLElement} [container]
7 * @returns {HTMLElement}
8 */
9function qs(query, container) {
10  const target = container ? container : document;
11
12  /** @type {any} */
13  const result = target.querySelector(query);
14
15  if (result) {
16    return result;
17  }
18
19  throw new Error(`No element ${query}`);
20}
21
22/**
23 * Utility for query selector all
24 *
25 * @param {string} query
26 * @param {HTMLElement | null} [container]
27 * @returns {NodeListOf<any>}
28 */
29function qsa(query, container) {
30  const target = container ? container : document;
31
32  /** @type {NodeListOf<HTMLElement>} */
33  const result = target.querySelectorAll(query);
34  return result;
35}
36
37export { qs, qsa };

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.