Skip to content

Commit

Permalink
feat: improve converter interface
Browse files Browse the repository at this point in the history
Simplify the converter interface. This is a breaking change, so bump the
(major) version to 1.0.
  • Loading branch information
hacksalot committed Feb 10, 2018
1 parent a7b7b1d commit c7a2ca9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 50 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fresh-jrs-converter",
"version": "0.3.0",
"version": "1.0.0",
"description": "Convert résumés and CVs between FRESH and JSON Resume formats.",
"repository": {
"type": "git",
Expand Down
84 changes: 39 additions & 45 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ FRESH to JSON Resume conversion routines.
@method toFresh
@todo Refactor
*/
toFRESH: function( src, foreign ) {
toFRESH: function( src ) {

return {
name: src.basics.name,
Expand All @@ -67,53 +67,43 @@ FRESH to JSON Resume conversion routines.
/**
Convert from FRESH format to a specific JSON Resume format.
@param src The source FRESH resume object.
@param foreign Currently unused.
@param ver The JSON Resume version. If specified, must be "0", "1", or
"edge". If omitted, defaults to "edge" (the latest JSON Resume schema).
@param opts Options for the transformation.
@returns The converted resume object in JSON Resume format.
*/
toJRS: function( src, foreign, ver ) {

switch( ver || "edge" ) {

case "0":
return {
//meta: not in this version
basics: sect.jrs.basics( src ),
work: sect.jrs.work( src, src.employment ),
education: sect.jrs.education( src, src.education ),
//projects: not in this version
skills: sect.jrs.skills( src, src.skills ),
volunteer: sect.jrs.volunteer( src, src.service ),
awards: sect.jrs.awards( src, src.recognition ),
publications: sect.jrs.publications( src, src.writing ),
interests: src.interests,
references: sect.jrs.references( src, src.testimonials ),
languages: src.languages
};

case "1":
case "edge":
return {
meta: sect.jrs.meta( src, src.meta ),
basics: sect.jrs.basics( src ),
work: sect.jrs.work( src, src.employment ),
education: sect.jrs.education( src, src.education ),
projects: sect.jrs.projects( src, src.projects ),
skills: sect.jrs.skills( src, src.skills ),
volunteer: sect.jrs.volunteer( src, src.service ),
awards: sect.jrs.awards( src, src.recognition ),
publications: sect.jrs.publications( src, src.writing ),
interests: src.interests,
references: sect.jrs.references( src, src.testimonials ),
languages: src.languages
};

default:
// TODO: error
return null;
toJRS: function( src, opts ) {
opts = opts || { };
if( !opts.edge ) { // Convert to the 0.0.16 official JSON Resume
return {
//meta: not in this version
basics: sect.jrs.basics( src ),
work: sect.jrs.work( src, src.employment ),
education: sect.jrs.education( src, src.education ),
//projects: not in this version
skills: sect.jrs.skills( src, src.skills ),
volunteer: sect.jrs.volunteer( src, src.service ),
awards: sect.jrs.awards( src, src.recognition ),
publications: sect.jrs.publications( src, src.writing ),
interests: src.interests,
references: sect.jrs.references( src, src.testimonials ),
languages: src.languages
};
}
else { // Convert to the 1.0.0 candidate JSON Resume
return {
meta: sect.jrs.meta( src, src.meta ),
basics: sect.jrs.basics( src ),
work: sect.jrs.work( src, src.employment ),
education: sect.jrs.education( src, src.education ),
projects: sect.jrs.projects( src, src.projects ),
skills: sect.jrs.skills( src, src.skills ),
volunteer: sect.jrs.volunteer( src, src.service ),
awards: sect.jrs.awards( src, src.recognition ),
publications: sect.jrs.publications( src, src.writing ),
interests: src.interests,
references: sect.jrs.references( src, src.testimonials ),
languages: src.languages
};
}

},


Expand Down Expand Up @@ -144,3 +134,7 @@ FRESH to JSON Resume conversion routines.


}());

// [^1]: Ultimately, the converter will convert not just between FRESH and JRS,
// but between *different versions* of FRESH and JRS. That said, right now
// both FRESH and JRS versions are a little fuzzy.
8 changes: 4 additions & 4 deletions test/test-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ describe('CONVERT', function () {
return;
it( key + ' to JSON Resume format', function () {
expect(function() {
_rJ0 = CONVERTER.toJRS( val, null, "0" );
_rJ1 = CONVERTER.toJRS( val, null, "1" );
_rJ0 = CONVERTER.toJRS( val );
_rJ1 = CONVERTER.toJRS( val, { edge: true } );
_rF0 = CONVERTER.toFRESH( _rJ0 );
_rF1 = CONVERTER.toFRESH( _rJ1 );
}).to.not.throw();
Expand All @@ -80,8 +80,8 @@ describe('CONVERT', function () {
it( key + ' to FRESH format', function () {
expect(function() {
_rF0 = CONVERTER.toFRESH( val );
_rJ0 = CONVERTER.toJRS( _rF0, null, "0" );
_rJ1 = CONVERTER.toJRS( _rF0, null, "1" );
_rJ0 = CONVERTER.toJRS( _rF0 );
_rJ1 = CONVERTER.toJRS( _rF0, { edge: true } );
}).to.not.throw();

var isvf = freshValidator.isValid( _rF0 );
Expand Down

0 comments on commit c7a2ca9

Please sign in to comment.