1// Generated by CoffeeScript 1.10.0 2(function() { 3 var $, Range, Trie, 4 indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; 5 6 Trie = (function() { 7 function Trie() { 8 this.trie = {}; 9 } 10 11 Trie.prototype.push = function(value) { 12 var char, i, j, len, obj, ref, results; 13 value = value.toString(); 14 obj = this.trie; 15 ref = value.split(''); 16 results = []; 17 for (i = j = 0, len = ref.length; j < len; i = ++j) { 18 char = ref[i]; 19 if (obj[char] == null) { 20 if (i === (value.length - 1)) { 21 obj[char] = null; 22 } else { 23 obj[char] = {}; 24 } 25 } 26 results.push(obj = obj[char]); 27 } 28 return results; 29 }; 30 31 Trie.prototype.find = function(value) { 32 var char, i, j, len, obj, ref; 33 value = value.toString(); 34 obj = this.trie; 35 ref = value.split(''); 36 for (i = j = 0, len = ref.length; j < len; i = ++j) { 37 char = ref[i]; 38 if (obj.hasOwnProperty(char)) { 39 if (obj[char] === null) { 40 return true; 41 } 42 } else { 43 return false; 44 } 45 obj = obj[char]; 46 } 47 }; 48 49 return Trie; 50 51 })(); 52 53 Range = (function() { 54 function Range(trie1) { 55 this.trie = trie1; 56 if (this.trie.constructor !== Trie) { 57 throw Error('Range constructor requires a Trie parameter'); 58 } 59 } 60 61 Range.rangeWithString = function(ranges) { 62 var j, k, len, n, r, range, ref, ref1, trie; 63 if (typeof ranges !== 'string') { 64 throw Error('rangeWithString requires a string parameter'); 65 } 66 ranges = ranges.replace(/ /g, ''); 67 ranges = ranges.split(','); 68 trie = new Trie; 69 for (j = 0, len = ranges.length; j < len; j++) { 70 range = ranges[j]; 71 if (r = range.match(/^(\d+)-(\d+)$/)) { 72 for (n = k = ref = r[1], ref1 = r[2]; ref <= ref1 ? k <= ref1 : k >= ref1; n = ref <= ref1 ? ++k : --k) { 73 trie.push(n); 74 } 75 } else if (range.match(/^\d+$/)) { 76 trie.push(range); 77 } else { 78 throw Error("Invalid range '" + r + "'"); 79 } 80 } 81 return new Range(trie); 82 }; 83 84 Range.prototype.match = function(number) { 85 return this.trie.find(number); 86 }; 87 88 return Range; 89 90 })(); 91 92 93 /* 94 jQuery Credit Card Validator 1.1 95 96 Copyright 2012-2015 Pawel Decowski 97 98 Permission is hereby granted, free of charge, to any person obtaining a copy 99 of this software and associated documentation files (the "Software"), to deal 100 in the Software without restriction, including without limitation the rights 101 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 102 copies of the Software, and to permit persons to whom the Software 103 is furnished to do so, subject to the following conditions: 104 105 The above copyright notice and this permission notice shall be included 106 in all copies or substantial portions of the Software. 107 108 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 109 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 110 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 111 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 112 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 113 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 114 IN THE SOFTWARE. 115 */ 116 117 $ = jQuery; 118 119 $.fn.validateCreditCard = function(callback, options) { 120 var bind, card, card_type, card_types, get_card_type, is_valid_length, is_valid_luhn, j, len, normalize, ref, validate, validate_number; 121 card_types = [ 122 { 123 name: 'amex', 124 range: '34,37', 125 valid_length: [15] 126 }, { 127 name: 'diners_club_carte_blanche', 128 range: '300-305', 129 valid_length: [14] 130 }, { 131 name: 'diners_club_international', 132 range: '36', 133 valid_length: [14] 134 }, { 135 name: 'jcb', 136 range: '3528-3589', 137 valid_length: [16] 138 }, { 139 name: 'laser', 140 range: '6304, 6706, 6709, 6771', 141 valid_length: [16, 17, 18, 19] 142 }, { 143 name: 'visa_electron', 144 range: '4026, 417500, 4508, 4844, 4913, 4917', 145 valid_length: [16] 146 }, { 147 name: 'visa', 148 range: '4', 149 valid_length: [13, 14, 15, 16, 17, 18, 19] 150 }, { 151 name: 'mastercard', 152 range: '51-55,2221-2720', 153 valid_length: [16] 154 }, { 155 name: 'discover', 156 range: '6011, 622126-622925, 644-649, 65', 157 valid_length: [16] 158 }, { 159 name: 'dankort', 160 range: '5019', 161 valid_length: [16] 162 }, { 163 name: 'maestro', 164 range: '50, 56-69', 165 valid_length: [12, 13, 14, 15, 16, 17, 18, 19] 166 }, { 167 name: 'uatp', 168 range: '1', 169 valid_length: [15] 170 } 171 ]; 172 bind = false;
173 if (callback) { 174 if (typeof callback === 'object') { 175 options = callback; 176 bind = false; 177 callback = null; 178 } else if (typeof callback === 'function') { 179 bind = true; 180 } 181 } 182 if (options == null) { 183 options = {}; 184 } 185 if (options.accept == null) { 186 options.accept = (function() { 187 var j, len, results; 188 results = []; 189 for (j = 0, len = card_types.length; j < len; j++) { 190 card = card_types[j]; 191 results.push(card.name); 192 } 193 return results; 194 })(); 195 } 196 ref = options.accept; 197 for (j = 0, len = ref.length; j < len; j++) { 198 card_type = ref[j]; 199 if (indexOf.call((function() { 200 var k, len1, results; 201 results = []; 202 for (k = 0, len1 = card_types.length; k < len1; k++) { 203 card = card_types[k]; 204 results.push(card.name); 205 } 206 return results; 207 })(), card_type) < 0) { 208 throw Error("Credit card type '" + card_type + "' is not supported"); 209 } 210 } 211 get_card_type = function(number) { 212 var k, len1, r, ref1; 213 ref1 = (function() { 214 var l, len1, ref1, results; 215 results = []; 216 for (l = 0, len1 = card_types.length; l < len1; l++) { 217 card = card_types[l]; 218 if (ref1 = card.name, indexOf.call(options.accept, ref1) >= 0) { 219 results.push(card); 220 } 221 } 222 return results; 223 })(); 224 for (k = 0, len1 = ref1.length; k < len1; k++) { 225 card_type = ref1[k]; 226 r = Range.rangeWithString(card_type.range); 227 if (r.match(number)) { 228 return card_type; 229 } 230 } 231 return null; 232 }; 233 is_valid_luhn = function(number) { 234 var digit, k, len1, n, ref1, sum; 235 sum = 0; 236 ref1 = number.split('').reverse(); 237 for (n = k = 0, len1 = ref1.length; k < len1; n = ++k) { 238 digit = ref1[n]; 239 digit = +digit; 240 if (n % 2) { 241 digit *= 2; 242 if (digit < 10) { 243 sum += digit; 244 } else { 245 sum += digit - 9; 246 } 247 } else { 248 sum += digit; 249 } 250 } 251 return sum % 10 === 0; 252 }; 253 is_valid_length = function(number, card_type) { 254 var ref1; 255 return ref1 = number.length, indexOf.call(card_type.valid_length, ref1) >= 0; 256 }; 257 validate_number = function(number) { 258 var length_valid, luhn_valid; 259 card_type = get_card_type(number); 260 luhn_valid = false; 261 length_valid = false; 262 if (card_type != null) { 263 luhn_valid = is_valid_luhn(number); 264 length_valid = is_valid_length(number, card_type); 265 } 266 return { 267 card_type: card_type, 268 valid: luhn_valid && length_valid, 269 luhn_valid: luhn_valid, 270 length_valid: length_valid 271 }; 272 }; 273 validate = (function(_this) { 274 return function() { 275 var number; 276 number = normalize($(_this).val()); 277 return validate_number(number); 278 }; 279 })(this); 280 normalize = function(number) { 281 return number.replace(/[ -]/g, ''); 282 }; 283 if (!bind) { 284 return validate(); 285 } 286 this.on('input.jccv', (function(_this) { 287 return function() { 288 $(_this).off('keyup.jccv'); 289 return callback.call(_this, validate()); 290 }; 291 })(this)); 292 this.on('keyup.jccv', (function(_this) { 293 return function() { 294 return callback.call(_this, validate()); 295 }; 296 })(this)); 297 callback.call(this, validate()); 298 return this; 299 }; 300 301}).call(this);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.