Open History to see the last commit
1// --------------------------------------------------------------------------------
2//
3// copied from
4// https://github.com/vercel/next.js/blob/6bc07792a4462a4bf921a72ab30dc4ab2c4e1bda/packages/next/src/server/htmlescape.ts
5// License: https://github.com/vercel/next.js/blob/6bc07792a4462a4bf921a72ab30dc4ab2c4e1bda/packages/next/license.md
6//
7// --------------------------------------------------------------------------------
8β
9// This utility is based on https://github.com/zertosh/htmlescape
10// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE
11β
12const ESCAPE_LOOKUP: Record<string, string> = {
13 '&': '\\u0026',
14 '>': '\\u003e',
15 '<': '\\u003c',
16 '\u2028': '\\u2028',
17 '\u2029': '\\u2029',
18}
19β
20export const ESCAPE_REGEX = /[&><\u2028\u2029]/g
21β
22export function htmlEscapeJsonString(str: string): string {
23 return str.replace(ESCAPE_REGEX, (match) => ESCAPE_LOOKUP[match]!)
24}