mazey
    Preparing search index...

    Function escapeHtmlAttribute

    • Escape a string for use inside a quoted HTML attribute.

      By default, the function escapes ampersands, angle brackets, double quotes, and single quotes. Set preserveEntities to retain syntactically valid named, decimal, and hexadecimal character references that already appear in source markup. Bare or malformed ampersands are still escaped. Forward slashes are never escaped.

      Usage:

      import { escapeHtmlAttribute } from "mazey";

      const rawValue = escapeHtmlAttribute(
      'https://example.com/?q="Mazey"&page=1'
      );
      const markupValue = escapeHtmlAttribute(
      "Mazey & TypeScript",
      { preserveEntities: true }
      );

      console.log(rawValue);
      console.log(markupValue);

      Output:

      https://example.com/?q="Mazey"&page=1
      Mazey & TypeScript
      

      Parameters

      • value: string

        Text to escape for a quoted HTML attribute.

      • options: { preserveEntities?: boolean } = {}

        Escaping options. Existing character references are escaped unless preserveEntities is true.

      Returns string

      The escaped attribute value.

      If value is not a string.

      This function performs context-specific escaping only. It does not validate URLs, sanitize arbitrary HTML, or make an unsafe attribute name or surrounding markup safe.