var moment = require('moment');
var defaultFormat = 'YYYY';

module.exports = {
  /**
  * Return Formatted date via moment.js
  */
  date: function(str, format, meridiem) {
    var meridiemRegEx = new RegExp('(a{1,2}|p)\.?m{1}?\.?', 'i');

    if (str !== undefined) {
      if (!meridiem) {
        return moment(str).format(format);
      }
      else {
        return moment(str).format(format).replace(meridiemRegEx, "$1.m.");
      }
    }
  },

  /**
  * Set user-specified default format for date
  */
  setDefaultFormat: function(format) {
    defaultFormat = format;
    return defaultFormat;
  },
  
  /**
  * Add filter to nunjucks environment
  */
  install: function(env, customName) {
    env.addFilter(customName || 'date', function(str, format, meridiem) {
      return date(str, format, meridiem);
    });
  }
};
@@ -29,216 +29,217 @@
 ');%0A
-var defaultFormat = 'YYYY';%0A%0Amodule.exports = %7B%0A  /**%0A  * Return Formatted date via moment.js%0A  */%0A  date: function(str, format, meridiem) %7B%0A    var meridiemRegEx = new RegExp('(a%7B1,2%7D%7Cp)%5C.?m%7B1%7D?%5C.?', 'i');%0A%0A
+%0Avar meridiemRegEx = new RegExp('(a%7B1,2%7D%7Cp)%5C.?m%7B1%7D?%5C.?', 'i');%0Avar defaultFormat = 'YYYY';%0A%0A%0Afunction getFilter(format) %7B%0A    format = format %7C%7C defaultFormat;%0A    return function(str, format, meridiem) %7B%0A    
     
@@ -259,24 +259,30 @@
 ndefined) %7B%0A
+      
       if (!m
@@ -292,32 +292,40 @@
 diem) %7B%0A        
+      
+  
 return moment(st
@@ -353,23 +353,23 @@
     
-%7D%0A
      
+ %7D
  else %7B%0A
     
@@ -364,16 +364,24 @@
  else %7B%0A
+        
         
@@ -457,29 +457,71 @@
     
+ 
-%7D%0A
+     %7D%0A  
     
+  
 %7D%0A  
-%7D,%0A%0A  
+  %7D;%0A%7D%0A%0Amodule.exports = getFilter();%0A%0A
 /**%0A
- 
  * S
@@ -562,23 +562,35 @@
 or date%0A
- 
  */%0A
-  
+module.exports.
 setDefau
@@ -597,17 +597,18 @@
 ltFormat
-:
+ =
  functio
@@ -623,16 +623,23 @@
 ) %7B%0A    
+return 
 defaultF
@@ -658,49 +658,17 @@
 at;%0A
-    return defaultFormat;%0A  %7D,%0A  %0A  
+%7D;%0A%0A%0A
 /**%0A
- 
  * A
@@ -705,23 +705,36 @@
 ent%0A
- 
  */%0A
-  
+module.exports.
 install
-:
+ =
  fun
@@ -802,94 +802,21 @@
 e', 
-function(str, format, meridiem) %7B%0A      return date(str, format, meridiem);%0A    %7D);%0A  %7D%0A%7D;
+getFilter());%0A%7D;%0A

Reformat plugin