PageSourceSearch

https://www.biotreino.com.br/js/validatorcard.js?id=53f72f27d2c7de2f73a919a6d6755819

js biotreino.com.br collected 2026-10-02 15:51:15 UTC 7,449 bytes, 270 lines download raw bytes

vendor: 6,390 bytes, lines 1-229
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  $ = jQuery;
93
94  $.fn.validateCreditCard = function(callback, options) {
95    var bind, card, card_type, card_types, get_card_type, is_valid_length, is_valid_luhn, j, len, normalize, ref, validate, validate_number;
96    card_types = [
97      {
98      name: 'elo',
99        range: '4011, 401178, 401179, 431274, 438935, 451416, 457393, 4576 , 457631, 457632, '+
100        ' 504175, 506699-506778, 509000-509999, '+
101        ' 627780, 636297, 636368, 636369, '+
102        ' 650031-650033, 650035-650051, 650405-650439, 650485-650538, 650541- 650598, 650700-650718, 650720-650727, 650901-650920, 651652-651679, 655000-655019, 655021-655058 ',
103        valid_length: [16]
104      },
105      {
106        name: 'amex',
107        range: '34,37',
108        valid_length: [15]
109      },
110      {
111        name: 'diners',
112        range: '300-305, 36-38',
113        valid_length: [14, 16]
114      },
115      {
116        name: 'hipercard',
117        range: '38,60',
118        valid_length: [13,16,19]
119      },
120      {
121        name: 'visa_electron',
122        range: '4026, 417500, 4508, 4844, 4913, 4917',
123        valid_length: [16]
124      },
125      {
126        name: 'visa',
127        range: '4',
128        valid_length: [13, 14, 15, 16, 17, 18, 19]
129      },
130      {
131        name: 'mastercard',
132        range: '51-55,2221-2720',
133        valid_length: [16]
134      },
135      {
136        name: 'maestro',
137        range: '50, 56-69',
138        valid_length: [12, 13, 14, 15, 16, 17, 18, 19]
139      }
140    ];
141    bind = false;
142    if (callback) {
143      if (typeof callback === 'object') {
144        options = callback;
145        bind = false;
146        callback = null;
147      } else if (typeof callback === 'function') {
148        bind = true;
149      }
150    }
151    if (options == null) {
152      options = {};
153    }
154    if (options.accept == null) {
155      options.accept = (function() {
156        var j, len, results;
157        results = [];
158        for (j = 0, len = card_types.length; j < len; j++) {
159          card = card_types[j];
160          results.push(card.name);
161        }
162        return results;
163      })();
164    }
165    ref = options.accept;
166    for (j = 0, len = ref.length; j < len; j++) {
167      card_type = ref[j];
168      if (indexOf.call((function() {
169        var k, len1, results;
170        results = [];
171        for (k = 0, len1 = card_types.length; k < len1; k++) {
172          card = card_types[k];
173          results.push(card.name);
174        }
175        return results;
176      })(), card_type) < 0) {
177        throw Error("Credit card type '" + card_type + "' is not supported");
178      }
179    }
180    get_card_type = function(number) {
181      var k, len1, r, ref1;
182      ref1 = (function() {
183        var l, len1, ref1, results;
184        results = [];
185        for (l = 0, len1 = card_types.length; l < len1; l++) {
186          card = card_types[l];
187          if (ref1 = card.name, indexOf.call(options.accept, ref1) >= 0) {
188            results.push(card);
189          }
190        }
191        return results;
192      })();
193      for (k = 0, len1 = ref1.length; k < len1; k++) {
194        card_type = ref1[k];
195        r = Range.rangeWithString(card_type.range);
196        if (r.match(number)) {
197          return card_type;
198        }
199      }
200      return null;
201    };
202    is_valid_luhn = function(number) {
203      var digit, k, len1, n, ref1, sum;
204      sum = 0;
205      ref1 = number.split('').reverse();
206      for (n = k = 0, len1 = ref1.length; k < len1; n = ++k) {
207        digit = ref1[n];
208        digit = +digit;
209        if (n % 2) {
210          digit *= 2;
211          if (digit < 10) {
212            sum += digit;
213          } else {
214            sum += digit - 9;
215          }
216        } else {
217          sum += digit;
218        }
219      }
220      return sum % 10 === 0;
221    };
222    is_valid_length = function(number, card_type) {
223      var ref1;
224      return ref1 = number.length, indexOf.call(card_type.valid_length, ref1) >= 0;
225    };
226    validate_number = function(number) {
227      var length_valid, luhn_valid;
228      card_type = get_card_type(number);
229      luhn_valid = false;
230      length_valid = false;
231      if (card_type != null) {
232        luhn_valid = is_valid_luhn(number);
233        length_valid = is_valid_length(number, card_type);
234      }
235      return {
236        card_type: card_type,
237        valid: luhn_valid && length_valid,
238        luhn_valid: luhn_valid,
239        length_valid: length_valid
240      };
241    };
242    validate = (function(_this) {
243      return function() {
244        var number;
245        number = normalize($(_this).val());
246        return validate_number(number);
247      };
248    })(this);
249    normalize = function(number) {
250      return number.replace(/[ -]/g, '');
251    };
252    if (!bind) {
253      return validate();
254    }
255    this.on('input.jccv', (function(_this) {
256      return function() {
257        $(_this).off('keyup.jccv');
258        return callback.call(_this, validate());
259      };
260    })(this));
261    this.on('keyup.jccv', (function(_this) {
262      return function() {
263        return callback.call(_this, validate());
264      };
265    })(this));
266    callback.call(this, validate());
267    return this;
268  };
269
270}).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.