MCPcopy Create free account
hub / github.com/json5/json5 / formatChar

Function formatChar

lib/parse.js:1081–1107  ·  view source on GitHub ↗
(c)

Source from the content-addressed store, hash-verified

1079}
1080
1081function formatChar (c) {
1082 const replacements = {
1083 "'": "\\'",
1084 '"': '\\"',
1085 '\\': '\\\\',
1086 '\b': '\\b',
1087 '\f': '\\f',
1088 '\n': '\\n',
1089 '\r': '\\r',
1090 '\t': '\\t',
1091 '\v': '\\v',
1092 '\0': '\\0',
1093 '\u2028': '\\u2028',
1094 '\u2029': '\\u2029',
1095 }
1096
1097 if (replacements[c]) {
1098 return replacements[c]
1099 }
1100
1101 if (c < ' ') {
1102 const hexString = c.charCodeAt(0).toString(16)
1103 return '\\x' + ('00' + hexString).substring(hexString.length)
1104 }
1105
1106 return c
1107}
1108
1109function syntaxError (message) {
1110 const err = new SyntaxError(message)

Callers 2

invalidCharFunction · 0.85
separatorCharFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…