mirror of
				https://github.com/JuanCanham/HackMyResume.git
				synced 2025-11-04 06:47:27 +00:00 
			
		
		
		
	Reintroduce HackMyCore, dropping the interim submodule, and reorganize and improve tests.
		
			
				
	
	
		
			33 lines
		
	
	
		
			686 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			686 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
 | 
						|
/**
 | 
						|
Definition of the SafeJsonLoader class.
 | 
						|
@module utils/safe-json-loader
 | 
						|
@license MIT. See LICENSE.md for details.
 | 
						|
 */
 | 
						|
 | 
						|
(function() {
 | 
						|
  var FS, SyntaxErrorEx;
 | 
						|
 | 
						|
  FS = require('fs');
 | 
						|
 | 
						|
  SyntaxErrorEx = require('./syntax-error-ex');
 | 
						|
 | 
						|
  module.exports = function(file) {
 | 
						|
    var ret, retRaw;
 | 
						|
    ret = {};
 | 
						|
    try {
 | 
						|
      ret.raw = FS.readFileSync(file, 'utf8');
 | 
						|
      ret.json = JSON.parse(ret.raw);
 | 
						|
    } catch (_error) {
 | 
						|
      retRaw = ret.raw && ret.raw.trim();
 | 
						|
      ret.ex = {
 | 
						|
        operation: retRaw ? 'parse' : 'read',
 | 
						|
        inner: SyntaxErrorEx.is(_error) ? new SyntaxErrorEx(_error, retRaw) : _error,
 | 
						|
        file: file
 | 
						|
      };
 | 
						|
    }
 | 
						|
    return ret;
 | 
						|
  };
 | 
						|
 | 
						|
}).call(this);
 |