1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-05 09:56:22 +00:00

Add IIFE.

This commit is contained in:
hacksalot 2016-01-18 14:10:25 -05:00
parent 712cba57b8
commit c8d8e566f8

View File

@ -1,32 +1,37 @@
/** /**
The HackMyResume date representation. The HackMyResume date representation.
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk. @license MIT. See LICENSE.md for details.
@module fluent-date.js @module core/fluent-date
*/ */
var moment = require('moment'); (function(){
/** var moment = require('moment');
Create a FluentDate from a string or Moment date object. There are a few date
formats to be aware of here. /**
1. The words "Present" and "Now", referring to the current date Create a FluentDate from a string or Moment date object. There are a few date
2. The default "YYYY-MM-DD" format used in JSON Resume ("2015-02-10") formats to be aware of here.
3. Year-and-month only ("2015-04") 1. The words "Present" and "Now", referring to the current date
4. Year-only "YYYY" ("2015") 2. The default "YYYY-MM-DD" format used in JSON Resume ("2015-02-10")
5. The friendly HackMyResume "mmm YYYY" format ("Mar 2015" or "Dec 2008") 3. Year-and-month only ("2015-04")
6. Empty dates ("", " ") 4. Year-only "YYYY" ("2015")
7. Any other date format that Moment.js can parse from 5. The friendly HackMyResume "mmm YYYY" format ("Mar 2015" or "Dec 2008")
Note: Moment can transparently parse all or most of these, without requiring us 6. Empty dates ("", " ")
to specify a date format...but for maximum parsing safety and to avoid Moment 7. Any other date format that Moment.js can parse from
deprecation warnings, it's recommended to either a) explicitly specify the date Note: Moment can transparently parse all or most of these, without requiring us
format or b) use an ISO format. For clarity, we handle these cases explicitly. to specify a date format...but for maximum parsing safety and to avoid Moment
@class FluentDate deprecation warnings, it's recommended to either a) explicitly specify the date
*/ format or b) use an ISO format. For clarity, we handle these cases explicitly.
function FluentDate( dt ) { @class FluentDate
*/
function FluentDate( dt ) {
this.rep = this.fmt( dt ); this.rep = this.fmt( dt );
} }
FluentDate/*.prototype*/.fmt = function( dt, throws ) {
throws = (throws === undefined || throws === null) || throws;
FluentDate/*.prototype*/.fmt = function( dt ) {
if( (typeof dt === 'string' || dt instanceof String) ) { if( (typeof dt === 'string' || dt instanceof String) ) {
dt = dt.toLowerCase().trim(); dt = dt.toLowerCase().trim();
if( /^(present|now|current)$/.test(dt) ) { // "Present", "Now" if( /^(present|now|current)$/.test(dt) ) { // "Present", "Now"
@ -63,7 +68,9 @@ FluentDate/*.prototype*/.fmt = function( dt ) {
var mt = moment( dt ); var mt = moment( dt );
if(mt.isValid()) if(mt.isValid())
return mt; return mt;
if( throws )
throw 'Invalid date format encountered.'; throw 'Invalid date format encountered.';
return null;
} }
} }
else { else {
@ -72,13 +79,17 @@ FluentDate/*.prototype*/.fmt = function( dt ) {
} }
else if( dt.isValid && dt.isValid() ) else if( dt.isValid && dt.isValid() )
return dt; return dt;
if( throws )
throw 'Unknown date object encountered.'; throw 'Unknown date object encountered.';
return null;
} }
}; };
var months = {}, abbr = {}; var months = {}, abbr = {};
moment.months().forEach(function(m,idx){months[m.toLowerCase()]=idx+1;}); moment.months().forEach(function(m,idx){months[m.toLowerCase()]=idx+1;});
moment.monthsShort().forEach(function(m,idx){abbr[m.toLowerCase()]=idx+1;}); moment.monthsShort().forEach(function(m,idx){abbr[m.toLowerCase()]=idx+1;});
abbr.sept = 9; abbr.sept = 9;
module.exports = FluentDate; module.exports = FluentDate;
}());