Skip to content

Instantly share code, notes, and snippets.

@rkatic
Created July 1, 2010 04:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkatic/459570 to your computer and use it in GitHub Desktop.
Save rkatic/459570 to your computer and use it in GitHub Desktop.
jQuery.checkVersion
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';
};
@cowboy
Copy link

cowboy commented Jul 1, 2010

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

@rkatic
Copy link
Author

rkatic commented Jul 2, 2010

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.

@cowboy
Copy link

cowboy commented Jul 2, 2010

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