MCPcopy Create free account
hub / github.com/expressjs/body-parser / createStrictSyntaxError

Function createStrictSyntaxError

lib/types/json.js:130–148  ·  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

128 * @private
129 */
130function createStrictSyntaxError (str, char) {
131 const index = str.indexOf(char)
132 let partial = ''
133
134 if (index !== -1) {
135 partial = str.substring(0, index) + JSON_SYNTAX_CHAR.repeat(str.length - index)
136 }
137
138 try {
139 JSON.parse(partial); /* istanbul ignore next */ throw new SyntaxError('strict violation')
140 } catch (e) {
141 return normalizeJsonSyntaxError(e, {
142 message: e.message.replace(JSON_SYNTAX_REGEXP, function (placeholder) {
143 return str.substring(index, index + placeholder.length)
144 }),
145 stack: e.stack
146 })
147 }
148}
149
150/**
151 * 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