mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-07-11 12:41:06 +01:00
chore: decaffeinate: convert error.coffee and 58 other files to JS
This commit is contained in:
@ -1,33 +1,38 @@
|
||||
###*
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
/**
|
||||
Definition of the ResumeFactory class.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module core/resume-factory
|
||||
###
|
||||
*/
|
||||
|
||||
|
||||
|
||||
FS = require 'fs'
|
||||
HMS = require './status-codes'
|
||||
HME = require './event-codes'
|
||||
ResumeConverter = require 'fresh-jrs-converter'
|
||||
chalk = require 'chalk'
|
||||
SyntaxErrorEx = require '../utils/syntax-error-ex'
|
||||
_ = require 'underscore'
|
||||
resumeDetect = require '../utils/resume-detector'
|
||||
require 'string.prototype.startswith'
|
||||
const FS = require('fs');
|
||||
const HMS = require('./status-codes');
|
||||
const HME = require('./event-codes');
|
||||
const ResumeConverter = require('fresh-jrs-converter');
|
||||
const chalk = require('chalk');
|
||||
const SyntaxErrorEx = require('../utils/syntax-error-ex');
|
||||
const _ = require('underscore');
|
||||
const resumeDetect = require('../utils/resume-detector');
|
||||
require('string.prototype.startswith');
|
||||
|
||||
|
||||
|
||||
###*
|
||||
/**
|
||||
A simple factory class for FRESH and JSON Resumes.
|
||||
@class ResumeFactory
|
||||
###
|
||||
*/
|
||||
|
||||
ResumeFactory = module.exports =
|
||||
const ResumeFactory = (module.exports = {
|
||||
|
||||
|
||||
|
||||
###*
|
||||
/**
|
||||
Load one or more resumes from disk.
|
||||
|
||||
@param {Object} opts An options object with settings for the factory as well
|
||||
@ -41,72 +46,85 @@ ResumeFactory = module.exports =
|
||||
}
|
||||
}
|
||||
|
||||
###
|
||||
load: ( sources, opts, emitter ) ->
|
||||
sources.map( (src) ->
|
||||
@loadOne( src, opts, emitter )
|
||||
, @)
|
||||
*/
|
||||
load( sources, opts, emitter ) {
|
||||
return sources.map( function(src) {
|
||||
return this.loadOne( src, opts, emitter );
|
||||
}
|
||||
, this);
|
||||
},
|
||||
|
||||
|
||||
###* Load a single resume from disk. ###
|
||||
loadOne: ( src, opts, emitter ) ->
|
||||
/** Load a single resume from disk. */
|
||||
loadOne( src, opts, emitter ) {
|
||||
|
||||
toFormat = opts.format # Can be null
|
||||
let toFormat = opts.format; // Can be null
|
||||
|
||||
# Get the destination format. Can be 'fresh', 'jrs', or null/undefined.
|
||||
toFormat && (toFormat = toFormat.toLowerCase().trim())
|
||||
// Get the destination format. Can be 'fresh', 'jrs', or null/undefined.
|
||||
toFormat && (toFormat = toFormat.toLowerCase().trim());
|
||||
|
||||
# Load and parse the resume JSON
|
||||
info = _parse src, opts, emitter
|
||||
return info if info.fluenterror
|
||||
// Load and parse the resume JSON
|
||||
const info = _parse(src, opts, emitter);
|
||||
if (info.fluenterror) { return info; }
|
||||
|
||||
# Determine the resume format: FRESH or JRS
|
||||
json = info.json
|
||||
orgFormat = resumeDetect json
|
||||
if orgFormat == 'unk'
|
||||
info.fluenterror = HMS.unknownSchema
|
||||
return info
|
||||
// Determine the resume format: FRESH or JRS
|
||||
let { json } = info;
|
||||
const orgFormat = resumeDetect(json);
|
||||
if (orgFormat === 'unk') {
|
||||
info.fluenterror = HMS.unknownSchema;
|
||||
return info;
|
||||
}
|
||||
|
||||
# Convert between formats if necessary
|
||||
if toFormat and ( orgFormat != toFormat )
|
||||
json = ResumeConverter[ 'to' + toFormat.toUpperCase() ] json
|
||||
// Convert between formats if necessary
|
||||
if (toFormat && ( orgFormat !== toFormat )) {
|
||||
json = ResumeConverter[ `to${toFormat.toUpperCase()}` ](json);
|
||||
}
|
||||
|
||||
# Objectify the resume, that is, convert it from JSON to a FRESHResume
|
||||
# or JRSResume object.
|
||||
rez = null
|
||||
if opts.objectify
|
||||
reqLib = '../core/' + (toFormat || orgFormat) + '-resume'
|
||||
ResumeClass = require reqLib
|
||||
rez = new ResumeClass().parseJSON( json, opts.inner )
|
||||
rez.i().file = src
|
||||
// Objectify the resume, that is, convert it from JSON to a FRESHResume
|
||||
// or JRSResume object.
|
||||
let rez = null;
|
||||
if (opts.objectify) {
|
||||
const reqLib = `../core/${toFormat || orgFormat}-resume`;
|
||||
const ResumeClass = require(reqLib);
|
||||
rez = new ResumeClass().parseJSON( json, opts.inner );
|
||||
rez.i().file = src;
|
||||
}
|
||||
|
||||
file: src
|
||||
json: info.json
|
||||
rez: rez
|
||||
return {
|
||||
file: src,
|
||||
json: info.json,
|
||||
rez
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
_parse = ( fileName, opts, eve ) ->
|
||||
var _parse = function( fileName, opts, eve ) {
|
||||
|
||||
rawData = null
|
||||
try
|
||||
let rawData = null;
|
||||
try {
|
||||
|
||||
# Read the file
|
||||
// Read the file
|
||||
eve && eve.stat( HME.beforeRead, { file: fileName });
|
||||
rawData = FS.readFileSync( fileName, 'utf8' );
|
||||
eve && eve.stat( HME.afterRead, { file: fileName, data: rawData });
|
||||
|
||||
# Parse the file
|
||||
eve && eve.stat HME.beforeParse, { data: rawData }
|
||||
ret = { json: JSON.parse( rawData ) }
|
||||
orgFormat =
|
||||
if ret.json.meta && ret.json.meta.format && ret.json.meta.format.startsWith('FRESH@')
|
||||
then 'fresh' else 'jrs'
|
||||
// Parse the file
|
||||
eve && eve.stat(HME.beforeParse, { data: rawData });
|
||||
const ret = { json: JSON.parse( rawData ) };
|
||||
const orgFormat =
|
||||
ret.json.meta && ret.json.meta.format && ret.json.meta.format.startsWith('FRESH@')
|
||||
? 'fresh' : 'jrs';
|
||||
|
||||
eve && eve.stat HME.afterParse, { file: fileName, data: ret.json, fmt: orgFormat }
|
||||
return ret
|
||||
catch err
|
||||
# Can be ENOENT, EACCES, SyntaxError, etc.
|
||||
fluenterror: if rawData then HMS.parseError else HMS.readError
|
||||
inner: err
|
||||
raw: rawData
|
||||
file: fileName
|
||||
eve && eve.stat(HME.afterParse, { file: fileName, data: ret.json, fmt: orgFormat });
|
||||
return ret;
|
||||
} catch (err) {
|
||||
// Can be ENOENT, EACCES, SyntaxError, etc.
|
||||
return {
|
||||
fluenterror: rawData ? HMS.parseError : HMS.readError,
|
||||
inner: err,
|
||||
raw: rawData,
|
||||
file: fileName
|
||||
};
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user