﻿(function () {
  'use strict';

  angular.module('exceptionless.semver', [])
    .directive('semver', function ($timeout) {
      return {
        restrict: 'A',
        scope: false,
        require: '?ngModel',
        link: function (scope, element, attrs, modelCtrl) {
          modelCtrl.$parsers.push(function (inputValue) {
            if (!inputValue) {
              return inputValue;
            }

            var r = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
            if (!r.test(inputValue)) {
              return inputValue;
            }

            // convert 4 part version to semver (1.2.3.4 to 1.2.3-4)
            var transformedInput = inputValue.replace(r, '$1.$2.$3-$4');
            if (transformedInput !== inputValue) {
              modelCtrl.$setViewValue(transformedInput);
              modelCtrl.$render();
            }
            return transformedInput;
          });
        }
      };
    });
}());

@@ -395,32 +395,44 @@
 ;%0A            %7D%0A
+            
 %0A            var
@@ -432,17 +432,17 @@
     var 
-r
+z
  = /%5E(%5Cd
@@ -456,28 +456,31 @@
 +)%5C.
+?
 (%5Cd+)
+?
 %5C.
+?
 (%5Cd
-+
 )
+?
 $/;%0A    
     
@@ -471,32 +471,57 @@
 %5Cd)?$/;%0A    
+   
+     var result = '';%0A
         
 if (!r.test(
@@ -512,14 +512,17 @@
     
+    
 if (
-!r
+z
 .tes
@@ -535,16 +535,28 @@
 tValue))
+%0A           
  %7B%0A     
@@ -568,110 +568,331 @@
     
-return inputValue;%0A            %7D%0A%0A            // convert 4 part version to semver (1.2.3.4 to 
+var z2 = /%5E(%5Cd+)%5C.(%5Cd+)$/;%0A              if (z2.test(inputValue))%0A                  result = inputValue.replace(z2, '$1.$2.0-0');%0A              else %0A              %7B%0A                var z3 = /%5E(%5Cd+)%5C.(%5Cd+)%5C.(%5Cd+)$/;%0A                if (z3.test(inputValue))%0A                    result = inputValue.replace(z3, '$
 1.
+$
 2.
+$
 3-
-4)
+0');
 %0A   
@@ -904,27 +904,146 @@
     
-var transformedInpu
+    else %7B%0A                  var z4 = /%5E(%5Cd+)%5C.(%5Cd+)%5C.(%5Cd+)%5C.(%5Cd+)$/;%0A                  if (z4.test(inputValue))%0A                    resul
 t = 
@@ -1061,17 +1061,18 @@
 replace(
-r
+z4
 , '$1.$2
@@ -1084,60 +1084,110 @@
 4');
-%0A            if (transformedInput !== inputValue) %7B%0A
+                %0A              %7D%0A                %0A              if (result !== '')%0A              %7B%0A   
     
@@ -1224,27 +1224,20 @@
 lue(
-transformedInpu
+resul
 t);%0A
+   
     
@@ -1271,33 +1271,110 @@
 ();%0A            
-%7D
+     return result;%0A              %7D              %0A            %7D%0A              
 %0A            ret
@@ -1381,24 +1381,18 @@
 urn 
-transformedInput
+inputValue
 ;%0A  

Update semver-directive.js