Code coverage report for natural-compare-lite/natural-compare.js

Statements: 100% (13 / 13)      Branches: 100% (20 / 20)      Functions: 100% (1 / 1)      Lines: 100% (11 / 11)     

All files » natural-compare-lite/ » natural-compare.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32                      1   48 107 107   107 26 26 26 26     107   7          
 
 
 
/*
* @version  0.4.4
* @author   Lauri Rooden - https://github.com/litejs/natural-compare-lite
* @license  MIT License  - http://lauri.rooden.ee/mit-license.txt
*/
 
 
 
String.naturalCompare = function(a, b) {
 
	if (a != b) for (var i, ca, cb = 1, ia = 0, ib = 0; cb;) {
		ca = a.charCodeAt(ia++) || 0
		cb = b.charCodeAt(ib++) || 0
 
		if (ca < 58 && ca > 47 && cb < 58 && cb > 47) {
			for (i = ia; ca = a.charCodeAt(ia), ca < 58 && ca > 47; ia++);
			ca = (a.slice(i - 1, ia) | 0) + 1
			for (i = ib; cb = b.charCodeAt(ib), cb < 58 && cb > 47; ib++);
			cb = (b.slice(i - 1, ib) | 0) + 1
		}
 
		if (ca != cb) return (ca < cb) ? -1 : 1
	}
	return 0
}