You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

escape.ts 462B

123456789101112131415161718
  1. function escape(input: string): string {
  2. if (!input || typeof input !== 'string')
  3. return ''
  4. const res = input
  5. // .replaceAll('\\', '\\\\') // This would add too many backslashes
  6. .replaceAll('\0', '\\0')
  7. .replaceAll('\b', '\\b')
  8. .replaceAll('\f', '\\f')
  9. .replaceAll('\n', '\\n')
  10. .replaceAll('\r', '\\r')
  11. .replaceAll('\t', '\\t')
  12. .replaceAll('\v', '\\v')
  13. .replaceAll('\'', '\\\'')
  14. return res
  15. }
  16. export default escape