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

36 lines
881 B
JavaScript
Raw Permalink Normal View History

2016-01-27 10:29:26 +00:00
(function() {
2018-02-12 05:05:29 +00:00
/**
Definition of the SafeJsonLoader class.
@module utils/safe-json-loader
@license MIT. See LICENSE.md for details.
*/
2016-01-27 10:29:26 +00:00
var FS, SyntaxErrorEx;
FS = require('fs');
SyntaxErrorEx = require('./syntax-error-ex');
module.exports = function(file) {
2018-02-12 05:05:29 +00:00
var err, ret, retRaw;
2016-01-27 10:29:26 +00:00
ret = {};
try {
ret.raw = FS.readFileSync(file, 'utf8');
ret.json = JSON.parse(ret.raw);
2018-02-12 05:05:29 +00:00
} catch (error) {
err = error;
// If we get here, either FS.readFileSync or JSON.parse failed.
// We'll return HMSTATUS.readError or HMSTATUS.parseError.
2016-01-27 10:29:26 +00:00
retRaw = ret.raw && ret.raw.trim();
ret.ex = {
op: retRaw ? 'parse' : 'read',
2018-02-12 05:05:29 +00:00
inner: SyntaxErrorEx.is(err) ? new SyntaxErrorEx(err, retRaw) : err,
2016-01-27 10:29:26 +00:00
file: file
};
}
return ret;
};
}).call(this);
2016-02-02 02:14:36 +00:00
//# sourceMappingURL=safe-json-loader.js.map