Created
July 1, 2010 04:22
-
-
Save rkatic/459570 to your computer and use it in GitHub Desktop.
jQuery.checkVersion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.checkVersion = function( min, max ) { | |
var current = jQuery.fn.jquery + 'zz'; | |
max = ( max || min ) + 'zz'; | |
min += '0.0.0zz'.substr( min.length ); | |
return min <= current && current <= max; | |
}; | |
// This one will also handle 'pre' suffix as minor of 'alpha' and 'beta'. | |
jQuery.checkVersion = (function(){ | |
function norm( v, norm_length ) { | |
if ( norm_length ) { | |
v += '0.0.0'.substr( v.length ); | |
} | |
return v.replace(/p(re)?/, 'AA') + 'zz'; | |
} | |
var current = norm( jQuery.fn.jquery ); | |
return function( min, max ) { | |
return norm( min, true ) <= current && current <= norm( max || min ); | |
}; | |
})(); | |
// However, pre/alpha/beta versions would be used only for testing. Ignore them! | |
jQuery.checkVersion = function( min, max ) { | |
return min <= jQuery.fn.jquery && jQuery.fn.jquery <= ( max || min ) + 'z'; | |
}; |
Will this approach fail when testing that 1.4.9 is between 1.4.1 and 1.4.10?
Yes, it will, but I don't think it is an issue since 1.4.10 is not a valid jQuery version - or you are more informed then me.
Right now, there aren't any jQuery versions where a "part" is double-digits, so it doesn't matter. I was just thinking in terms of future-prrofing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will this approach fail when testing that 1.4.9 is between 1.4.1 and 1.4.10?
Either way, check out my take: http://gist.github.com/460275