1'use strict'; 2 3var tggh = {}; 4 5( function() { 6 // Utilities 7 // --------- 8 9 tggh.as_int = function( value, min, max ) { 10 var int = parseInt( value, 10 ); 11 int = isNaN( int ) ? 0 : int; 12 13 if ( typeof min === 'number' ) { 14 int = int < min ? min : int; 15 } 16 17 if ( typeof max === 'number' ) { 18 int = int > max ? max : int; 19 } 20 21 return int; 22 }; 23 24 tggh.is_array = function( value ) { 25 return Array.isArray( value ); 26 }; 27 28 tggh.is_non_empty_array = function( value ) { 29 return tggh.is_array( value ) && value.length > 0; 30 }; 31 32 tggh.as_array = function( value ) { 33 return tggh.is_array( value ) ? value : []; 34 }; 35 36 tggh.is_object = function( value ) { 37 return typeof value === 'object' && value !== null; 38 }; 39 40 // Random 41 // ------ 42 43 var re_word_unsafe = new RegExp( 44 '(?:' + 45 'a(?:n(?:al|us)|s[sn]|rs[ckq])|' + 46 'b(?:ang|dsm|oob|one|utt|i?mbo?|onz|ugr|ite|ord)|' + 47 'c(?:[oa][ckqn]{1,2}[oa]?|o[qn]|ovi|u[mln]t?|hu[jp]|urv|ulo|hat|lit)|' + 48 'd(?:[ie]?[ckq]{2}|[iy][ckq]e)|' + 49 'f(?:ag|[ei][ckq][ae]?|ist|[uickq][ckq]{1,2}|uq|o(?:tz|ll|ut)|rat)|' + 50 'ga[ye]|' + 51 'h(?:oo[ckq]|o[rv]n|ump|ack|ero|ij[ao])|' + 52 'j(?:a?[ckq]{2}|er[ckq]|ug|eba)|' + 53 'k(?:[oa][ckq][oe]|ono?|urv|a[ckq]{2})|' + 54 'l(?:e(?:sb|z)|ort)|gbt|' + 55 'm(?:ilf|org|op?se?|u(?:ft|sc|na)|e?rd)|' + 56 'n(?:[ie]gg?[er]|ip|ud|[yi]m[pf]|a[ckq]{2}|utt?|azi)|' + 57 'o(?:rg[ya]|var|rin)|' + 58 'p(?:a[ckq]i|e?n?[iu]ss?|ipi|i?[zs]d|o(?:o|rn)|op[pe]|e(?:[dz]o|rv)|u[tl][aei])|' + 59 'que|' + 60 'r(?:ap[ei]|e[ckq]t)|' + 61 's(?:[ckqr]at|ex|h[ie]?t|[lm]u?t|u[ckq]{1,2}|[ckq]{2}|ra[ct]|uli|eme|[mn]a[ckq]|a?lop?|u[ckq]e)|' + 62 't(?:it|ra[nv]|wa?t|rio)|' + 63 'ure|' + 64 'v(?:i?ag|er?g|o[yg]e|u?lv)|' + 65 'w(?:an[ckq]|hor|ich)|' + 66 'z(?:mrd|rat|izi)|' + 67 '666' + 68 ')', 'i' 69 ); 70 71 var alpha_upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; 72 var alpha_lower = 'abcdefghijklmnopqrstuvwxyz'; 73 var alpha_mixed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; 74 var alnum_upper = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; 75 var alnum_lower = '0123456789abcdefghijklmnopqrstuvwxyz'; 76 var alnum_mixed = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; 77 var digits = '0123456789'; 78 var d_digits = '23456789'; 79 var d_alpha_upper = 'ABCDEFGHJKLMNPQRSTUVWXYZ'; 80 var d_alpha_lower = 'abcdefghjkmnpqrstuvwxyz'; 81 var d_alpha_mixed = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz'; 82 var d_alnum_upper = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ'; 83 var d_alnum_lower = '23456789abcdefghjkmnpqrstuvwxyz'; 84 var d_alnum_mixed = '23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz'; 85 var hex_upper = '0123456789ABCDEF'; 86 var hex_lower = '0123456789abcdef'; 87 88 var c_alpha_upper = 26; 89 var c_alpha_lower = 26; 90 var c_alpha_mixed = 52; 91 var c_alnum_upper = 36; 92 var c_alnum_lower = 36; 93 var c_alnum_mixed = 62; 94 var c_digits = 10; 95 var c_d_digits = 8; 96 var c_d_alpha_upper = 24; 97 var c_d_alpha_lower = 23; 98 var c_d_alpha_mixed = 47; 99 var c_d_alnum_upper = 32; 100 var c_d_alnum_lower = 31; 101 var c_d_alnum_mixed = 55; 102 var c_hex_upper = 16; 103 var c_hex_lower = 16; 104 105 tggh.generate_random_id = function( format, _iter ) { 106 var result = ''; 107 var str = ''; 108 109 var parse = true; 110 for ( var i = 0, n = 0, len = format.length; i < len; ++i, n = 0 ) { 111 var f = format[i]; 112 113 if ( ! parse ) { 114 result += f; 115 str += f; 116 parse = true; 117 continue; 118 } 119 120 if ( f === '\\' ) { 121 parse = false;
122 continue; 123 } 124 125 var c = ''; 126 127 switch ( f ) { 128 case 'A': c = alpha_upper; n = c_alpha_upper; break; 129 case 'a': c = alpha_lower; n = c_alpha_lower; break; 130 case 'B': c = alpha_mixed; n = c_alpha_mixed; break; 131 case 'C': c = alnum_upper; n = c_alnum_upper; break; 132 case 'c': c = alnum_lower; n = c_alnum_lower; break; 133 case 'D': c = alnum_mixed; n = c_alnum_mixed; break; 134 case 'N': c = digits; n = c_digits; break; 135 case 'M': c = d_digits; n = c_d_digits; break; 136 case 'P': c = d_alpha_upper; n = c_d_alpha_upper; break; 137 case 'p': c = d_alpha_lower; n = c_d_alpha_lower; break; 138 case 'Q': c = d_alpha_mixed; n = c_d_alpha_mixed; break; 139 case 'I': c = d_alnum_upper; n = c_d_alnum_upper; break; 140 case 'i': c = d_alnum_lower; n = c_d_alnum_lower; break; 141 case 'J': c = d_alnum_mixed; n = c_d_alnum_mixed; break; 142 case 'X': c = hex_upper; n = c_hex_upper; break; 143 case 'x': c = hex_lower; n = c_hex_lower; break; 144 } 145 146 c = n > 0 ? c[tggh.random_int( 0, n - 1 )] : f; 147 148 if ( c.match( /[a-zA-Z0-9]/ ) ) { 149 str += c; 150 } 151 152 result += c; 153 } 154 155 var iteration = _iter || 0; 156 157 if ( iteration < 20 && str.match( re_word_unsafe ) ) { 158 result = tggh.generate_random_id( format, iteration + 1 ); 159 } 160 161 return result; 162 }; 163 164 tggh.count_random_id_possibilities = function( format ) { 165 var count = 1; 166 var parse = true; 167 var len = format.length; 168 var i; 169 170 for ( i = 0; i < len; ++i ) { 171 var f = format[i]; 172 173 if ( ! parse ) { parse = true; continue; } 174 if ( f === '\\' ) { parse = false; continue; } 175 176 switch ( f ) { 177 case 'A': count *= c_alpha_upper; break; 178 case 'a': count *= c_alpha_lower; break; 179 case 'B': count *= c_alpha_mixed; break; 180 case 'C': count *= c_alnum_upper; break; 181 case 'c': count *= c_alnum_lower; break; 182 case 'D': count *= c_alnum_mixed; break; 183 case 'N': count *= c_digits; break; 184 case 'M': count *= c_d_digits; break; 185 case 'P': count *= c_d_alpha_upper; break; 186 case 'p': count *= c_d_alpha_lower; break; 187 case 'Q': count *= c_d_alpha_mixed; break; 188 case 'I': count *= c_d_alnum_upper; break; 189 case 'i': count *= c_d_alnum_lower; break; 190 case 'J': count *= c_d_alnum_mixed; break; 191 case 'X': count *= c_hex_upper; break; 192 case 'x': count *= c_hex_lower; break; 193 } 194 } 195 196 return count; 197 }; 198 199 tggh.random_int = function( min, max ) { 200 min = Math.ceil( min ); 201 max = Math.floor( max ); 202 return Math.floor( Math.random() * ( max - min + 1 ) ) + min; 203 }; 204 205 tggh.short_random = function() { 206 return ( 207 tggh.generate_random_id( 'B' ) + 208 Math.random().toString(36).slice(2) 209 ); 210 }; 211 212 tggh.new_id = function( prefix ) { 213 return ( 214 'tggh_' + ( prefix ? ( prefix + '_' ) : '' ) + 215 tggh.short_random() 216 ); 217 }; 218 219 // Dates 220 // ----- 221 222 tggh.day_index = { 223 sun: 0, mon: 1, tue: 2, wed: 3, thu: 4, fri: 5, sat: 6 224 }; 225 226 // Fields 227 // ------ 228 229 tggh.gform_property = function( name ) { 230 return 'tggh_' + name; 231 }; 232 233 234 // Hooks 235 // ----- 236 237 tggh.hooks = { filters: {}, actions: {} }; 238 239 tggh.get_hooks = function( type, tag ) { 240 if ( ! tggh.hooks[type][tag] ) { 241 tggh.hooks[type][tag] = []; 242 } 243 return tggh.hooks[type][tag]; 244 }; 245 246 tggh.apply_filters = function( tag, data, args ) { 247 tggh.get_hooks( 'filters', tag ).forEach( function( fn ) { 248 data = fn.apply( this, [data].concat(args) ); 249 } ); 250 251 return data; 252 }; 253 254 tggh.add_filter = function( tag, fn ) { 255 tggh.get_hooks( 'filters', tag ).push( fn ); 256 }; 257 258 tggh.do_action = function( tag, args ) { 259 tggh.get_hooks( 'actions', tag ).forEach( function( fn ) { 260 fn.apply( this, args ); 261 } ); 262 }; 263 264 tggh.add_action = function( tag, fn ) { 265 tggh.get_hooks( 'actions', tag ).push( fn ); 266 }; 267 268 tggh.has_action = function( tag ) { 269 var actions = tggh.hooks.actions[tag]; 270 271 return tggh.is_array( actions ) && actions.length > 0; 272 }; 273} )();
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.