Best JavaScript code snippet using devicefarmer-stf
additional-methods.js
Source:additional-methods.js
...41 // Element is optional42 if (optionalValue) {43 return optionalValue;44 }45 if ($(element).attr("type") === "file") {46 // If we are using a wildcard, make it regex friendly47 typeParam = typeParam.replace(/\*/g, ".*");48 // Check if the element has a FileList before checking each file49 if (element.files && element.files.length) {50 for (i = 0; i < element.files.length; i++) {51 file = element.files[i];52 // Grab the mimetype from the loaded file, verify it matches53 if (!file.type.match(new RegExp( "\\.?(" + typeParam + ")$", "i"))) {54 return false;55 }56 }57 }58 }59 // Either return true because we've validated each file, or because the60 // browser does not support element.files and the FileList feature61 return true;62}, $.validator.format("Please enter a value with a valid mimetype."));63$.validator.addMethod("alphanumeric", function(value, element) {64 return this.optional(element) || /^\w+$/i.test(value);65}, "Letters, numbers, and underscores only please");66/*67 * Dutch bank account numbers (not 'giro' numbers) have 9 digits68 * and pass the '11 check'.69 * We accept the notation with spaces, as that is common.70 * acceptable: 123456789 or 12 34 56 78971 */72$.validator.addMethod("bankaccountNL", function(value, element) {73 if (this.optional(element)) {74 return true;75 }76 if (!(/^[0-9]{9}|([0-9]{2} ){3}[0-9]{3}$/.test(value))) {77 return false;78 }79 // now '11 check'80 var account = value.replace(/ /g, ""), // remove spaces81 sum = 0,82 len = account.length,83 pos, factor, digit;84 for ( pos = 0; pos < len; pos++ ) {85 factor = len - pos;86 digit = account.substring(pos, pos + 1);87 sum = sum + factor * digit;88 }89 return sum % 11 === 0;90}, "Please specify a valid bank account number");91$.validator.addMethod("bankorgiroaccountNL", function(value, element) {92 return this.optional(element) ||93 ($.validator.methods.bankaccountNL.call(this, value, element)) ||94 ($.validator.methods.giroaccountNL.call(this, value, element));95}, "Please specify a valid bank or giro account number");96/**97 * BIC is the business identifier code (ISO 9362). This BIC check is not a guarantee for authenticity.98 *99 * BIC pattern: BBBBCCLLbbb (8 or 11 characters long; bbb is optional)100 *101 * BIC definition in detail:102 * - First 4 characters - bank code (only letters)103 * - Next 2 characters - ISO 3166-1 alpha-2 country code (only letters)104 * - Next 2 characters - location code (letters and digits)105 * a. shall not start with '0' or '1'106 * b. second character must be a letter ('O' is not allowed) or one of the following digits ('0' for test (therefore not allowed), '1' for passive participant and '2' for active participant)107 * - Last 3 characters - branch code, optional (shall not start with 'X' except in case of 'XXX' for primary office) (letters and digits)108 */109$.validator.addMethod("bic", function(value, element) {110 return this.optional( element ) || /^([A-Z]{6}[A-Z2-9][A-NP-Z1-2])(X{3}|[A-WY-Z0-9][A-Z0-9]{2})?$/.test( value );111}, "Please specify a valid BIC code");112/*113 * Código de identificación fiscal ( CIF ) is the tax identification code for Spanish legal entities114 * Further rules can be found in Spanish on http://es.wikipedia.org/wiki/C%C3%B3digo_de_identificaci%C3%B3n_fiscal115 */116$.validator.addMethod( "cifES", function( value ) {117 "use strict";118 var num = [],119 controlDigit, sum, i, count, tmp, secondDigit;120 value = value.toUpperCase();121 // Quick format test122 if ( !value.match( "((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)" ) ) {123 return false;124 }125 for ( i = 0; i < 9; i++ ) {126 num[ i ] = parseInt( value.charAt( i ), 10 );127 }128 // Algorithm for checking CIF codes129 sum = num[ 2 ] + num[ 4 ] + num[ 6 ];130 for ( count = 1; count < 8; count += 2 ) {131 tmp = ( 2 * num[ count ] ).toString();132 secondDigit = tmp.charAt( 1 );133 sum += parseInt( tmp.charAt( 0 ), 10 ) + ( secondDigit === "" ? 0 : parseInt( secondDigit, 10 ) );134 }135 /* The first (position 1) is a letter following the following criteria:136 * A. Corporations137 * B. LLCs138 * C. General partnerships139 * D. Companies limited partnerships140 * E. Communities of goods141 * F. Cooperative Societies142 * G. Associations143 * H. Communities of homeowners in horizontal property regime144 * J. Civil Societies145 * K. Old format146 * L. Old format147 * M. Old format148 * N. Nonresident entities149 * P. Local authorities150 * Q. Autonomous bodies, state or not, and the like, and congregations and religious institutions151 * R. Congregations and religious institutions (since 2008 ORDER EHA/451/2008)152 * S. Organs of State Administration and regions153 * V. Agrarian Transformation154 * W. Permanent establishments of non-resident in Spain155 */156 if ( /^[ABCDEFGHJNPQRSUVW]{1}/.test( value ) ) {157 sum += "";158 controlDigit = 10 - parseInt( sum.charAt( sum.length - 1 ), 10 );159 value += controlDigit;160 return ( num[ 8 ].toString() === String.fromCharCode( 64 + controlDigit ) || num[ 8 ].toString() === value.charAt( value.length - 1 ) );161 }162 return false;163}, "Please specify a valid CIF number." );164/*165 * Brazillian CPF number (Cadastrado de Pessoas FÃsicas) is the equivalent of a Brazilian tax registration number.166 * CPF numbers have 11 digits in total: 9 numbers followed by 2 check numbers that are being used for validation.167 */168$.validator.addMethod("cpfBR", function(value) {169 // Removing special characters from value170 value = value.replace(/([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "");171 // Checking value to have 11 digits only172 if (value.length !== 11) {173 return false;174 }175 var sum = 0,176 firstCN, secondCN, checkResult, i;177 firstCN = parseInt(value.substring(9, 10), 10);178 secondCN = parseInt(value.substring(10, 11), 10);179 checkResult = function(sum, cn) {180 var result = (sum * 10) % 11;181 if ((result === 10) || (result === 11)) {result = 0;}182 return (result === cn);183 };184 // Checking for dump data185 if (value === "" ||186 value === "00000000000" ||187 value === "11111111111" ||188 value === "22222222222" ||189 value === "33333333333" ||190 value === "44444444444" ||191 value === "55555555555" ||192 value === "66666666666" ||193 value === "77777777777" ||194 value === "88888888888" ||195 value === "99999999999"196 ) {197 return false;198 }199 // Step 1 - using first Check Number:200 for ( i = 1; i <= 9; i++ ) {201 sum = sum + parseInt(value.substring(i - 1, i), 10) * (11 - i);202 }203 // If first Check Number (CN) is valid, move to Step 2 - using second Check Number:204 if ( checkResult(sum, firstCN) ) {205 sum = 0;206 for ( i = 1; i <= 10; i++ ) {207 sum = sum + parseInt(value.substring(i - 1, i), 10) * (12 - i);208 }209 return checkResult(sum, secondCN);210 }211 return false;212}, "Please specify a valid CPF number");213/* NOTICE: Modified version of Castle.Components.Validator.CreditCardValidator214 * Redistributed under the the Apache License 2.0 at http://www.apache.org/licenses/LICENSE-2.0215 * Valid Types: mastercard, visa, amex, dinersclub, enroute, discover, jcb, unknown, all (overrides all other settings)216 */217$.validator.addMethod("creditcardtypes", function(value, element, param) {218 if (/[^0-9\-]+/.test(value)) {219 return false;220 }221 value = value.replace(/\D/g, "");222 var validTypes = 0x0000;223 if (param.mastercard) {224 validTypes |= 0x0001;225 }226 if (param.visa) {227 validTypes |= 0x0002;228 }229 if (param.amex) {230 validTypes |= 0x0004;231 }232 if (param.dinersclub) {233 validTypes |= 0x0008;234 }235 if (param.enroute) {236 validTypes |= 0x0010;237 }238 if (param.discover) {239 validTypes |= 0x0020;240 }241 if (param.jcb) {242 validTypes |= 0x0040;243 }244 if (param.unknown) {245 validTypes |= 0x0080;246 }247 if (param.all) {248 validTypes = 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080;249 }250 if (validTypes & 0x0001 && /^(5[12345])/.test(value)) { //mastercard251 return value.length === 16;252 }253 if (validTypes & 0x0002 && /^(4)/.test(value)) { //visa254 return value.length === 16;255 }256 if (validTypes & 0x0004 && /^(3[47])/.test(value)) { //amex257 return value.length === 15;258 }259 if (validTypes & 0x0008 && /^(3(0[012345]|[68]))/.test(value)) { //dinersclub260 return value.length === 14;261 }262 if (validTypes & 0x0010 && /^(2(014|149))/.test(value)) { //enroute263 return value.length === 15;264 }265 if (validTypes & 0x0020 && /^(6011)/.test(value)) { //discover266 return value.length === 16;267 }268 if (validTypes & 0x0040 && /^(3)/.test(value)) { //jcb269 return value.length === 16;270 }271 if (validTypes & 0x0040 && /^(2131|1800)/.test(value)) { //jcb272 return value.length === 15;273 }274 if (validTypes & 0x0080) { //unknown275 return true;276 }277 return false;278}, "Please enter a valid credit card number.");279/**280 * Validates currencies with any given symbols by @jameslouiz281 * Symbols can be optional or required. Symbols required by default282 *283 * Usage examples:284 * currency: ["£", false] - Use false for soft currency validation285 * currency: ["$", false]286 * currency: ["RM", false] - also works with text based symbols such as "RM" - Malaysia Ringgit etc287 *288 * <input class="currencyInput" name="currencyInput">289 *290 * Soft symbol checking291 * currencyInput: {292 * currency: ["$", false]293 * }294 *295 * Strict symbol checking (default)296 * currencyInput: {297 * currency: "$"298 * //OR299 * currency: ["$", true]300 * }301 *302 * Multiple Symbols303 * currencyInput: {304 * currency: "$,£,¢"305 * }306 */307$.validator.addMethod("currency", function(value, element, param) {308 var isParamString = typeof param === "string",309 symbol = isParamString ? param : param[0],310 soft = isParamString ? true : param[1],311 regex;312 symbol = symbol.replace(/,/g, "");313 symbol = soft ? symbol + "]" : symbol + "]?";314 regex = "^[" + symbol + "([1-9]{1}[0-9]{0,2}(\\,[0-9]{3})*(\\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\\.[0-9]{0,2})?|0(\\.[0-9]{0,2})?|(\\.[0-9]{1,2})?)$";315 regex = new RegExp(regex);316 return this.optional(element) || regex.test(value);317}, "Please specify a valid currency");318$.validator.addMethod("dateFA", function(value, element) {319 return this.optional(element) || /^[1-4]\d{3}\/((0?[1-6]\/((3[0-1])|([1-2][0-9])|(0?[1-9])))|((1[0-2]|(0?[7-9]))\/(30|([1-2][0-9])|(0?[1-9]))))$/.test(value);320}, $.validator.messages.date);321/**322 * Return true, if the value is a valid date, also making this formal check dd/mm/yyyy.323 *324 * @example $.validator.methods.date("01/01/1900")325 * @result true326 *327 * @example $.validator.methods.date("01/13/1990")328 * @result false329 *330 * @example $.validator.methods.date("01.01.1900")331 * @result false332 *333 * @example <input name="pippo" class="{dateITA:true}" />334 * @desc Declares an optional input element whose value must be a valid date.335 *336 * @name $.validator.methods.dateITA337 * @type Boolean338 * @cat Plugins/Validate/Methods339 */340$.validator.addMethod("dateITA", function(value, element) {341 var check = false,342 re = /^\d{1,2}\/\d{1,2}\/\d{4}$/,343 adata, gg, mm, aaaa, xdata;344 if ( re.test(value)) {345 adata = value.split("/");346 gg = parseInt(adata[0], 10);347 mm = parseInt(adata[1], 10);348 aaaa = parseInt(adata[2], 10);349 xdata = new Date(Date.UTC(aaaa, mm - 1, gg, 12, 0, 0, 0));350 if ( ( xdata.getUTCFullYear() === aaaa ) && ( xdata.getUTCMonth () === mm - 1 ) && ( xdata.getUTCDate() === gg ) ) {351 check = true;352 } else {353 check = false;354 }355 } else {356 check = false;357 }358 return this.optional(element) || check;359}, $.validator.messages.date);360$.validator.addMethod("dateNL", function(value, element) {361 return this.optional(element) || /^(0?[1-9]|[12]\d|3[01])[\.\/\-](0?[1-9]|1[012])[\.\/\-]([12]\d)?(\d\d)$/.test(value);362}, $.validator.messages.date);363// Older "accept" file extension method. Old docs: http://docs.jquery.com/Plugins/Validation/Methods/accept364$.validator.addMethod("extension", function(value, element, param) {365 param = typeof param === "string" ? param.replace(/,/g, "|") : "png|jpe?g|gif";366 return this.optional(element) || value.match(new RegExp("\\.(" + param + ")$", "i"));367}, $.validator.format("Please enter a value with a valid extension."));368/**369 * Dutch giro account numbers (not bank numbers) have max 7 digits370 */371$.validator.addMethod("giroaccountNL", function(value, element) {372 return this.optional(element) || /^[0-9]{1,7}$/.test(value);373}, "Please specify a valid giro account number");374/**375 * IBAN is the international bank account number.376 * It has a country - specific format, that is checked here too377 */378$.validator.addMethod("iban", function(value, element) {379 // some quick simple tests to prevent needless work380 if (this.optional(element)) {381 return true;382 }383 // remove spaces and to upper case384 var iban = value.replace(/ /g, "").toUpperCase(),385 ibancheckdigits = "",386 leadingZeroes = true,387 cRest = "",388 cOperator = "",389 countrycode, ibancheck, charAt, cChar, bbanpattern, bbancountrypatterns, ibanregexp, i, p;390 // check the country code and find the country specific format391 countrycode = iban.substring(0, 2);392 bbancountrypatterns = {393 "AL": "\\d{8}[\\dA-Z]{16}",394 "AD": "\\d{8}[\\dA-Z]{12}",395 "AT": "\\d{16}",396 "AZ": "[\\dA-Z]{4}\\d{20}",397 "BE": "\\d{12}",398 "BH": "[A-Z]{4}[\\dA-Z]{14}",399 "BA": "\\d{16}",400 "BR": "\\d{23}[A-Z][\\dA-Z]",401 "BG": "[A-Z]{4}\\d{6}[\\dA-Z]{8}",402 "CR": "\\d{17}",403 "HR": "\\d{17}",404 "CY": "\\d{8}[\\dA-Z]{16}",405 "CZ": "\\d{20}",406 "DK": "\\d{14}",407 "DO": "[A-Z]{4}\\d{20}",408 "EE": "\\d{16}",409 "FO": "\\d{14}",410 "FI": "\\d{14}",411 "FR": "\\d{10}[\\dA-Z]{11}\\d{2}",412 "GE": "[\\dA-Z]{2}\\d{16}",413 "DE": "\\d{18}",414 "GI": "[A-Z]{4}[\\dA-Z]{15}",415 "GR": "\\d{7}[\\dA-Z]{16}",416 "GL": "\\d{14}",417 "GT": "[\\dA-Z]{4}[\\dA-Z]{20}",418 "HU": "\\d{24}",419 "IS": "\\d{22}",420 "IE": "[\\dA-Z]{4}\\d{14}",421 "IL": "\\d{19}",422 "IT": "[A-Z]\\d{10}[\\dA-Z]{12}",423 "KZ": "\\d{3}[\\dA-Z]{13}",424 "KW": "[A-Z]{4}[\\dA-Z]{22}",425 "LV": "[A-Z]{4}[\\dA-Z]{13}",426 "LB": "\\d{4}[\\dA-Z]{20}",427 "LI": "\\d{5}[\\dA-Z]{12}",428 "LT": "\\d{16}",429 "LU": "\\d{3}[\\dA-Z]{13}",430 "MK": "\\d{3}[\\dA-Z]{10}\\d{2}",431 "MT": "[A-Z]{4}\\d{5}[\\dA-Z]{18}",432 "MR": "\\d{23}",433 "MU": "[A-Z]{4}\\d{19}[A-Z]{3}",434 "MC": "\\d{10}[\\dA-Z]{11}\\d{2}",435 "MD": "[\\dA-Z]{2}\\d{18}",436 "ME": "\\d{18}",437 "NL": "[A-Z]{4}\\d{10}",438 "NO": "\\d{11}",439 "PK": "[\\dA-Z]{4}\\d{16}",440 "PS": "[\\dA-Z]{4}\\d{21}",441 "PL": "\\d{24}",442 "PT": "\\d{21}",443 "RO": "[A-Z]{4}[\\dA-Z]{16}",444 "SM": "[A-Z]\\d{10}[\\dA-Z]{12}",445 "SA": "\\d{2}[\\dA-Z]{18}",446 "RS": "\\d{18}",447 "SK": "\\d{20}",448 "SI": "\\d{15}",449 "ES": "\\d{20}",450 "SE": "\\d{20}",451 "CH": "\\d{5}[\\dA-Z]{12}",452 "TN": "\\d{20}",453 "TR": "\\d{5}[\\dA-Z]{17}",454 "AE": "\\d{3}\\d{16}",455 "GB": "[A-Z]{4}\\d{14}",456 "VG": "[\\dA-Z]{4}\\d{16}"457 };458 bbanpattern = bbancountrypatterns[countrycode];459 // As new countries will start using IBAN in the460 // future, we only check if the countrycode is known.461 // This prevents false negatives, while almost all462 // false positives introduced by this, will be caught463 // by the checksum validation below anyway.464 // Strict checking should return FALSE for unknown465 // countries.466 if (typeof bbanpattern !== "undefined") {467 ibanregexp = new RegExp("^[A-Z]{2}\\d{2}" + bbanpattern + "$", "");468 if (!(ibanregexp.test(iban))) {469 return false; // invalid country specific format470 }471 }472 // now check the checksum, first convert to digits473 ibancheck = iban.substring(4, iban.length) + iban.substring(0, 4);474 for (i = 0; i < ibancheck.length; i++) {475 charAt = ibancheck.charAt(i);476 if (charAt !== "0") {477 leadingZeroes = false;478 }479 if (!leadingZeroes) {480 ibancheckdigits += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(charAt);481 }482 }483 // calculate the result of: ibancheckdigits % 97484 for (p = 0; p < ibancheckdigits.length; p++) {485 cChar = ibancheckdigits.charAt(p);486 cOperator = "" + cRest + "" + cChar;487 cRest = cOperator % 97;488 }489 return cRest === 1;490}, "Please specify a valid IBAN");491$.validator.addMethod("integer", function(value, element) {492 return this.optional(element) || /^-?\d+$/.test(value);493}, "A positive or negative non-decimal number please");494$.validator.addMethod("ipv4", function(value, element) {495 return this.optional(element) || /^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/i.test(value);496}, "Please enter a valid IP v4 address.");497$.validator.addMethod("ipv6", function(value, element) {498 return this.optional(element) || /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/i.test(value);499}, "Please enter a valid IP v6 address.");500$.validator.addMethod("lettersonly", function(value, element) {501 return this.optional(element) || /^[a-z]+$/i.test(value);502}, "Letters only please");503$.validator.addMethod("letterswithbasicpunc", function(value, element) {504 return this.optional(element) || /^[a-z\-.,()'"\s]+$/i.test(value);505}, "Letters or punctuation only please");506$.validator.addMethod("mobileNL", function(value, element) {507 return this.optional(element) || /^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)6((\s|\s?\-\s?)?[0-9]){8}$/.test(value);508}, "Please specify a valid mobile number");509/* For UK phone functions, do the following server side processing:510 * Compare original input with this RegEx pattern:511 * ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$512 * Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'513 * Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.514 * A number of very detailed GB telephone number RegEx patterns can also be found at:515 * http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers516 */517$.validator.addMethod("mobileUK", function(phone_number, element) {518 phone_number = phone_number.replace(/\(|\)|\s+|-/g, "");519 return this.optional(element) || phone_number.length > 9 &&520 phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[1345789]\d{2}|624)\s?\d{3}\s?\d{3})$/);521}, "Please specify a valid mobile number");522/*523 * The número de identidad de extranjero ( NIE )is a code used to identify the non-nationals in Spain524 */525$.validator.addMethod( "nieES", function( value ) {526 "use strict";527 value = value.toUpperCase();528 // Basic format test529 if ( !value.match( "((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)" ) ) {530 return false;531 }532 // Test NIE533 //T534 if ( /^[T]{1}/.test( value ) ) {535 return ( value[ 8 ] === /^[T]{1}[A-Z0-9]{8}$/.test( value ) );536 }537 //XYZ538 if ( /^[XYZ]{1}/.test( value ) ) {539 return (540 value[ 8 ] === "TRWAGMYFPDXBNJZSQVHLCKE".charAt(541 value.replace( "X", "0" )542 .replace( "Y", "1" )543 .replace( "Z", "2" )544 .substring( 0, 8 ) % 23545 )546 );547 }548 return false;549}, "Please specify a valid NIE number." );550/*551 * The Número de Identificación Fiscal ( NIF ) is the way tax identification used in Spain for individuals552 */553$.validator.addMethod( "nifES", function( value ) {554 "use strict";555 value = value.toUpperCase();556 // Basic format test557 if ( !value.match("((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)") ) {558 return false;559 }560 // Test NIF561 if ( /^[0-9]{8}[A-Z]{1}$/.test( value ) ) {562 return ( "TRWAGMYFPDXBNJZSQVHLCKE".charAt( value.substring( 8, 0 ) % 23 ) === value.charAt( 8 ) );563 }564 // Test specials NIF (starts with K, L or M)565 if ( /^[KLM]{1}/.test( value ) ) {566 return ( value[ 8 ] === String.fromCharCode( 64 ) );567 }568 return false;569}, "Please specify a valid NIF number." );570jQuery.validator.addMethod( "notEqualTo", function( value, element, param ) {571 return this.optional(element) || !$.validator.methods.equalTo.call( this, value, element, param );572}, "Please enter a different value, values must not be the same." );573$.validator.addMethod("nowhitespace", function(value, element) {574 return this.optional(element) || /^\S+$/i.test(value);575}, "No white space please");576/**577* Return true if the field value matches the given format RegExp578*579* @example $.validator.methods.pattern("AR1004",element,/^AR\d{4}$/)580* @result true581*582* @example $.validator.methods.pattern("BR1004",element,/^AR\d{4}$/)583* @result false584*585* @name $.validator.methods.pattern586* @type Boolean587* @cat Plugins/Validate/Methods588*/589$.validator.addMethod("pattern", function(value, element, param) {590 if (this.optional(element)) {591 return true;592 }593 if (typeof param === "string") {594 param = new RegExp("^(?:" + param + ")$");595 }596 return param.test(value);597}, "Invalid format.");598/**599 * Dutch phone numbers have 10 digits (or 11 and start with +31).600 */601$.validator.addMethod("phoneNL", function(value, element) {602 return this.optional(element) || /^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)[1-9]((\s|\s?\-\s?)?[0-9]){8}$/.test(value);603}, "Please specify a valid phone number.");604/* For UK phone functions, do the following server side processing:605 * Compare original input with this RegEx pattern:606 * ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$607 * Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'608 * Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.609 * A number of very detailed GB telephone number RegEx patterns can also be found at:610 * http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers611 */612$.validator.addMethod("phoneUK", function(phone_number, element) {613 phone_number = phone_number.replace(/\(|\)|\s+|-/g, "");614 return this.optional(element) || phone_number.length > 9 &&615 phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?)|(?:\(?0))(?:\d{2}\)?\s?\d{4}\s?\d{4}|\d{3}\)?\s?\d{3}\s?\d{3,4}|\d{4}\)?\s?(?:\d{5}|\d{3}\s?\d{3})|\d{5}\)?\s?\d{4,5})$/);616}, "Please specify a valid phone number");617/**618 * matches US phone number format619 *620 * where the area code may not start with 1 and the prefix may not start with 1621 * allows '-' or ' ' as a separator and allows parens around area code622 * some people may want to put a '1' in front of their number623 *624 * 1(212)-999-2345 or625 * 212 999 2344 or626 * 212-999-0983627 *628 * but not629 * 111-123-5434630 * and not631 * 212 123 4567632 */633$.validator.addMethod("phoneUS", function(phone_number, element) {634 phone_number = phone_number.replace(/\s+/g, "");635 return this.optional(element) || phone_number.length > 9 &&636 phone_number.match(/^(\+?1-?)?(\([2-9]([02-9]\d|1[02-9])\)|[2-9]([02-9]\d|1[02-9]))-?[2-9]([02-9]\d|1[02-9])-?\d{4}$/);637}, "Please specify a valid phone number");638/* For UK phone functions, do the following server side processing:639 * Compare original input with this RegEx pattern:640 * ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$641 * Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'642 * Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.643 * A number of very detailed GB telephone number RegEx patterns can also be found at:644 * http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers645 */646//Matches UK landline + mobile, accepting only 01-3 for landline or 07 for mobile to exclude many premium numbers647$.validator.addMethod("phonesUK", function(phone_number, element) {648 phone_number = phone_number.replace(/\(|\)|\s+|-/g, "");649 return this.optional(element) || phone_number.length > 9 &&650 phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[1345789]\d{8}|624\d{6})))$/);651}, "Please specify a valid uk phone number");652/**653 * Matches a valid Canadian Postal Code654 *655 * @example jQuery.validator.methods.postalCodeCA( "H0H 0H0", element )656 * @result true657 *658 * @example jQuery.validator.methods.postalCodeCA( "H0H0H0", element )659 * @result false660 *661 * @name jQuery.validator.methods.postalCodeCA662 * @type Boolean663 * @cat Plugins/Validate/Methods664 */665$.validator.addMethod( "postalCodeCA", function( value, element ) {666 return this.optional( element ) || /^[ABCEGHJKLMNPRSTVXY]\d[A-Z] \d[A-Z]\d$/.test( value );667}, "Please specify a valid postal code" );668/*669* Valida CEPs do brasileiros:670*671* Formatos aceitos:672* 99999-999673* 99.999-999674* 99999999675*/676$.validator.addMethod("postalcodeBR", function(cep_value, element) {677 return this.optional(element) || /^\d{2}.\d{3}-\d{3}?$|^\d{5}-?\d{3}?$/.test( cep_value );678}, "Informe um CEP válido.");679/* Matches Italian postcode (CAP) */680$.validator.addMethod("postalcodeIT", function(value, element) {681 return this.optional(element) || /^\d{5}$/.test(value);682}, "Please specify a valid postal code");683$.validator.addMethod("postalcodeNL", function(value, element) {684 return this.optional(element) || /^[1-9][0-9]{3}\s?[a-zA-Z]{2}$/.test(value);685}, "Please specify a valid postal code");686// Matches UK postcode. Does not match to UK Channel Islands that have their own postcodes (non standard UK)687$.validator.addMethod("postcodeUK", function(value, element) {688 return this.optional(element) || /^((([A-PR-UWYZ][0-9])|([A-PR-UWYZ][0-9][0-9])|([A-PR-UWYZ][A-HK-Y][0-9])|([A-PR-UWYZ][A-HK-Y][0-9][0-9])|([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))\s?([0-9][ABD-HJLNP-UW-Z]{2})|(GIR)\s?(0AA))$/i.test(value);689}, "Please specify a valid UK postcode");690/*691 * Lets you say "at least X inputs that match selector Y must be filled."692 *693 * The end result is that neither of these inputs:694 *695 * <input class="productinfo" name="partnumber">696 * <input class="productinfo" name="description">697 *698 * ...will validate unless at least one of them is filled.699 *700 * partnumber: {require_from_group: [1,".productinfo"]},701 * description: {require_from_group: [1,".productinfo"]}702 *703 * options[0]: number of fields that must be filled in the group704 * options[1]: CSS selector that defines the group of conditionally required fields705 */706$.validator.addMethod("require_from_group", function(value, element, options) {707 var $fields = $(options[1], element.form),708 $fieldsFirst = $fields.eq(0),709 validator = $fieldsFirst.data("valid_req_grp") ? $fieldsFirst.data("valid_req_grp") : $.extend({}, this),710 isValid = $fields.filter(function() {711 return validator.elementValue(this);712 }).length >= options[0];713 // Store the cloned validator for future validation714 $fieldsFirst.data("valid_req_grp", validator);715 // If element isn't being validated, run each require_from_group field's validation rules716 if (!$(element).data("being_validated")) {717 $fields.data("being_validated", true);718 $fields.each(function() {719 validator.element(this);720 });721 $fields.data("being_validated", false);722 }723 return isValid;724}, $.validator.format("Please fill at least {0} of these fields."));725/*726 * Lets you say "either at least X inputs that match selector Y must be filled,727 * OR they must all be skipped (left blank)."728 *729 * The end result, is that none of these inputs:730 *731 * <input class="productinfo" name="partnumber">732 * <input class="productinfo" name="description">733 * <input class="productinfo" name="color">734 *735 * ...will validate unless either at least two of them are filled,736 * OR none of them are.737 *738 * partnumber: {skip_or_fill_minimum: [2,".productinfo"]},739 * description: {skip_or_fill_minimum: [2,".productinfo"]},740 * color: {skip_or_fill_minimum: [2,".productinfo"]}741 *742 * options[0]: number of fields that must be filled in the group743 * options[1]: CSS selector that defines the group of conditionally required fields744 *745 */746$.validator.addMethod("skip_or_fill_minimum", function(value, element, options) {747 var $fields = $(options[1], element.form),748 $fieldsFirst = $fields.eq(0),749 validator = $fieldsFirst.data("valid_skip") ? $fieldsFirst.data("valid_skip") : $.extend({}, this),750 numberFilled = $fields.filter(function() {751 return validator.elementValue(this);752 }).length,753 isValid = numberFilled === 0 || numberFilled >= options[0];754 // Store the cloned validator for future validation755 $fieldsFirst.data("valid_skip", validator);756 // If element isn't being validated, run each skip_or_fill_minimum field's validation rules757 if (!$(element).data("being_validated")) {758 $fields.data("being_validated", true);759 $fields.each(function() {760 validator.element(this);761 });762 $fields.data("being_validated", false);763 }764 return isValid;...
shared.ts
Source:shared.ts
...17 top: 0;18 right: 0;19 left: 0;20 z-index: 1000;21 /* background: color(var(--darkgrey) l(-5%)); */22 background: ${lighten('-0.05', colors.darkgrey)};23`;24export const SiteMain = css`25 flex-grow: 1;26 @media (prefers-color-scheme: dark) {27 background: ${colors.darkmode};28 }29`;30export const SiteTitle = styled.h1`31 z-index: 10;32 margin: 0 0 0 -2px;33 padding: 0;34 font-size: 5rem;35 line-height: 1em;36 font-weight: 600;37 @media (max-width: 500px) {38 font-size: 4.2rem;39 }40`;41export const SiteDescription = styled.h2`42 z-index: 10;43 margin: 0;44 padding: 5px 0;45 font-size: 2.1rem;46 line-height: 1.4em;47 font-weight: 400;48 opacity: 0.8;49 @media (max-width: 500px) {50 font-size: 1.8rem;51 }52`;53export const Posts = css`54 overflow-x: hidden;55`;56export const PostFeed = css`57 position: relative;58 display: flex;59 flex-wrap: wrap;60 margin: 0 -20px;61 padding: 50px 0 0;62 background: #fff;63 /* Special Template Styles */64 padding: 40px 0 5vw;65 border-top-left-radius: 3px;66 border-top-right-radius: 3px;67 @media (prefers-color-scheme: dark) {68 background: ${colors.darkmode};69 }70`;71export const SocialLink = css`72 display: inline-block;73 margin: 0;74 padding: 10px;75 opacity: 0.8;76 :hover {77 opacity: 1;78 }79 svg {80 height: 1.8rem;81 fill: #fff;82 }83`;84export const SocialLinkFb = css`85 svg {86 height: 1.6rem;87 }88`;89export const SiteHeader = css``;90export const SiteHeaderContent = styled.div`91 z-index: 100;92 display: flex;93 flex-direction: column;94 justify-content: center;95 align-items: center;96 padding: 6vw 3vw;97 min-height: 200px;98 max-height: 340px;99`;100export const SiteHeaderStyles = css`101 position: relative;102 /* margin-top: 64px; */103 padding-bottom: 12px;104 color: #fff;105 /* background: color(var(--darkgrey) l(-5%)) no-repeat center center; */106 background: ${lighten('-0.05', colors.darkgrey)} no-repeat center center;107 background-size: cover;108 :before {109 content: '';110 position: absolute;111 top: 0;112 right: 0;113 bottom: 0;114 left: 0;115 z-index: 10;116 display: block;117 background: rgba(0, 0, 0, 0.18);118 }119 :after {120 content: '';121 position: absolute;122 top: 0;123 right: 0;124 bottom: auto;125 left: 0;126 z-index: 10;127 display: block;128 height: 140px;129 background: linear-gradient(rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0));130 }131 @media (prefers-color-scheme: dark) {132 :before {133 background: rgba(0, 0, 0, 0.6);134 }135 }136`;137export const AuthorProfileImage = css`138 flex: 0 0 60px;139 margin: 0;140 width: 60px;141 height: 60px;142 border: none;143 @media (prefers-color-scheme: dark) {144 box-shadow: 0 0 0 6px hsla(0, 0%, 100%, 0.04);145 background: ${colors.darkmode};146 }147`;148// tag and author post lists149export const SiteArchiveHeader = css`150 .site-header-content {151 position: relative;152 align-items: stretch;153 padding: 12vw 0 20px;154 min-height: 200px;155 max-height: 600px;156 }157`;158export const SiteHeaderBackground = css`159 margin-top: 64px;160`;161export const ResponsiveHeaderBackground = styled.div<{ backgroundImage?: string }>`162 ${p =>163 p.backgroundImage164 && `165 position: relative;166 margin-top: 64px;167 padding-bottom: 12px;168 color: #fff;169 background-size: cover;170 /* background: color(var(--darkgrey) l(-5%)) no-repeat center center; */171 background: #090a0b no-repeat 50%;172 background-image: url(${p.backgroundImage});173 :before {174 content: '';175 position: absolute;176 top: 0;177 right: 0;178 bottom: 0;179 left: 0;180 z-index: 10;181 display: block;182 background: rgba(0, 0, 0, 0.18);183 }184 :after {185 content: '';186 position: absolute;187 top: 0;188 right: 0;189 bottom: auto;190 left: 0;191 z-index: 10;192 display: block;193 height: 140px;194 background: linear-gradient(rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0));195 }196 @media (prefers-color-scheme: dark) {197 &:before {198 background: rgba(0, 0, 0, 0.6);199 }200 }201 `}202 ${p =>203 !p.backgroundImage204 && `205 padding-top: 0;206 padding-bottom: 0;207 /* color: var(--darkgrey); */208 color: ${colors.darkgrey};209 background: #fff;210 opacity: 1;211 .site-description {212 /* color: var(--midgrey); */213 color: ${colors.midgrey};214 opacity: 1;215 }216 .site-header-content {217 padding: 5vw 0 10px;218 /* border-bottom: 1px solid color(var(--lightgrey) l(+12%)); */219 border-bottom: 1px solid ${lighten('0.12', colors.lightgrey)};220 }221 .author-bio {222 /* color: var(--midgrey); */223 color: ${colors.midgrey};224 opacity: 1;225 }226 .author-meta {227 /* color: var(--midgrey); */228 color: ${colors.midgrey};229 opacity: 1;230 }231 .author-social-link a {232 /* color: var(--darkgrey); */233 color: ${colors.darkgrey};234 }235 .author-social-link a:before {236 /* color: var(--midgrey); */237 color: ${colors.midgrey};238 }239 .author-location + .author-stats:before,240 .author-stats + .author-social-link:before,241 .author-social-link + .author-social-link:before {242 /* color: var(--midgrey); */243 color: ${colors.midgrey};244 }245 .author-header {246 padding-bottom: 20px;247 }248 @media (max-width: 500px) {249 .site-header-content {250 flex-direction: column;251 align-items: center;252 min-height: unset;253 }254 .site-title {255 font-size: 4.2rem;256 text-align: center;257 }258 .site-header-content {259 padding: 12vw 0 20px;260 }261 .author-header {262 padding-bottom: 10px;263 }264 }265 @media (prefers-color-scheme: dark) {266 color: rgba(255, 255, 255, 0.9);267 /* background: var(--darkmode); */268 background: ${colors.darkmode};269 .site-header-content {270 /* border-bottom-color: color(var(--darkmode) l(+15%)); */271 /* border-bottom-color: ${lighten('0.15', colors.darkmode)}; */272 border-bottom-color: #272a30;273 }274 .author-social-link a {275 color: rgba(255, 255, 255, 0.75);276 }277 }278 `}279`;280export const NoImage = css`281 .no-image {282 padding-top: 0;283 padding-bottom: 0;284 /* color: var(--darkgrey); */285 color: ${colors.darkgrey};286 background: #fff;287 opacity: 1;288 }289 .no-image .site-description {290 /* color: var(--midgrey); */291 color: ${colors.midgrey};292 opacity: 1;293 }294 .no-image .site-header-content {295 padding: 5vw 0 10px;296 /* border-bottom: 1px solid color(var(--lightgrey) l(+12%)); */297 border-bottom: 1px solid ${lighten('0.12', colors.lightgrey)};298 }299 .no-image .author-bio {300 /* color: var(--midgrey); */301 color: ${colors.midgrey};302 opacity: 1;303 }304 .no-image .author-meta {305 /* color: var(--midgrey); */306 color: ${colors.midgrey};307 opacity: 1;308 }309 .no-image .author-social-link a {310 /* color: var(--darkgrey); */311 color: ${colors.darkgrey};312 }313 .no-image .author-social-link a:before {314 /* color: var(--midgrey); */315 color: ${colors.midgrey};316 }317 .no-image .author-location + .author-stats:before,318 .no-image .author-stats + .author-social-link:before,319 .no-image .author-social-link + .author-social-link:before {320 /* color: var(--midgrey); */321 color: ${colors.midgrey};322 }323 @media (max-width: 500px) {324 .site-header-content {325 flex-direction: column;326 align-items: center;327 min-height: unset;328 }329 .site-title {330 font-size: 4.2rem;331 text-align: center;332 }333 .no-image .site-header-content {334 padding: 12vw 0 20px;335 }336 }337 @media (prefers-color-scheme: dark) {338 .no-image {339 color: rgba(255, 255, 255, 0.9);340 /* background: var(--darkmode); */341 background: ${colors.darkmode};342 }343 .no-image .site-header-content {344 /* border-bottom-color: color(var(--darkmode) l(+15%)); */345 border-bottom-color: ${lighten('0.15', colors.darkmode)};346 }347 .no-image .author-social-link a {348 color: rgba(255, 255, 255, 0.75);349 }350 }...
userRoutes.js
Source:userRoutes.js
1const AlunosModels = require('../../models/alunos')2const userRoute = (app) => {3 app.route('/alunos/:id?')4 .get(async (req, res) => {5 const { id } = req.params6 const query = {};7 if (id){8 query._id = id9 }10 try {11 const alunos = await AlunosModels.findAll(query)12 res.send({ alunos })13 } catch (error){14 res.status(400).send({ error: 'Falha ao encontrar aluno' })15 }16 })17 .post(async (req, res) => {18 try {19 const post = new AlunosModels(req.body)20 await post.save()21 res.status(201).send('POST')22 } catch (error) {23 res.send(error)24 }25 })26 .put(async (req, res) => {27 const { id } = req.params28 if(!id) {29 return res.status(400).send({ error: 'ID do aluno não encontrado'})30 }31 try {32 const updatePost = await AlunosModels.findOneAndUpdate({ _id: id }, req.body, {33 new: true,34 });35 console.log(updatePost)36 if(updatePost) {37 return res.status(200).send('OK!')38 }39 res.status(400).send({ error: 'Não é possÃvel atualizar aluno'})40 } catch (error) {41 res.send(error)42 }43 })44 .delete(async (req, res) => {45 const { id } = req.params46 if(!id) {47 return res.status(400).send({ error: 'ID do aluno não encontrado'})48 }49 try {50 const deletePost = await AlunosModels.deleteOne({ _id: id })51 if (deletePost.deletedCount) {52 return res.send('Deletado')53 }54 res.status(400).send({ error: 'Não foi possÃvel deletar aluno' })55 } catch (error) {56 res.send(error)57 }58 })59}...
.eslintrc.js
Source:.eslintrc.js
1module.exports = {2 root: true,3 env: {4 node: true,5 jest: true,6 browser: true,7 },8 extends: ['xo-space', 'xo-react/space', 'xo-typescript'],9 rules: {10 '@typescript-eslint/object-curly-spacing': ['error', 'always'],11 '@typescript-eslint/indent': ['error', 2, { SwitchCase: 1 }],12 '@typescript-eslint/explicit-function-return-type': 'off',13 'capitalized-comments': 'off',14 'comma-dangle': ['error', 'always-multiline'],15 'react/jsx-tag-spacing': 'off',16 'react/prop-types': 'off',17 'react/require-default-props': 'off',18 'no-warning-comments': 'off',19 'complexity': 'off',20 'jsx-quotes': 'off',21 '@typescript-eslint/strict-boolean-expressions': 'off',22 '@typescript-eslint/no-unnecessary-condition': 'off',23 '@typescript-eslint/no-unsafe-call': 'off',24 '@typescript-eslint/no-unsafe-member-access': 'off',25 '@typescript-eslint/restrict-template-expressions': 'off',26 '@typescript-eslint/prefer-readonly-parameter-types': 'off',27 '@typescript-eslint/no-unsafe-return': 'off',28 '@typescript-eslint/comma-dangle': 'off',29 '@typescript-eslint/no-confusing-void-expression': 'off',30 '@typescript-eslint/no-unsafe-assignment': 'off',31 '@typescript-eslint/no-require-imports': 'off',32 '@typescript-eslint/naming-convention': 'off',33 '@typescript-eslint/no-unnecessary-type-arguments': 'off',34 },...
App.js
Source:App.js
1import React, { useEffect, useRef, useState } from "react";2import "./App.css";3import Home from "./Components/Home/Home";4import Navbar from "./Components/Navbar/Navbar";5import { ThemeContext } from "./ContextProvider/ThemeContext";6function App() {7 const [state, setState] = useState(false);8 const { newTheme, open, handleMenu } = React.useContext(ThemeContext);9 const scrollRef = useRef();10 return (11 <React.Fragment>12 <div className="components">13 <div14 style={{15 background: `${newTheme.menuBackground}`,16 color: `${newTheme.title}`,17 left: `${open ? "-100vw" : "0"}`,18 }}19 className="links"20 >21 <a onClick={handleMenu} href="#home">22 Home23 </a>24 <a onClick={handleMenu} href="#about">25 About26 </a>27 <a onClick={handleMenu} href="#projects">28 Projects29 </a>30 <a onClick={handleMenu} href="#techStacks">31 Skills32 </a>33 <a onClick={handleMenu} href="#contact">34 Contact35 </a>36 </div>37 <Navbar />38 <Home scrollRef={scrollRef} />39 </div>40 </React.Fragment>41 );42}...
3_select.js
Source:3_select.js
1const models = require('../../models')2const alunos = require('../../models')3async function select(){4 console.log('\n')5 const alunos = await models.alunos.findAll()6 alunos.forEach((alunos) => {7 console.log(`alunos: ${alunos.nome}8 ${alunos.email} 9 ${alunos.curso}10 ${alunos.nota}11 ${alunos.createdAt}12 13 `)14 })15}...
colors.ts
Source:colors.ts
...9 lightgrey: '#c5d2d9',10 whitegrey: '#e5eff5',11 pink: '#fa3a57',12 brown: '#a3821a',13 // darkmode: color(var(--darkgrey) l(+2%)),14 darkmode: '#191b1f',...
index.js
Source:index.js
1const sequelize = require('../src/pg/_database')2const models = {3 alunos: require('./alunos'),4 sequelize: sequelize5}...
Using AI Code Generation
1var r = require('devicefarmer-stf').r;2 stf.getDevices().then(function (devices) {3 console.log(devices);4 });5});6var r = require('devicefarmer-stf').r;7 stf.getDevices().then(function (devices) {8 console.log(devices);9 });10});11var r = require('devicefarmer-stf').r;12 stf.getDevices().then(function (devices) {13 console.log(devices);14 });15});16var r = require('devicefarmer-stf').r;17 stf.getDevices().then(function (devices) {18 console.log(devices);19 });20});21var r = require('devicefarmer-stf').r;22 stf.getDevices().then(function (devices) {23 console.log(devices);24 });25});
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2var device = new stf.Device({serial: 'serialnumber'});3device.r('shell', ['am', 'start', '-a', 'android.intent.action.MAIN', '-n', 'com.example/.MainActivity']);4var stf = require('devicefarmer-stf-client');5var device = new stf.Device({serial: 'serialnumber'});6device.r('shell', ['am', 'start', '-a', 'android.intent.action.MAIN', '-n', 'com.example/.MainActivity', '-d', 'hello', '-t', 'text/plain']);7var stf = require('devicefarmer-stf-client');8var device = new stf.Device({serial: 'serialnumber'});9device.r('shell', ['am', 'start', '-a', 'android.intent.action.MAIN', '-n', 'com.example/.MainActivity', '-d', 'hello', '-t', 'text/plain', '-c', 'android.intent.category.LAUNCHER']);
Using AI Code Generation
1var client = require('devicefarmer-stf-client')2 if(err) throw err;3 console.log(res);4});5var client = require('devicefarmer-stf-client')6 if(err) throw err;7 console.log(res);8});9var client = require('devicefarmer-stf-client')10 if(err) throw err;11 console.log(res);12});13var client = require('devicefarmer-stf-client')14 if(err) throw err;15 console.log(res);16});17var client = require('devicefarmer-stf-client')18 if(err) throw err;19 console.log(res);20});21var client = require('devicefarmer-stf-client')22 if(err) throw err;23 console.log(res);24});25var client = require('devicefarmer-stf-client')26 if(err) throw err;27 console.log(res);28});29var client = require('devicefarmer-stf-client')
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var device = stf.device;3var options = {4};5device.connect(options);6device.r('devices', function(err, res) {7 console.log(res);8});9var stf = require('devicefarmer-stf');10var device = stf.device;11var options = {12};13device.connect(options);14device.r('devices', function(err, res) {15 console.log(res);16});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!