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

Function createStrictSyntaxError

lib/types/json.js:156–178  ·  view source on GitHub ↗

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

(str, char)

Source from the content-addressed store, hash-verified

154 */
155
156function createStrictSyntaxError (str, char) {
157 var index = str.indexOf(char)
158 var partial = ''
159
160 if (index !== -1) {
161 partial = str.substring(0, index) + JSON_SYNTAX_CHAR
162
163 for (var i = index + 1; i < str.length; i++) {
164 partial += JSON_SYNTAX_CHAR
165 }
166 }
167
168 try {
169 JSON.parse(partial); /* istanbul ignore next */ throw new SyntaxError('strict violation')
170 } catch (e) {
171 return normalizeJsonSyntaxError(e, {
172 message: e.message.replace(JSON_SYNTAX_REGEXP, function (placeholder) {
173 return str.substring(index, index + placeholder.length)
174 }),
175 stack: e.stack
176 })
177 }
178}
179
180/**
181 * Get the first non-whitespace character in a string.

Callers 1

parseFunction · 0.85

Calls 1

normalizeJsonSyntaxErrorFunction · 0.85

Tested by

no test coverage detected