Skip to the content

Capsid menu

app/lib/not-found-query.mjs

21 lines and 3 functions in DrDustinEdwards/dustinedwards-info, at commit 1590ba4 on 2026-10-24. This file on GitHub.

Functions

The functions of not-found-query.mjs
FunctionLinesComplexityCoveredCRAPMutation
notFoundQuery13 to 222100%OkCRAP 2Watch73.7%
<anonymous:14>14 to 141100%OkCRAP 1Ok100%
<anonymous:20>20 to 202100%OkCRAP 2Watch75%

Imports

It imports no other module of this repo. Imported by app/components/not-found-help.tsx.

Source

// Plain .mjs so `node --test` can import it; the types are JSDoc under checkJs.

/**
 * The words of a missing address, to start the 404 page's search box with: the last path segment
 * with any file extension off, split on everything that is not a letter or digit. Number-only words
 * are dropped, because a bare year is a search filter and an old dated address would otherwise
 * narrow the search to that year. Percent escapes are dropped rather than decoded, since a malformed
 * one would throw. Empty when nothing useful is left, and the box then shows its placeholder.
 *
 * @param {string} pathname
 * @returns {string}
 */
export function notFoundQuery(pathname) {
  const segments = pathname.split("/").filter((segment) => segment.length > 0);
  const last = segments.at(-1) ?? "";
  const words = last
    .replace(/%[0-9A-Fa-f]{2}/g, " ")
    .replace(/\.[A-Za-z0-9]{1,5}$/, "")
    .split(/[^\p{L}\p{N}]+/u)
    .filter((word) => word.length > 0 && !/^\p{N}+$/u.test(word));
  return words.join(" ").slice(0, 100).trim();
}