1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-16 22:00:09 +00:00
HackMyResume/dist/utils/safe-json-loader.js

35 lines
732 B
JavaScript
Raw Normal View History

2016-01-27 10:29:26 +00:00
/**
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);
2016-02-02 02:14:36 +00:00
//# sourceMappingURL=safe-json-loader.js.map