1(function() { 2 var PostalCode; 3 4 PostalCode = (function() { 5 function PostalCode(first, second) { 6 this.valid = false; 7 this.first = this.second = null; 8 try { 9 if (first && second) { 10 this.first = parseInt(first); 11 this.second = parseInt(second); 12 this.valid = true; 13 } else if (first) { 14 if (first.match(/^([0-9]{3})([0-9]{4})$/) || first.match(/^([0-9]{3})\-([0-9]{4})$/)) { 15 this.first = parseInt(RegExp.$1); 16 this.second = parseInt(RegExp.$2); 17 this.valid = true; 18 } 19 } 20 } catch (_error) {} 21 } 22 23 PostalCode.prototype.invalid = function() { 24 return !this.valid; 25 }; 26 27 PostalCode.prototype.lpad0 = function(str, length) { 28 while (str.length < length) { 29 str = '0' + str; 30 } 31 return str; 32 }; 33 34 PostalCode.prototype.first0 = function() { 35 return this.lpad0(this.first, 3); 36 }; 37 38 PostalCode.prototype.second0 = function() { 39 return this.lpad0(this.second, 4); 40 }; 41 42 PostalCode.prototype.digits7 = function() { 43 return this.first0() + '-' + this.second0(); 44 }; 45 46 PostalCode.prototype.with_hyphen = function() { 47 return this.first0() + this.second0(); 48 }; 49 50 return PostalCode; 51 52 })(); 53 54 $.postalChecker = { 55 compile: function(text, options) { 56 var defaults, lines, opts, results; 57 defaults = { 58 value: true 59 }; 60 opts = $.extend(defaults, options); 61 lines = text.split(/\n/); 62 results = {}; 63 $.each(lines, function(num, line) { 64 var p; 65 line = line.replace(/^\s+/, ''); 66 line = line.replace(/\s+$/, ''); 67 p = new PostalCode(line); 68 if (p.invalid()) { 69 return true; 70 } 71 if (results[p.first] == null) { 72 results[p.first] = []; 73 } 74 return results[p.first].push(p.second); 75 }); 76 if (opts.deploy) { 77 $.each(results, function(first, seconds) { 78 return results[first] = JSON.stringify(seconds); 79 }); 80 } 81 return results; 82 }, 83 _checkCodeWithJson: function(postalCode, json) { 84 var res, second, seconds; 85 if ((json != null) && (json[postalCode.first] != null)) { 86 second = postalCode.second; 87 seconds = json[postalCode.first]; 88 if (typeof seconds === 'string') { 89 seconds = json[postalCode.first] = $.parseJSON(seconds); 90 } 91 if (seconds instanceof Array) { 92 res = false; 93 $.each(seconds, function(i, v) { 94 if (v === second) { 95 res = true; 96 return false; 97 } 98 }); 99 return res; 100 } else if (seconds instanceof Object) { 101 if (seconds[second] != null) { 102 return true; 103 } 104 } 105 } 106 return false; 107 }, 108 _behaveResult: function(postalCode, result, options) { 109 if (result === true && options.done) { 110 options.done(postalCode); 111 } else if (result === false && options.fail) { 112 options.fail(postalCode); 113 } 114 if (options.always) { 115 return options.always(postalCode); 116 } 117 }, 118 _checkCode: function(postalCode, options) { 119 var defaults, json, ns, opts, result; 120 defaults = {}; 121 opts = $.extend(defaults, options); 122 result = null; 123 ns = $.postalChecker; 124 if (opts.json_data != null) { 125 result = ns._checkCodeWithJson(postalCode, opts.json_data); 126 ns._behaveResult(postalCode, result, opts); 127 return; 128 } 129 if (opts.json_url != null) { 130 opts.json_ajax = $.extend(opts.json_ajax, { 131 url: opts.json_url 132 }); 133 delete opts.json_url; 134 } 135 if (opts.json_ajax != null) { 136 $.ajax(opts.json_ajax).done(function(json) { 137 if (typeof json === 'string') { 138 json = $.parseJSON(json); 139 } 140 result = ns._checkCodeWithJson(postalCode, json); 141 return ns._behaveResult(postalCode, result, opts); 142 }); 143 return; 144 } 145 if (opts.text_data != null) { 146 json = ns.compile(opts.text_data, opts); 147 result = ns._checkCodeWithJson(postalCode, json); 148 ns._behaveResult(postalCode, result, opts); 149 return; 150 } 151 if (opts.text_url != null) { 152 opts.text_ajax = $.extend(opts.text_ajax, { 153 url: opts.text_url 154 }); 155 delete opts.text_url; 156 } 157 if (opts.text_ajax != null) { 158 $.ajax(opts.text_ajax).done(function(text) { 159 if (typeof json !== 'string') { 160 text = text.toString(); 161 } 162 json = ns.compile(text, opts); 163 result = ns._checkCodeWithJson(postalCode, json); 164 return ns._behaveResult(postalCode, result, opts); 165 }); 166 } 167 }, 168 check1: function(code, options) { 169 var p; 170 p = new PostalCode(code); 171 return $.postalChecker._checkCode(p, options); 172 }, 173 check2: function(first, second, options) { 174 var p; 175 p = new PostalCode(first, second); 176 return $.postalChecker._checkCode(p, options); 177 } 178 }; 179 180}).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.