| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
;(function($) { |
| 6 |
'use strict'; |
| 7 |
|
| 8 |
|
| 9 |
var named = { |
| 10 |
negative: [ 'negative', 'minus' ], |
| 11 |
numbers : { |
| 12 |
'zero' : 0, |
| 13 |
'one' : 1, |
| 14 |
'two' : 2, |
| 15 |
'three' : 3, |
| 16 |
'four' : 4, |
| 17 |
'five' : 5, |
| 18 |
'six' : 6, |
| 19 |
'seven' : 7, |
| 20 |
'eight' : 8, |
| 21 |
'nine' : 9, |
| 22 |
'ten' : 10, |
| 23 |
'eleven' : 11, |
| 24 |
'twelve' : 12, |
| 25 |
'thirteen' : 13, |
| 26 |
'fourteen' : 14, |
| 27 |
'fifteen' : 15, |
| 28 |
'sixteen' : 16, |
| 29 |
'seventeen' : 17, |
| 30 |
'eighteen' : 18, |
| 31 |
'nineteen' : 19, |
| 32 |
'twenty' : 20, |
| 33 |
'thirty' : 30, |
| 34 |
'forty' : 40, |
| 35 |
'fourty' : 40, |
| 36 |
'fifty' : 50, |
| 37 |
'sixty' : 60, |
| 38 |
'seventy' : 70, |
| 39 |
'eighty' : 80, |
| 40 |
'ninety' : 90 |
| 41 |
}, |
| 42 |
|
| 43 |
hundred : 'hundred', |
| 44 |
|
| 45 |
powers : { |
| 46 |
'thousand' : 1e3, |
| 47 |
'million' : 1e6, |
| 48 |
'billion' : 1e9, |
| 49 |
'trillion' : 1e12, |
| 50 |
'quadrillion' : 1e15, |
| 51 |
'quintillion' : 1e18, |
| 52 |
'sextillion' : 1e21, |
| 53 |
'septillion' : 1e24, |
| 54 |
'octillion' : 1e27, |
| 55 |
'nonillion' : 1e30, |
| 56 |
'decillion' : 1e33, |
| 57 |
'undecillion' : 1e36, |
| 58 |
'duodecillion' : 1e39, |
| 59 |
'tredecillion' : 1e42, |
| 60 |
'quattuordecillion' : 1e45, |
| 61 |
'quindecillion' : 1e48, |
| 62 |
'sexdecillion' : 1e51, |
| 63 |
'septendecillion' : 1e54, |
| 64 |
'octodecillion' : 1e57, |
| 65 |
'novemdecillion' : 1e60, |
| 66 |
'vigintillion' : 1e63, |
| 67 |
'unvigintillion' : 1e66, |
| 68 |
'duovigintillion' : 1e69, |
| 69 |
'trevigintillion' : 1e72, |
| 70 |
'quattuorvigintillion' : 1e75, |
| 71 |
'quinvigintillion' : 1e78, |
| 72 |
'sexvigintillion' : 1e81, |
| 73 |
'septenvigintillion' : 1e84, |
| 74 |
'octovigintillion' : 1e87, |
| 75 |
'novemvigintillion' : 1e90, |
| 76 |
'trigintillion' : 1e93, |
| 77 |
'untrigintillion' : 1e96, |
| 78 |
'duotrigintillion' : 1e99, |
| 79 |
'googl' : 1e100 |
| 80 |
} |
| 81 |
}, |
| 82 |
result, group, |
| 83 |
negativeRegex = new RegExp('(' + named.negative.join('|') + ')'), |
| 84 |
calc = function ( rawWord, table ) { |
| 85 |
|
| 86 |
var word = rawWord.replace( /[,."']/g, '' ), |
| 87 |
|
| 88 |
num = $.tablesorter.formatFloat( rawWord || '', table ), |
| 89 |
power = named.powers.hasOwnProperty( word ) ? named.powers[ word ] : null; |
| 90 |
num = typeof num === 'number' ? num : named.numbers.hasOwnProperty( word ) ? named.numbers[ word ] : null; |
| 91 |
if ( num !== null ) { |
| 92 |
group += num; |
| 93 |
} else if ( word === named.hundred ) { |
| 94 |
group *= 100; |
| 95 |
} else if ( power !== null ) { |
| 96 |
result += group * power; |
| 97 |
group = 0; |
| 98 |
} |
| 99 |
}; |
| 100 |
|
| 101 |
$.tablesorter.addParser({ |
| 102 |
id: 'namedNumbers', |
| 103 |
is: function () { |
| 104 |
return false; |
| 105 |
}, |
| 106 |
format: function ( str, table ) { |
| 107 |
result = 0; |
| 108 |
group = 0; |
| 109 |
var indx, |
| 110 |
arry = ( str || '' ).split( /[\s-]+/ ), |
| 111 |
len = arry.length; |
| 112 |
for ( indx = 0; indx < len; indx++ ) { |
| 113 |
calc( arry[ indx ].toLowerCase(), table ); |
| 114 |
} |
| 115 |
result = ( result + group ) * ( str.match( negativeRegex ) ? -1 : 1 ); |
| 116 |
|
| 117 |
return result || named.numbers.hasOwnProperty( str ) ? result : $.tablesorter.formatFloat( str || '', table ); |
| 118 |
}, |
| 119 |
type: 'numeric' |
| 120 |
}); |
| 121 |
|
| 122 |
})( jQuery ); |