Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
at main 753 B view raw
1// See: https://github.com/vercel/next.js/blob/6bc07792a4462a4bf921a72ab30dc4ab2c4e1bda/packages/next/src/server/htmlescape.ts 2// License: https://github.com/vercel/next.js/blob/6bc07792a4462a4bf921a72ab30dc4ab2c4e1bda/packages/next/license.md 3 4// This utility is based on https://github.com/zertosh/htmlescape 5// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE 6 7const ESCAPE_LOOKUP: { [match: string]: string } = { 8 '&': '\\u0026', 9 '>': '\\u003e', 10 '<': '\\u003c', 11 '\u2028': '\\u2028', 12 '\u2029': '\\u2029', 13}; 14 15export const ESCAPE_REGEX = /[&><\u2028\u2029]/g; 16 17export function htmlEscapeJsonString(str: string): string { 18 return str.replace(ESCAPE_REGEX, match => ESCAPE_LOOKUP[match]); 19}