json-parse-even-better-errors
Advanced tools
Comparing version 2.3.0 to 2.3.1
@@ -69,3 +69,6 @@ 'use strict' | ||
// things other than objects and arrays aren't indented, so ignore those | ||
// Important: in both of these regexps, the $1 capture group is the newline | ||
// or undefined, and the $2 capture group is the indent, or undefined. | ||
const formatRE = /^\s*[{\[]((?:\r?\n)+)([\s\t]*)/ | ||
const emptyRE = /^(?:\{\}|\[\])((?:\r?\n)+)?$/ | ||
@@ -81,3 +84,7 @@ const parseJson = (txt, reviver, context) => { | ||
// JSON.stringify ignores symbols, so this is reasonably safe. | ||
const [, newline, indent] = parseText.match(formatRE) || [, '', ''] | ||
// if the string is '{}' or '[]', then use the default 2-space indent. | ||
const [, newline = '\n', indent = ' '] = parseText.match(emptyRE) || | ||
parseText.match(formatRE) || | ||
[, '', ''] | ||
const result = JSON.parse(parseText, reviver) | ||
@@ -84,0 +91,0 @@ if (result && typeof result === 'object') { |
Copyright 2017 Kat Marchán | ||
Copyright npm, Inc. and Contributors | ||
Copyright npm, Inc. | ||
@@ -4,0 +4,0 @@ Permission is hereby granted, free of charge, to any person obtaining a |
{ | ||
"name": "json-parse-even-better-errors", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "JSON.parse with context information on error", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
10426
105