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.
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.
Throws
If value is not a string.
Remarks
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.
Escape a string for use inside a quoted HTML attribute.
By default, the function escapes ampersands, angle brackets, double quotes, and single quotes. Set
preserveEntitiesto 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:
Output: