MCPcopy Index your code
hub / github.com/expressjs/body-parser / createStrictSyntaxError

Function createStrictSyntaxError

lib/types/json.js:128–146  ·  view source on GitHub ↗

* Create strict violation syntax error matching native error. * * @param {string} str * @param {string} char * @returns {Error} * @private

(str, char)

Source from the content-addressed store, hash-verified

126 * @private
127 */
128function createStrictSyntaxError (str, char) {
129 const index = str.indexOf(char)
130 let partial = ''
131
132 if (index !== -1) {
133 partial = str.substring(0, index) + JSON_SYNTAX_CHAR.repeat(str.length - index)
134 }
135
136 try {
137 JSON.parse(partial); /* istanbul ignore next */ throw new SyntaxError('strict violation')
138 } catch (e) {
139 return normalizeJsonSyntaxError(e, {
140 message: e.message.replace(JSON_SYNTAX_REGEXP, function (placeholder) {
141 return str.substring(index, index + placeholder.length)
142 }),
143 stack: e.stack
144 })
145 }
146}
147
148/**
149 * Get the first non-whitespace character in a string.

Callers 1

createJsonParserFunction · 0.85

Calls 1

normalizeJsonSyntaxErrorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…