2016-01-27 10:29:26 +00:00
|
|
|
(function() {
|
2018-02-12 05:05:29 +00:00
|
|
|
/**
|
|
|
|
Definition of the FRESHResume class.
|
|
|
|
@license MIT. See LICENSE.md for details.
|
|
|
|
@module core/fresh-resume
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
Convert human-friendly dates into formal Moment.js dates for all collections.
|
|
|
|
We don't want to lose the raw textual date as entered by the user, so we store
|
|
|
|
the Moment-ified date as a separate property with a prefix of .safe. For ex:
|
|
|
|
job.startDate is the date as entered by the user. job.safeStartDate is the
|
|
|
|
parsed Moment.js date that we actually use in processing.
|
|
|
|
*/
|
2018-02-05 03:49:58 +00:00
|
|
|
var CONVERTER, FS, FluentDate, FreshResume, JRSResume, MD, PATH, XML, _, __, _parseDates, extend, moment, validator;
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
FS = require('fs');
|
|
|
|
|
|
|
|
extend = require('extend');
|
|
|
|
|
|
|
|
validator = require('is-my-json-valid');
|
|
|
|
|
|
|
|
_ = require('underscore');
|
|
|
|
|
|
|
|
__ = require('lodash');
|
|
|
|
|
|
|
|
PATH = require('path');
|
|
|
|
|
|
|
|
moment = require('moment');
|
|
|
|
|
|
|
|
XML = require('xml-escape');
|
|
|
|
|
|
|
|
MD = require('marked');
|
|
|
|
|
|
|
|
CONVERTER = require('fresh-jrs-converter');
|
|
|
|
|
|
|
|
JRSResume = require('./jrs-resume');
|
|
|
|
|
2016-01-30 21:40:22 +00:00
|
|
|
FluentDate = require('./fluent-date');
|
|
|
|
|
2016-01-27 10:29:26 +00:00
|
|
|
/**
|
|
|
|
A FRESH resume or CV. FRESH resumes are backed by JSON, and each FreshResume
|
|
|
|
object is an instantiation of that JSON decorated with utility methods.
|
|
|
|
@constructor
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
FreshResume = class FreshResume { // extends AbstractResume
|
2016-01-27 10:29:26 +00:00
|
|
|
/** Initialize the the FreshResume from JSON string data. */
|
2018-02-12 05:05:29 +00:00
|
|
|
parse(stringData, opts) {
|
2016-01-29 20:23:57 +00:00
|
|
|
var ref;
|
|
|
|
this.imp = (ref = this.imp) != null ? ref : {
|
|
|
|
raw: stringData
|
|
|
|
};
|
2016-01-27 10:29:26 +00:00
|
|
|
return this.parseJSON(JSON.parse(stringData), opts);
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initialize the FreshResume from JSON.
|
|
|
|
Open and parse the specified FRESH resume. Merge the JSON object model onto
|
|
|
|
this Sheet instance with extend() and convert sheet dates to a safe &
|
|
|
|
consistent format. Then sort each section by startDate descending.
|
|
|
|
@param rep {Object} The raw JSON representation.
|
|
|
|
@param opts {Object} Resume loading and parsing options.
|
|
|
|
{
|
2018-02-12 05:05:29 +00:00
|
|
|
date: Perform safe date conversion.
|
|
|
|
sort: Sort resume items by date.
|
|
|
|
compute: Prepare computed resume totals.
|
2016-01-27 10:29:26 +00:00
|
|
|
}
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
parseJSON(rep, opts) {
|
|
|
|
var ignoreList, privateList, ref, scrubbed, scrubber;
|
2018-02-01 11:44:07 +00:00
|
|
|
if (opts && opts.privatize) {
|
2018-02-12 05:05:29 +00:00
|
|
|
// Ignore any element with the 'ignore: true' or 'private: true' designator.
|
2018-02-05 03:49:58 +00:00
|
|
|
scrubber = require('../utils/resume-scrubber');
|
2018-02-12 05:05:29 +00:00
|
|
|
({scrubbed, ignoreList, privateList} = scrubber.scrubResume(rep, opts));
|
2018-02-01 11:44:07 +00:00
|
|
|
}
|
2018-02-12 05:05:29 +00:00
|
|
|
// Now apply the resume representation onto this object
|
2018-02-01 11:44:07 +00:00
|
|
|
extend(true, this, opts && opts.privatize ? scrubbed : rep);
|
2018-02-12 05:05:29 +00:00
|
|
|
if (!((ref = this.imp) != null ? ref.processed : void 0)) {
|
|
|
|
// Set up metadata TODO: Clean up metadata on the object model.
|
2016-01-27 10:29:26 +00:00
|
|
|
opts = opts || {};
|
|
|
|
if (opts.imp === void 0 || opts.imp) {
|
|
|
|
this.imp = this.imp || {};
|
|
|
|
this.imp.title = (opts.title || this.imp.title) || this.name;
|
2016-01-29 20:23:57 +00:00
|
|
|
if (!this.imp.raw) {
|
|
|
|
this.imp.raw = JSON.stringify(rep);
|
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
}
|
2016-01-29 20:23:57 +00:00
|
|
|
this.imp.processed = true;
|
2018-02-12 05:05:29 +00:00
|
|
|
// Parse dates, sort dates, and calculate computed values
|
2016-01-27 10:29:26 +00:00
|
|
|
(opts.date === void 0 || opts.date) && _parseDates.call(this);
|
|
|
|
(opts.sort === void 0 || opts.sort) && this.sort();
|
|
|
|
(opts.compute === void 0 || opts.compute) && (this.computed = {
|
|
|
|
numYears: this.duration(),
|
|
|
|
keywords: this.keywords()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return this;
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/** Save the sheet to disk (for environments that have disk access). */
|
2018-02-12 05:05:29 +00:00
|
|
|
save(filename) {
|
2016-01-27 10:29:26 +00:00
|
|
|
this.imp.file = filename || this.imp.file;
|
|
|
|
FS.writeFileSync(this.imp.file, this.stringify(), 'utf8');
|
|
|
|
return this;
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Save the sheet to disk in a specific format, either FRESH or JSON Resume.
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
saveAs(filename, format) {
|
2018-02-10 06:10:20 +00:00
|
|
|
var newRep, parts, safeFormat, useEdgeSchema;
|
2018-02-12 05:05:29 +00:00
|
|
|
// If format isn't specified, default to FRESH
|
2018-02-10 06:10:20 +00:00
|
|
|
safeFormat = (format && format.trim()) || 'FRESH';
|
2018-02-12 05:05:29 +00:00
|
|
|
// Validate against the FRESH version regex
|
|
|
|
// freshVersionReg = require '../utils/fresh-version-regex'
|
|
|
|
// if (not freshVersionReg().test( safeFormat ))
|
|
|
|
// throw badVer: safeFormat
|
2018-02-10 02:34:24 +00:00
|
|
|
parts = safeFormat.split('@');
|
|
|
|
if (parts[0] === 'FRESH') {
|
2016-01-27 10:29:26 +00:00
|
|
|
this.imp.file = filename || this.imp.file;
|
|
|
|
FS.writeFileSync(this.imp.file, this.stringify(), 'utf8');
|
2018-02-10 02:34:24 +00:00
|
|
|
} else if (parts[0] === 'JRS') {
|
2018-02-10 06:10:20 +00:00
|
|
|
useEdgeSchema = parts.length > 1 ? parts[1] === '1' : false;
|
|
|
|
newRep = CONVERTER.toJRS(this, {
|
|
|
|
edge: useEdgeSchema
|
|
|
|
});
|
2016-01-27 10:29:26 +00:00
|
|
|
FS.writeFileSync(filename, JRSResume.stringify(newRep), 'utf8');
|
2018-02-10 02:34:24 +00:00
|
|
|
} else {
|
|
|
|
throw {
|
|
|
|
badVer: safeFormat
|
|
|
|
};
|
2016-01-27 10:29:26 +00:00
|
|
|
}
|
|
|
|
return this;
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Duplicate this FreshResume instance.
|
|
|
|
This method first extend()s this object onto an empty, creating a deep copy,
|
|
|
|
and then passes the result into a new FreshResume instance via .parseJSON.
|
|
|
|
We do it this way to create a true clone of the object without re-running any
|
|
|
|
of the associated processing.
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
dupe() {
|
2016-01-27 10:29:26 +00:00
|
|
|
var jso, rnew;
|
|
|
|
jso = extend(true, {}, this);
|
|
|
|
rnew = new FreshResume();
|
|
|
|
rnew.parseJSON(jso, {});
|
|
|
|
return rnew;
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Convert this object to a JSON string, sanitizing meta-properties along the
|
|
|
|
way.
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
stringify() {
|
2016-01-27 10:29:26 +00:00
|
|
|
return FreshResume.stringify(this);
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Create a copy of this resume in which all string fields have been run through
|
|
|
|
a transformation function (such as a Markdown filter or XML encoder).
|
|
|
|
TODO: Move this out of FRESHResume.
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
transformStrings(filt, transformer) {
|
2016-01-27 10:29:26 +00:00
|
|
|
var ret, trx;
|
|
|
|
ret = this.dupe();
|
|
|
|
trx = require('../utils/string-transformer');
|
|
|
|
return trx(ret, filt, transformer);
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Create a copy of this resume in which all fields have been interpreted as
|
|
|
|
Markdown.
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
markdownify() {
|
2016-01-27 10:29:26 +00:00
|
|
|
var MDIN, trx;
|
|
|
|
MDIN = function(txt) {
|
|
|
|
return MD(txt || '').replace(/^\s*<p>|<\/p>\s*$/gi, '');
|
|
|
|
};
|
|
|
|
trx = function(key, val) {
|
|
|
|
if (key === 'summary') {
|
|
|
|
return MD(val);
|
|
|
|
}
|
|
|
|
return MDIN(val);
|
|
|
|
};
|
|
|
|
return this.transformStrings(['skills', 'url', 'start', 'end', 'date'], trx);
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Create a copy of this resume in which all fields have been interpreted as
|
|
|
|
Markdown.
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
xmlify() {
|
2016-01-27 10:29:26 +00:00
|
|
|
var trx;
|
|
|
|
trx = function(key, val) {
|
|
|
|
return XML(val);
|
|
|
|
};
|
|
|
|
return this.transformStrings([], trx);
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/** Return the resume format. */
|
2018-02-12 05:05:29 +00:00
|
|
|
format() {
|
2016-01-27 10:29:26 +00:00
|
|
|
return 'FRESH';
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return internal metadata. Create if it doesn't exist.
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
i() {
|
2016-01-27 10:29:26 +00:00
|
|
|
return this.imp = this.imp || {};
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
2018-02-09 05:17:10 +00:00
|
|
|
/**
|
|
|
|
Return a unique list of all skills declared in the resume.
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
// TODO: Several problems here:
|
|
|
|
// 1) Confusing name. Easily confused with the keyword-inspector module, which
|
|
|
|
// parses resume body text looking for these same keywords. This should probably
|
|
|
|
// be renamed.
|
|
|
|
|
|
|
|
// 2) Doesn't bother trying to integrate skills.list with skills.sets if they
|
|
|
|
// happen to declare different skills, and if skills.sets declares ONE skill and
|
|
|
|
// skills.list declared 50, only 1 skill will be registered.
|
|
|
|
|
|
|
|
// 3) In the future, skill.sets should only be able to use skills declared in
|
|
|
|
// skills.list. That is, skills.list is the official record of a candidate's
|
|
|
|
// declared skills. skills.sets is just a way of grouping those into skillsets
|
|
|
|
// for easier consumption.
|
|
|
|
keywords() {
|
2016-01-27 10:29:26 +00:00
|
|
|
var flatSkills;
|
|
|
|
flatSkills = [];
|
|
|
|
if (this.skills) {
|
|
|
|
if (this.skills.sets) {
|
|
|
|
flatSkills = this.skills.sets.map(function(sk) {
|
|
|
|
return sk.skills;
|
|
|
|
}).reduce(function(a, b) {
|
|
|
|
return a.concat(b);
|
|
|
|
});
|
|
|
|
} else if (this.skills.list) {
|
|
|
|
flatSkills = flatSkills.concat(this.skills.list.map(function(sk) {
|
|
|
|
return sk.name;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
flatSkills = _.uniq(flatSkills);
|
|
|
|
}
|
|
|
|
return flatSkills;
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Reset the sheet to an empty state. TODO: refactor/review
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
clear(clearMeta) {
|
2016-01-27 10:29:26 +00:00
|
|
|
clearMeta = ((clearMeta === void 0) && true) || clearMeta;
|
|
|
|
if (clearMeta) {
|
|
|
|
delete this.imp;
|
|
|
|
}
|
2018-02-12 05:05:29 +00:00
|
|
|
delete this.computed; // Don't use Object.keys() here
|
2016-01-27 10:29:26 +00:00
|
|
|
delete this.employment;
|
|
|
|
delete this.service;
|
|
|
|
delete this.education;
|
|
|
|
delete this.recognition;
|
|
|
|
delete this.reading;
|
|
|
|
delete this.writing;
|
|
|
|
delete this.interests;
|
|
|
|
delete this.skills;
|
|
|
|
return delete this.social;
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Get a safe count of the number of things in a section.
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
count(obj) {
|
2016-01-27 10:29:26 +00:00
|
|
|
if (!obj) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (obj.history) {
|
|
|
|
return obj.history.length;
|
|
|
|
}
|
|
|
|
if (obj.sets) {
|
|
|
|
return obj.sets.length;
|
|
|
|
}
|
|
|
|
return obj.length || 0;
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
2018-02-12 05:05:29 +00:00
|
|
|
add(moniker) {
|
2016-01-27 10:29:26 +00:00
|
|
|
var defSheet, newObject;
|
2018-02-12 05:05:29 +00:00
|
|
|
defSheet = FreshResume.default();
|
2016-01-27 10:29:26 +00:00
|
|
|
newObject = defSheet[moniker].history ? $.extend(true, {}, defSheet[moniker].history[0]) : moniker === 'skills' ? $.extend(true, {}, defSheet.skills.sets[0]) : $.extend(true, {}, defSheet[moniker][0]);
|
|
|
|
this[moniker] = this[moniker] || [];
|
|
|
|
if (this[moniker].history) {
|
|
|
|
this[moniker].history.push(newObject);
|
|
|
|
} else if (moniker === 'skills') {
|
|
|
|
this.skills.sets.push(newObject);
|
|
|
|
} else {
|
|
|
|
this[moniker].push(newObject);
|
|
|
|
}
|
|
|
|
return newObject;
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Determine if the sheet includes a specific social profile (eg, GitHub).
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
hasProfile(socialNetwork) {
|
2016-01-27 10:29:26 +00:00
|
|
|
socialNetwork = socialNetwork.trim().toLowerCase();
|
|
|
|
return this.social && _.some(this.social, function(p) {
|
|
|
|
return p.network.trim().toLowerCase() === socialNetwork;
|
|
|
|
});
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/** Return the specified network profile. */
|
2018-02-12 05:05:29 +00:00
|
|
|
getProfile(socialNetwork) {
|
2016-01-27 10:29:26 +00:00
|
|
|
socialNetwork = socialNetwork.trim().toLowerCase();
|
|
|
|
return this.social && _.find(this.social, function(sn) {
|
|
|
|
return sn.network.trim().toLowerCase() === socialNetwork;
|
|
|
|
});
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return an array of profiles for the specified network, for when the user
|
|
|
|
has multiple eg. GitHub accounts.
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
getProfiles(socialNetwork) {
|
2016-01-27 10:29:26 +00:00
|
|
|
socialNetwork = socialNetwork.trim().toLowerCase();
|
|
|
|
return this.social && _.filter(this.social, function(sn) {
|
|
|
|
return sn.network.trim().toLowerCase() === socialNetwork;
|
|
|
|
});
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/** Determine if the sheet includes a specific skill. */
|
2018-02-12 05:05:29 +00:00
|
|
|
hasSkill(skill) {
|
2016-01-27 10:29:26 +00:00
|
|
|
skill = skill.trim().toLowerCase();
|
|
|
|
return this.skills && _.some(this.skills, function(sk) {
|
|
|
|
return sk.keywords && _.some(sk.keywords, function(kw) {
|
|
|
|
return kw.trim().toLowerCase() === skill;
|
|
|
|
});
|
|
|
|
});
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/** Validate the sheet against the FRESH Resume schema. */
|
2018-02-12 05:05:29 +00:00
|
|
|
isValid(info) {
|
2016-01-27 10:29:26 +00:00
|
|
|
var ret, schemaObj, validate;
|
2018-02-02 09:48:28 +00:00
|
|
|
schemaObj = require('fresh-resume-schema');
|
2016-01-27 10:29:26 +00:00
|
|
|
validator = require('is-my-json-valid');
|
2018-02-12 05:05:29 +00:00
|
|
|
validate = validator(schemaObj, { // See Note [1].
|
2016-01-27 10:29:26 +00:00
|
|
|
formats: {
|
|
|
|
date: /^\d{4}(?:-(?:0[0-9]{1}|1[0-2]{1})(?:-[0-9]{2})?)?$/
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ret = validate(this);
|
|
|
|
if (!ret) {
|
|
|
|
this.imp = this.imp || {};
|
|
|
|
this.imp.validationErrors = validate.errors;
|
|
|
|
}
|
|
|
|
return ret;
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
2018-02-12 05:05:29 +00:00
|
|
|
duration(unit) {
|
2018-02-05 03:49:58 +00:00
|
|
|
var inspector;
|
|
|
|
inspector = require('../inspectors/duration-inspector');
|
|
|
|
return inspector.run(this, 'employment.history', 'start', 'end', unit);
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sort dated things on the sheet by start date descending. Assumes that dates
|
|
|
|
on the sheet have been processed with _parseDates().
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
sort() {
|
2016-01-27 10:29:26 +00:00
|
|
|
var byDateDesc, sortSection;
|
|
|
|
byDateDesc = function(a, b) {
|
|
|
|
if (a.safe.start.isBefore(b.safe.start)) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
2016-01-30 21:40:22 +00:00
|
|
|
if (a.safe.start.isAfter(b.safe.start)) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
sortSection = function(key) {
|
|
|
|
var ar, datedThings;
|
|
|
|
ar = __.get(this, key);
|
|
|
|
if (ar && ar.length) {
|
|
|
|
datedThings = obj.filter(function(o) {
|
|
|
|
return o.start;
|
|
|
|
});
|
|
|
|
return datedThings.sort(byDateDesc);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
sortSection('employment.history');
|
|
|
|
sortSection('education.history');
|
|
|
|
sortSection('service.history');
|
|
|
|
sortSection('projects');
|
|
|
|
return this.writing && this.writing.sort(function(a, b) {
|
|
|
|
if (a.safe.date.isBefore(b.safe.date)) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return (a.safe.date.isAfter(b.safe.date) && -1) || 0;
|
|
|
|
}
|
|
|
|
});
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
2018-02-12 05:05:29 +00:00
|
|
|
};
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Get the default (starter) sheet.
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
FreshResume.default = function() {
|
2016-02-04 23:49:16 +00:00
|
|
|
return new FreshResume().parseJSON(require('fresh-resume-starter').fresh);
|
2016-01-27 10:29:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
Convert the supplied FreshResume to a JSON string, sanitizing meta-properties
|
|
|
|
along the way.
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
2016-01-27 10:29:26 +00:00
|
|
|
FreshResume.stringify = function(obj) {
|
|
|
|
var replacer;
|
2018-02-12 05:05:29 +00:00
|
|
|
replacer = function(key, value) { // Exclude these keys from stringification
|
2016-01-27 10:29:26 +00:00
|
|
|
var exKeys;
|
|
|
|
exKeys = ['imp', 'warnings', 'computed', 'filt', 'ctrl', 'index', 'safe', 'result', 'isModified', 'htmlPreview', 'display_progress_bar'];
|
|
|
|
if (_.some(exKeys, function(val) {
|
|
|
|
return key.trim() === val;
|
|
|
|
})) {
|
|
|
|
return void 0;
|
|
|
|
} else {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return JSON.stringify(obj, replacer, 2);
|
|
|
|
};
|
|
|
|
|
|
|
|
_parseDates = function() {
|
|
|
|
var _fmt, replaceDatesInObject, that;
|
|
|
|
_fmt = require('./fluent-date').fmt;
|
|
|
|
that = this;
|
2018-02-12 05:05:29 +00:00
|
|
|
// TODO: refactor recursion
|
2016-01-27 10:29:26 +00:00
|
|
|
replaceDatesInObject = function(obj) {
|
|
|
|
if (!obj) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Object.prototype.toString.call(obj) === '[object Array]') {
|
2016-01-30 21:40:22 +00:00
|
|
|
obj.forEach(function(elem) {
|
2016-01-27 10:29:26 +00:00
|
|
|
return replaceDatesInObject(elem);
|
|
|
|
});
|
|
|
|
} else if (typeof obj === 'object') {
|
|
|
|
if (obj._isAMomentObject || obj.safe) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Object.keys(obj).forEach(function(key) {
|
|
|
|
return replaceDatesInObject(obj[key]);
|
|
|
|
});
|
2016-01-30 21:40:22 +00:00
|
|
|
['start', 'end', 'date'].forEach(function(val) {
|
2016-01-27 10:29:26 +00:00
|
|
|
if ((obj[val] !== void 0) && (!obj.safe || !obj.safe[val])) {
|
|
|
|
obj.safe = obj.safe || {};
|
|
|
|
obj.safe[val] = _fmt(obj[val]);
|
|
|
|
if (obj[val] && (val === 'start') && !obj.end) {
|
2016-01-30 21:40:22 +00:00
|
|
|
obj.safe.end = _fmt('current');
|
2016-01-27 10:29:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2016-01-30 21:40:22 +00:00
|
|
|
Object.keys(this).forEach(function(member) {
|
|
|
|
replaceDatesInObject(that[member]);
|
2016-01-27 10:29:26 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Export the Sheet function/ctor. */
|
|
|
|
module.exports = FreshResume;
|
|
|
|
|
2018-02-12 05:05:29 +00:00
|
|
|
// Note 1: Adjust default date validation to allow YYYY and YYYY-MM formats
|
|
|
|
// in addition to YYYY-MM-DD. The original regex:
|
|
|
|
|
|
|
|
// /^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-[0-9]{2}$/
|
|
|
|
|
|
|
|
|
2016-01-27 10:29:26 +00:00
|
|
|
}).call(this);
|
2016-02-02 02:14:36 +00:00
|
|
|
|
|
|
|
//# sourceMappingURL=fresh-resume.js.map
|