Best JavaScript code snippet using wpt
ohrl.js
Source:ohrl.js
1/**2 * Provides utilities to deal with website/app urls. Provides functionality3 * for deep-linking Ajax calls, and a url mapper to generate dynamic urls.4 * @module urls5 */6/**7 * Utility for application urls8 *9 * @class urls10 * @namespace ohrl11 */12ohrl = function() {13 var _urls = {},14 _compiled = {},15 _lastHash = '',16 _nameMatcher = new RegExp('<([a-zA-Z0-9-_%]{1,})>', 'g');17 function _getArgs(urlName, path) {18 var args = {},19 name_matches = _urls[urlName].match(_nameMatcher),20 value_matches = path.match(_compiled[urlName]);21 if (name_matches) {22 var i, len, arg;23 for (i=0, len=name_matches.length; i<len; i+=1) {24 arg = name_matches[i].substring(1, name_matches[i].length-1);25 args[arg] = value_matches[i+1];;26 }27 }28 return args;29 };30 function _getName(path) {31 if (!path) {32 return;33 }34 for (url in _compiled) {35 if (path.match(_compiled[url])) {36 return url;37 }38 }39 return;40 };41 return {42 /**43 * Loads a set of urls names and paths44 * @method load45 * @static46 * @param {Object} urls an Object literal with names and paths like47 * {'taskEdit': '/task/edit/<taskId>/', 'taskCreate': '/task/create/'}48 * @return {Object} this for method chaining49 */50 load: function(urls) {51 for (url in urls) {52 if (urls.hasOwnProperty(url)) {53 _compiled[url] = new RegExp('^' + urls[url].replace(_nameMatcher, "([a-zA-Z0-9-_%]{0,})") + '$');54 }55 }56 _urls = urls;57 return this;58 },59 /**60 * Returns a url from the list that matches the specified parameters.61 * A non-existant url will raise an exception.62 * @method get63 * @static64 * @param {string} name: url name to call65 * @param {string} kwargs: an option object literal with key/value66 that can be used to get urls that require parameters67 * @return {String} url path68 */69 get: function(name, kwargs) {70 var path = _urls[name];71 if (!path) {72 throw('URL not found: ' + name);73 }74 var _path = path;75 var key;76 for (key in kwargs) {77 if (kwargs.hasOwnProperty(key)) {78 if (!path.match('<' + key +'>')) {79 throw('Invalid parameter ('+ key +') for '+ name);80 }81 path = path.replace('<' + key +'>', kwargs[key]);82 }83 }84 var missing_args = path.match(_nameMatcher);85 if (missing_args) {86 throw('Missing arguments (' + missing_args.join(", ") + ') for url ' + _path);87 }88 return path;89 },90 /**91 * Recieves a url path, and returns a url object with the name and92 * variables if there is match in the url list93 * @method resolve94 * @static95 * @param {String} path the url path96 * @return {Object/undefined} url object or undefined97 */98 resolve: function(path) {99 var url = {},100 urlName,101 kwargs;102 urlName = _getName(path);103 //olive.log(url + ' => ' + urlName);104 if (urlName) {105 kwargs = _getArgs(urlName, path);106 url['name'] = urlName;107 url['kwargs'] = kwargs;108 return url;109 }110 return;111 }112 };...
raw_tag_search.js
Source:raw_tag_search.js
1import download from './../../download/download.__TARGET__.js';2import {3 validate_string,4 validate_counting_number,5 validate_page_string,6 validate_boolean,7 validate_from_list8} from './../../validation/validation.js';9async function raw_tag_search (settings) {10 validate_settings(settings);11 return download.call(this, {12 method: 'GET',13 path: '/tags',14 response: 'JSON',15 format: 'URL',16 data: make_data(settings)17 }).catch(handle_error);18}19function handle_error (error) {20 // Todo21 console.log(error);22 throw error;23}24function validate_settings (settings) {25 if (settings['search[id]'] !== null) {26 validate_counting_number(settings['search[id]'], 'search[id]');27 }28 if (settings['search[fuzzy_name_matches]'] !== null) {29 validate_string(settings['search[fuzzy_name_matches]'], 'search[fuzzy_name_matches]');30 }31 if (settings['search[name_matches]'] !== null) {32 validate_string(settings['search[name_matches]'], 'search[name_matches]');33 }34 if (settings['search[name]'] !== null) {35 validate_string(settings['search[name]'], 'search[name]');36 }37 if (settings['search[category]'] !== null) {38 validate_counting_number(settings['search[category]'], 'search[category]');39 }40 if (settings['search[hide_empty]'] !== null) {41 validate_boolean(settings['search[hide_empty]'], 'search[hide_empty]');42 }43 if (settings['search[has_wiki]'] !== null) {44 validate_boolean(settings['search[has_wiki]'], 'search[has_wiki]');45 }46 if (settings['search[has_artist]'] !== null) {47 validate_boolean(settings['search[has_artist]'], 'search[has_artist]');48 }49 if (settings['search[is_locked]'] !== null) {50 validate_boolean(settings['search[is_locked]'], 'search[is_locked]');51 }52 if (settings['search[hide_wiki]'] !== null) {53 validate_boolean(settings['search[hide_wiki]'], 'search[hide_wiki]');54 }55 if (settings['search[order]'] !== null) {56 validate_from_list(settings['search[order]'], ['name', 'date', 'count', 'similarity'], 'search[order]');57 }58 if (settings.limit !== null) {59 validate_counting_number(settings.limit, 'limit');60 }61 if (settings.page !== null) {62 validate_page_string(settings.page, 'page');63 }64}65function make_data (settings) {66 const return_object = {};67 if (settings['search[id]'] !== null) {68 return_object['search[id]'] = settings['search[id]'];69 }70 if (settings['search[fuzzy_name_matches]'] !== null) {71 return_object['search[fuzzy_name_matches]'] = settings['search[fuzzy_name_matches]'];72 }73 if (settings['search[name_matches]'] !== null) {74 return_object['search[name_matches]'] = settings['search[name_matches]'];75 }76 if (settings['search[name]'] !== null) {77 return_object['search[name]'] = settings['search[name]'];78 }79 if (settings['search[category]'] !== null) {80 return_object['search[category]'] = settings['search[category]'];81 }82 if (settings['search[hide_empty]'] !== null) {83 return_object['search[hide_empty]'] = settings['search[hide_empty]'];84 }85 if (settings['search[has_wiki]'] !== null) {86 return_object['search[has_wiki]'] = settings['search[has_wiki]'];87 }88 if (settings['search[has_artist]'] !== null) {89 return_object['search[has_artist]'] = settings['search[has_artist]'];90 }91 if (settings['search[is_locked]'] !== null) {92 return_object['search[is_locked]'] = settings['search[is_locked]'];93 }94 if (settings['search[order]'] !== null) {95 return_object['search[order]'] = settings['search[order]'];96 }97 if (settings.limit !== null) {98 return_object.limit = settings.limit;99 }100 if (settings.page !== null) {101 return_object.page = settings.page;102 }103 return return_object;104}...
TagRelationships.ts
Source:TagRelationships.ts
1import Endpoint, { SearchParams } from "../components/Endpoint";2import { FormattedResponse } from "../components/RequestQueue";3import { APITagCategory } from "../responses/APITag";4import APITagAlias, { APITagAliasStatus } from "../responses/APITagAlias";5export default class TagRelationshipsEndpoint extends Endpoint<APITagAlias> {6 protected searchParams = [7 "name_matches", "antecedent_name", "consequent_name", "creator_name", "approver_name",8 "antecedent_tag_category", "consequent_tag_category", "status", "order", // Native9 ];10 protected searchParamAliases = {11 "name": "name_matches",12 };13 public find(search: TagRelationshipSearchParams = {}): Promise<FormattedResponse<APITagAlias>> { return super.find(search); }14}15export interface TagRelationshipSearchParams extends SearchParams {16 // Native17 /// name_matches?: string,18 antecedent_name?: string,19 consequent_name?: string,20 creator_name?: string,21 approver_name?: string,22 antecedent_tag_category?: APITagCategory,23 consequent_tag_category?: APITagCategory,24 status?: APITagAliasStatus,25 order?: TagRelationshipSearchOrder,26 // Aliases27 name?: string,28}29enum TagRelationshipSearchOrder {30 Status = "status",31 CreatedAt = "created_at",32 UpdatedAt = "updated_at",33 Name = "name",34 TagCount = "tag_count",...
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Barack Obama');3page.get(function(err, resp) {4 console.log(resp);5});6var wptools = require('wptools');7var page = wptools.page('Barack Obama');8page.name_matches(function(err, resp) {9 console.log(resp);10});11var wptools = require('wptools');12var page = wptools.page('Barack Obama');13page.get_wikidata(function(err, resp) {14 console.log(resp);15});16var wptools = require('wptools');17var page = wptools.page('Barack Obama');18page.jsonld(function(err, resp) {19 console.log(resp);20});21var wptools = require('wptools');22var page = wptools.page('Barack Obama');23page.html(function(err, resp) {24 console.log(resp);25});26var wptools = require('wptools');27var page = wptools.page('Barack Obama');28page.wikibase(function(err, resp) {29 console.log(resp);30});31var wptools = require('wptools');32var page = wptools.page('Barack Obama');33page.get_query(function(err, resp) {34 console.log(resp);35});36var wptools = require('wptools');37var page = wptools.page('Barack Obama');38page.get_parse(function(err, resp) {39 console.log(resp);40});41var wptools = require('wptools');42var page = wptools.page('Barack Obama');43page.get_restbase(function(err, resp) {
Using AI Code Generation
1var wptools = require('wptools');2var name = 'John Doe';3wptools.name_matches(name, function(err, resp) {4 if (err) {5 console.log(err);6 } else {7 console.log(resp);8 }9});10var wptools = require('wptools');11var name = 'John Doe';12wptools.get_pageid(name, function(err, resp) {13 if (err) {14 console.log(err);15 } else {16 console.log(resp);17 }18});19var wptools = require('wptools');20var name = 'John Doe';21wptools.get_pageid(name, function(err, resp) {22 if (err) {23 console.log(err);24 } else {25 console.log(resp);26 }27});28var wptools = require('wptools');29var name = 'John Doe';30wptools.get_pageid(name, function(err, resp) {31 if (err) {32 console.log(err);33 } else {34 console.log(resp);35 }36});37var wptools = require('wptools');38var name = 'John Doe';39wptools.get_pageid(name, function(err, resp) {40 if (err) {41 console.log(err);42 } else {
Using AI Code Generation
1const wpt = require('wpt');2const wptObj = new wpt(process.env.WPT_API_KEY);3wptObj.name_matches('www.webpagetest.org', function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10const wpt = require('wpt');11const wptObj = new wpt(process.env.WPT_API_KEY);12wptObj.get_testers(function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19const wpt = require('wpt');20const wptObj = new wpt(process.env.WPT_API_KEY);21wptObj.get_tester('1', function(err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28const wpt = require('wpt');29const wptObj = new wpt(process.env.WPT_API_KEY);30wptObj.get_locations(function(err, data) {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37const wpt = require('wpt');38const wptObj = new wpt(process.env.WPT_API_KEY);39wptObj.get_location('Dulles_MotoG4', function(err, data) {40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});46const wpt = require('wpt');47const wptObj = new wpt(process.env.WPT_API_KEY);48wptObj.get_location('Dulles_MotoG4', function(err, data) {49 if (err) {50 console.log(err);51 } else {52 console.log(data);53 }54});55const wpt = require('wpt');
Using AI Code Generation
1var wptools = require('wptools');2var name = "Barack Obama";3wptools.page(name).get(function(err,resp){4 console.log(resp);5});6var wptools = require('wptools');7var name = "Barack Obama";8wptools.page(name).get(function(err,resp){9 console.log(resp);10});11var wptools = require('wptools');12var name = "Barack Obama";13wptools.page(name).get(function(err,resp){14 console.log(resp);15});16var wptools = require('wptools');17var name = "Barack Obama";18wptools.page(name).get(function(err,resp){19 console.log(resp);20});21var wptools = require('wptools');22var name = "Barack Obama";23wptools.page(name).get(function(err,resp){24 console.log(resp);25});26var wptools = require('wptools');27var name = "Barack Obama";28wptools.page(name).get(function(err,resp){29 console.log(resp);30});31var wptools = require('wptools');32var name = "Barack Obama";33wptools.page(name).get(function(err,resp){34 console.log(resp);35});36var wptools = require('wptools');37var name = "Barack Obama";38wptools.page(name).get(function(err,resp){39 console.log(resp);40});41var wptools = require('wptools');42var name = "Barack Obama";43wptools.page(name).get(function(err,resp){44 console.log(resp);45});
Using AI Code Generation
1var wptools = require('wptools');2var name = 'Johann Sebastian Bach';3wptools(name).get(function(err, resp) {4 var matches = resp.name_matches;5 console.log(matches);6});7var wptools = require('wptools');8var name = 'Johann Sebastian Bach';9wptools(name).get(function(err, resp) {10 var matches = resp.name_matches;11 var disambiguation = matches[1];12 wptools(disambiguation).get(function(err, resp) {13 console.log(resp);14 });15});16var wptools = require('wptools');17var name = 'Johann Sebastian Bach';18wptools(name).get(function(err, resp) {19 var disambiguation = resp.disambiguation;20 wptools(disambiguation).get(function(err, resp) {21 console.log(resp);22 });23});24var wptools = require('wptools');25var name = 'Johann Sebastian Bach';26wptools(name).get(function(err, resp) {
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Albert Einstein');3page.get()4 .then(function (page) {5 var name_matches = page.name_matches();6 console.log(name_matches);7 })8 .catch(function (error) {9 console.log(error);10 });11## name_matches()12var wptools = require('wptools');13var page = wptools.page('Albert Einstein');14page.get()15 .then(function (page) {16 var name_matches = page.name_matches();17 console.log(name_matches);18 })19 .catch(function (error) {20 console.log(error);21 });22## langlinks()23var wptools = require('wptools');24var page = wptools.page('Albert Einstein');25page.get()26 .then(function (page) {27 var langlinks = page.langlinks();28 console.log(langlinks);29 })30 .catch(function (error) {31 console.log(error);32 });
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!!