You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. var errorEx = require('error-ex');
  3. var fallback = require('./vendor/parse');
  4. var JSONError = errorEx('JSONError', {
  5. fileName: errorEx.append('in %s')
  6. });
  7. module.exports = function (x, reviver, filename) {
  8. if (typeof reviver === 'string') {
  9. filename = reviver;
  10. reviver = null;
  11. }
  12. try {
  13. try {
  14. return JSON.parse(x, reviver);
  15. } catch (err) {
  16. fallback.parse(x, {
  17. mode: 'json',
  18. reviver: reviver
  19. });
  20. throw err;
  21. }
  22. } catch (err) {
  23. var jsonErr = new JSONError(err);
  24. if (filename) {
  25. jsonErr.fileName = filename;
  26. }
  27. throw jsonErr;
  28. }
  29. };