How to use parseUrl method in Testcafe

Best JavaScript code snippet using testcafe

generate.js

Source:generate.js Github

copy

Full Screen

...75 <source class="fallback" srcset="${composeSrcSet(76 title,77 ogFileName78 )}" sizes="(max-width: 640px) 640px" type="${getImageType(ogFileName)}" />79 <img id="header-image" class="img" src="/assets/${parseUrl(title)}/${parseUrl(80 ogFileName81 )}" alt="${alt}" loading="lazy" />82 </picture>83 </figure>84 </header>`85 /* Generate Content */86 blogContent += content87 .map((element) => build(title, element))88 .reduce((previous, blog) => (previous += blog))89 blog = blog.replace("__Liliya_title__", title)90 blog = blog.replace("__Liliya_blog__", blogContent)91 /* Generate Link */92 let nextStory =93 index < contentList.length - 194 ? contentList[index + 1]95 : contentList[0],96 previousStory =97 index > 098 ? contentList[index - 1]99 : contentList[contentList.length - 1]100 nextStory = JSON.parse(101 fs.readFileSync(composeContent(nextStory), {102 encoding: "utf8"103 })104 )105 previousStory = JSON.parse(106 fs.readFileSync(composeContent(previousStory), {107 encoding: "utf8"108 })109 )110 blog = blog.replace(111 "__Liliya_next__",112 `/content/${parseUrl(nextStory.header.title)}`113 )114 blog = blog.replace(115 "__Liliya_previous__",116 `/content/${parseUrl(previousStory.header.title)}`117 )118 blog = blog.replace(119 "__Liliya_next_title__",120 nextStory.header.title121 )122 blog = blog.replace(123 "__Liliya_previous_title__",124 previousStory.header.title125 )126 let nextStoryImage = getFileName(nextStory.header.src),127 previousStoryImage = getFileName(previousStory.header.src)128 blog = blog.replace(129 new RegExp("__Liliya_next_src__", "g"),130 `131 <figure class="figure">132 <picture>133 <source class="webp" srcset="/assets/${parseUrl(134 nextStory.header.title135 )}/${renameExtension(136 parseUrl(addPreloadToFileName(nextStoryImage)),137 "webp"138 )} ,/assets/${parseUrl(139 nextStory.header.title140 )}/${renameExtension(141 parseUrl(142 add2xToFileName(143 addPreloadToFileName(nextStoryImage)144 )145 ),146 "webp"147 )} 2x" sizes="(max-width: 400px) 400px" type="image/webp" />148 <source class="fallback" srcset="/assets/${parseUrl(149 nextStory.header.title150 )}/${parseUrl(151 addPreloadToFileName(nextStoryImage)152 )} ,/assets/${parseUrl(nextStory.header.title)}/${parseUrl(153 addPreloadToFileName(nextStoryImage)154 )} 2x" sizes="(max-width: 400px) 400px" type="${getImageType(nextStoryImage)}" />155 <img class="img preload-story" src="/assets/${parseUrl(nextStory.header.title)}/${parseUrl(156 addPreloadToFileName(nextStoryImage)157 )}" alt="${nextStory.header.alt}" loading="lazy" />158 </picture>159 </figure>160 `161 )162 blog = blog.replace(163 new RegExp("__Liliya_previous_src__", "g"),164 `165 <figure class="figure">166 <picture>167 <source class="webp" srcset="/assets/${parseUrl(168 previousStory.header.title169 )}/${renameExtension(170 parseUrl(addPreloadToFileName(previousStoryImage)),171 "webp"172 )} ,/assets/${parseUrl(173 previousStory.header.title174 )}/${renameExtension(175 parseUrl(176 add2xToFileName(177 addPreloadToFileName(previousStoryImage)178 )179 ),180 "webp"181 )} 2x" sizes="(max-width: 400px) 400px" type="image/webp" />182 <source class="fallback" srcset="/assets/${parseUrl(183 previousStory.header.title184 )}/${parseUrl(185 addPreloadToFileName(previousStoryImage)186 )} ,/assets/${parseUrl(187 previousStory.header.title188 )}/${parseUrl(189 add2xToFileName(190 addPreloadToFileName(previousStoryImage)191 )192 )} 2x" sizes="(max-width: 400px) 400px" type="${getImageType(previousStoryImage)}" />193 <img class="img preload-story" src="/assets/${parseUrl(194 previousStory.header.title195 )}/${parseUrl(196 addPreloadToFileName(previousStoryImage)197 )}" alt="${previousStory.header.alt}" loading="lazy" />198 </picture>199 </figure>200 `201 )202 blog = blog.replace(203 "__Liliya_next_alt__",204 `/assets/${nextStory.header.alt}/${nextStoryImage}`205 )206 blog = blog.replace(207 "__Liliya_previous_alt__",208 `/assets/${previousStory.header.alt}/${previousStoryImage}`209 )210 blog = blog.replace(211 new RegExp("__Liliya_previous_json__", "g"),212 parseUrl(`/assets/${previousStory.header.title}/data.json`)213 )214 blog = blog.replace(215 new RegExp("__Liliya_next_json__", "g"),216 parseUrl(`/assets/${nextStory.header.title}/data.json`)217 )218 /* Generate Inline CSS */219 let inlineCSS = minifyCSS(220 fs.readFileSync(`${basepath}/src/styles/init.css`, {221 encoding: "utf8"222 })223 )224 inlineCSS += minifyCSS(225 fs.readFileSync(`${basepath}/src/styles/blog.css`, {226 encoding: "utf8"227 })228 )229 blog = blog.replace("/* __Liliya_style__ */", inlineCSS)230 /* ! SEO */231 let web = "https://liliya.saltyaom.com"232 blog = blog.replace(233 new RegExp("__Liliya_seo_title__", "g"),234 header.title235 )236 blog = blog.replace(237 new RegExp("__Liliya_seo_description__", "g"),238 content.filter((element) => element.nodeName === "p")[0]239 .textContent || "Project Liliya"240 )241 blog = blog.replace(242 new RegExp("__Liliya_seo_image__", "g"),243 `${web}/assets/${parseUrl(header.title)}/${addTitleToFileName(244 parseUrl(getFileName(header.src))245 )}`246 )247 blog = blog.replace(248 new RegExp("__Liliya_seo_url__", "g"),249 `${web}/content/${parseUrl(header.title)}`250 )251 blog = blog.replace(252 new RegExp("__Liliya_next_href__", "g"),253 `/content/${parseUrl(header.title)}`254 )255 blog = blog.replace(256 new RegExp("__Liliya_previous_href__", "g"),257 `/content/${parseUrl(header.title)}`258 )259 blog = minifyHTML(blog)260 fs.mkdirSync(composeDist(`content/${parseUrl(title)}`))261 fs.writeFileSync(262 composeDist(`content/${parseUrl(title)}/index.html`),263 blog264 )265 /* Pack Image */266 let blogAssets = `${assetsPath}/${parseUrl(title)}`267 fs.mkdirSync(`${assetsPath}/${parseUrl(title)}`)268 /* Pack Assets */269 let localAssets = new RegExp(assets, "g")270 let asLocalContent = JSON.parse(271 JSON.stringify(parsedBlogContent)272 .replace(localAssets, `/assets/${parseUrl(title)}`)273 .replace(/file\:\/\//g, "")274 .replace(/\n/g, "")275 )276 asLocalContent = Object.assign(asLocalContent, {277 content: asLocalContent.content.map((node) => {278 if (node.nodeName !== "img") return node279 return {280 ...node,281 src: parseUrl(node.src)282 }283 })284 })285 asLocalContent.header.src = parseUrl(asLocalContent.header.src)286 asLocalContent.footer = {287 previous: {288 title: previousStory.header.title,289 json: parseUrl(290 `/assets/${previousStory.header.title}/data.json`291 ),292 src: parseUrl(293 `/assets/${previousStory.header.title}/${previousStoryImage}`294 ),295 alt: previousStory.header.alt,296 href: `/content/${parseUrl(previousStory.header.title)}`297 },298 next: {299 title: nextStory.header.title,300 json: parseUrl(301 `/assets/${nextStory.header.title}/data.json`302 ),303 src: parseUrl(304 `/assets/${nextStory.header.title}/${nextStoryImage}`305 ),306 alt: nextStory.header.title,307 href: `/content/${parseUrl(nextStory.header.title)}`308 }309 }310 fs.writeFileSync(311 `${assetsPath}/${parseUrl(title)}/data.json`,312 JSON.stringify(asLocalContent)313 )314 content315 .filter(({ nodeName }) => nodeName === "img")316 .map(async ({ src }) => {317 packImage(src, blogAssets)318 })319 await packImage(src, blogAssets)320 await packTitle(src, blogAssets)321 await packPreload(src, blogAssets, 430)322 /* Pack etc */323 packFile(`${basepath}/assets/robots.txt`, dist)324 packFile(`${basepath}/assets/icon.png`, `${dist}/assets`)325 resolve(true)326 })327 )328 /* Pack Service Worker */329 await packContent()330 let serviceWorker = fs.readFileSync(331 `${basepath}/assets/service-worker.min.js`,332 { encoding: "utf8" }333 )334 let cachedAssets = []335 let assetsFolder = fs.readdirSync(`${basepath}/generated/dist/assets`)336 assetsFolder.forEach((assetFolder) => {337 let assetsOrFolder = `${basepath}/generated/dist/assets/${assetFolder}`338 if (!fs.lstatSync(assetsOrFolder).isDirectory())339 return cachedAssets.push(assetsOrFolder)340 fs.readdirSync(assetsOrFolder).forEach((fileName) => {341 let file = `${assetsOrFolder}/${fileName}`342 cachedAssets.push(file)343 })344 })345 let contentFolder = fs.readdirSync(`${basepath}/generated/dist/content`)346 contentFolder.forEach((contentName) => {347 let contentFolder = `${basepath}/generated/dist/content/${contentName}`348 fs.readdirSync(contentFolder).forEach((contentFile) => {349 cachedAssets.push(`${contentFolder}/${contentFile}`)350 })351 })352 cachedAssets = cachedAssets.map((asset) => `"${asset.replace(dist, "")}"`)353 serviceWorker = serviceWorker.replace(354 "__Liliya_service_worker__",355 cachedAssets356 )357 console.log(cachedAssets)358 fs.writeFileSync(`${dist}/service-worker.js`, serviceWorker)359}360let packFile = (path, dest) => {361 fs.copyFileSync(parseUrl(path), `${dest}/${getFileName(path)}`)362 },363 packImage = async (path, destination, size = 640, multiplier = 1.75) => {364 fs.writeFileSync(365 parseUrl(`${destination}/${getFileName(path)}`),366 await resizeImage(path, size)367 )368 fs.writeFileSync(369 parseUrl(`${destination}/${add2xToFileName(getFileName(path))}`),370 await resizeImage(path, size * multiplier)371 )372 fs.writeFileSync(373 parseUrl(374 `${destination}/${renameExtension(375 `${getFileName(path)}`,376 "webp"377 )}`378 ),379 await resizeImage(path, size, { webp: true })380 )381 fs.writeFileSync(382 `${destination}/${renameExtension(383 parseUrl(`${add2xToFileName(getFileName(path))}`),384 "webp"385 )}`,386 await resizeImage(path, size * multiplier, { webp: true })387 )388 },389 packPreload = async (path, destination, size = 400) => {390 fs.writeFileSync(391 parseUrl(392 `${destination}/${addPreloadToFileName(getFileName(path))}`393 ),394 await resizeImage(path, size)395 )396 fs.writeFileSync(397 parseUrl(398 `${destination}/${add2xToFileName(399 addPreloadToFileName(getFileName(path))400 )}`401 ),402 await resizeImage(path, size * 1.5)403 )404 fs.writeFileSync(405 parseUrl(406 `${destination}/${addPreloadToFileName(407 renameExtension(`${getFileName(path)}`, "webp")408 )}`409 ),410 await resizeImage(path, size, { webp: true })411 )412 fs.writeFileSync(413 parseUrl(414 `${destination}/${add2xToFileName(415 addPreloadToFileName(416 renameExtension(getFileName(path), "webp")417 )418 )}`419 ),420 await resizeImage(path, size * 1.5, { webp: true })421 )422 },423 packTitle = async (path, destination, size = 1920) => {424 fs.writeFileSync(425 parseUrl(426 `${destination}/${addTitleToFileName(getFileName(path))}`427 ),428 await resizeImage(path, size)429 )430 },431 minimizeAndPackCSS = (path, destination) => {432 let css = minifyCSS(433 fs.readFileSync(path, {434 encoding: "utf8"435 })436 )437 fs.writeFileSync(destination, css)438 }439let build = (title, node) => {440 let built441 switch (node.nodeName) {442 case "h1":443 built = `<h1 class="h1">${node.textContent}</h1>`444 break445 case "h2":446 built = `<h2 class="h2">${node.textContent}</h2>`447 break448 case "p":449 built = `<p class="p">${node.children450 .map((child) =>451 typeof child === "string"452 ? child453 : `<a class="a" href="${child.href}" target="_blank" rel="noreopener norefferer">${child.textContent}</a>`454 )455 .join("")}</p>`456 break457 case "img":458 let splitSrc = node.src.split("/"),459 fileName = splitSrc[splitSrc.length - 1]460 built = `<figure class="figure">461 <picture>462 <source class="webp" srcset="${composeSrcSet(463 title,464 renameExtension(fileName, "webp")465 )}" sizes="(max-width: 640px) 640px" type="image/webp" />466 <source class="fallback" srcset="${composeSrcSet(467 title,468 fileName469 )}" sizes="(max-width: 640px) 640px" type="${getImageType(fileName)}" />470 <img class="img" src="/assets/${parseUrl(title)}/${parseUrl(471 fileName472 )}" alt="${node.alt}" loading="lazy" />473 </picture>474 </figure>`475 break476 default:477 break478 }479 return built480}481let getFileName = (path) => {482 let splited = path.split("/")483 return splited[splited.length - 1].replace(/\%20/g, "-").toLowerCase()484 },485 renameExtension = (fileName, extension) => {486 let name = fileName.split(".")487 name.splice(name.length - 1, 0, ".")488 name.pop()489 name = name.reduce((name, next) => (name += next))490 return name + extension491 },492 add2xToFileName = (fileName) => {493 let name = fileName.split(".")494 name.splice(name.length - 1, 0, "@2x.")495 return name.reduce((name, next) => (name += next))496 },497 addPreloadToFileName = (fileName) => {498 let name = fileName.split(".")499 name.splice(name.length - 1, 0, "@preload.")500 return name.reduce((name, next) => (name += next))501 },502 addTitleToFileName = (fileName) => {503 let name = fileName.split(".")504 name.splice(name.length - 1, 0, "@title.")505 return name.reduce((name, next) => (name += next))506 },507 composeSrcSet = (title, file) => {508 let parsedTitle = parseUrl(title),509 parsedFile = parseUrl(file)510 return (511 `/assets/${parsedTitle}/${parsedFile}` +512 `\ ,` +513 `/assets/${parsedTitle}/${add2xToFileName(parsedFile)}\ 2x`514 )515 },516 getImageType = (fileName) => {517 let splited = fileName.split("."),518 type = splited[splited.length - 1]519 return type === "png" ? "image/png" : "image/jpeg"520 },521 parseUrl = (path) =>522 path523 .replace(/\ /g, "-")...

Full Screen

Full Screen

AdminController.js

Source:AdminController.js Github

copy

Full Screen

1/**2* AdminController3*4* @description :: Server-side logic for managing admins5* @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers6*/7module.exports = {8 listUsers: function(req, res) {9 var page = 1;10 var update = 0;11 var msg = "";12 var me = req.session.user;13 var query = User.find();14 var error_msg = [15 "Format email incorrect !",16 "Format firstName incorrect !",17 "Le firstName peut possèder: 2 à 35 charactères",18 "Format lastName incorrect !",19 "Le lastName peut possèder: 2 à 35 charactères",20 "Format pseudo incorrect !",21 "Le pseudo peut possèder: 2 à 35 charactères",22 "Permission incorrect !",23 "Language incorrect !",24 "Vous devez avoir une photo pour pouvoir la supprimer",25 "Le codeActive doit possèder au minimum 2 charactères"26 ];27 if (req.url.match("page=")) {28 url = req.url.split("page=")29 if (url[1].match("OK=update")) {30 url = url[1].split("\?OK=update")31 url[1] = url[0]32 update = 133 } else if (url[1].match("OFF=update")) {34 url = url[1].split("\?OFF=update")35 url[1] = url[0]36 update = 237 check_msg = url[1].split("-")38 msg = check_msg[1]39 if (msg === "email") {40 msg = error_msg[0]41 } else if (msg === "firstName0") {42 msg = error_msg[1]43 } else if (msg === "firstName1") {44 msg = error_msg[2]45 } else if (msg === "lastName0") {46 msg = error_msg[3]47 } else if (msg === "lastName1") {48 msg = error_msg[4]49 } else if (msg === "peudo0") {50 msg = error_msg[5]51 } else if (msg === "pseudo1") {52 msg = error_msg[6]53 } else if (msg === "permit") {54 msg = error_msg[7]55 } else if (msg === "language") {56 msg = error_msg[8]57 } else if (msg === "pic") {58 msg = error_msg[9]59 } else if (msg === "codeActive0") {60 msg = error_msg[10]61 }62 }63 if (url[1]) {64 if (Number(url[1])) {65 page = url[1]66 User.find().paginate({page: page, limit: 10}).exec(function(err, found){67 if (err)68 return res.serverError(err);69 return res.view('gestionUsers', {listUsers: found, page: page, update: update, msg: msg});70 });71 } else {72 User.find().paginate({page: page, limit: 10}).exec(function(err, found){73 if (err)74 return res.serverError(err);75 return res.view('gestionUsers', {listUsers: found, page: page, update: update, msg: msg});76 });77 }78 }79 } else {80 if (req.url.match("OK=update")) {81 update = 182 } else if (req.url.match("OFF=update")) {83 check_msg = req.url.split("-")84 msg = check_msg[1]85 if (msg === "email") {86 msg = error_msg[0]87 } else if (msg === "firstName0") {88 msg = error_msg[1]89 } else if (msg === "firstName1") {90 msg = error_msg[2]91 } else if (msg === "lastName0") {92 msg = error_msg[3]93 } else if (msg === "lastName1") {94 msg = error_msg[4]95 } else if (msg === "peudo0") {96 msg = error_msg[5]97 } else if (msg === "pseudo1") {98 msg = error_msg[6]99 } else if (msg === "permit") {100 msg = error_msg[7]101 } else if (msg === "language") {102 msg = error_msg[8]103 } else if (msg === "pic") {104 msg = error_msg[9]105 } else if (msg === "codeActive0") {106 msg = error_msg[10]107 }108 update = 2109 }110 if (me.admin === 2) {111 query.where({'admin': [1,0]}).paginate({page: page, limit: 10}).exec(function(err, found){112 if (err)113 return res.serverError(err);114 return res.view('gestionUsers', {listUsers: found, page: page, update: update, msg: msg, me: me});115 });116 } else if (me.admin === 1) {117 query.where({'admin': 0}).paginate({page: page, limit: 10}).exec(function(err, found){118 if (err)119 return res.serverError(err);120 return res.view('gestionUsers', {listUsers: found, page: page, update: update, msg: msg, me: me});121 });122 } else {123 return res.redirect('/');124 }125 }126 },127 adminUpdateUser: function(req, res) {128 User.find({ id: req.param("id_user") }).exec(function(err, user){129 const fs = require('fs');130 var temp = user.pop();131 var newUrl = "";132 var backURL = req.header('Referer') || '/';133 if (err) {134 return res.serverError(err);135 } else {136 if (backURL.match("OFF=update") || backURL.match("OK=update")) {137 parseUrl = backURL.split("\?");138 if (parseUrl[1] && (parseUrl[1].match("OFF=update") || parseUrl[1].match("OK=update"))) {139 newUrl = parseUrl[0]140 } else if (parseUrl[2] && (parseUrl[2].match("OFF=update") || parseUrl[1].match("OK=update"))) {141 newUrl = parseUrl[0] + "?" + parseUrl[1]142 } else {143 newUrl = backURL144 }145 }146 if (newUrl !== "") {147 backURL = newUrl148 }149 if (req.param("action") === "active") {150 temp.active = 1151 } else if (req.param("action") === "desactive") {152 temp.active = 0153 } else if (req.param("action") === "delete_pic") {154 if (temp.photo && temp.photo !== "") {155 var tmp_dir = temp.photo156 fs.unlink('./assets' + tmp_dir, (err) => {157 if (err) {158 console.log("error = " + err);159 } else {160 temp.photo = "";161 temp.save(function(err) {162 if (err) throw err;163 });164 }165 });166 } else {167 if (backURL.match("OK=update")) {168 parseUrl = backURL.split("\?");169 if (parseUrl[1] && parseUrl[1] === "OK=update") {170 parseUrl[1] = "OFF=update-pic"171 newUrl = parseUrl[0] + "?" + parseUrl[1]172 } else if (parseUrl[2] && parseUrl[2] === "OK=update") {173 parseUrl[2] = "OFF=update-pic"174 newUrl = parseUrl[0] + "?" + parseUrl[1] + "?" + parseUrl[2]175 } else {176 newUrl = backURL177 }178 return res.redirect(newUrl)179 } else {180 return res.redirect(backURL + "?OFF=update-pic")181 }182 }183 } else {184 var permit = 0185 if (req.param("permit") === "admin")186 permit = 1187 if (req.param("email") !== temp.email || req.param("firstName") !== temp.firstName || req.param("lastName") !== temp.lastName || req.param("pseudo") !== temp.pseudo || req.param("codeActive") !== temp.codeActive || permit !== temp.admin || req.param("language") !== temp.language) {188 if (req.param("email") !== "" && req.param("email") !== undefined && req.param("email") !== temp.email) {189 if (req.param("email").match(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]{2,}\.[a-z]{2,4}$/)) {190 temp.email = req.param("email")191 } else {192 if (backURL.match("OK=update")) {193 parseUrl = backURL.split("\?");194 if (parseUrl[1] && parseUrl[1] === "OK=update") {195 parseUrl[1] = "OFF=update-email"196 newUrl = parseUrl[0] + "?" + parseUrl[1]197 } else if (parseUrl[2] && parseUrl[2] === "OK=update") {198 parseUrl[2] = "OFF=update-email"199 newUrl = parseUrl[0] + "?" + parseUrl[1] + "?" + parseUrl[2]200 } else {201 newUrl = backURL202 }203 return res.redirect(newUrl)204 } else {205 return res.redirect(backURL + "?OFF=update-email")206 }207 }208 }209 if (req.param("firstName") !== "" && req.param("firstName") !== undefined && req.param("firstName") !== temp.firstName) {210 count = req.param("firstName").length211 if (count > 1 && count < 35) {212 var check = req.param("firstName").match(/[A-z\- éèàç]/g).length213 if (check === count) {214 temp.firstName = req.param("firstName")215 } else {216 if (backURL.match("OK=update")) {217 parseUrl = backURL.split("\?");218 if (parseUrl[1] && parseUrl[1] === "OK=update") {219 parseUrl[1] = "OFF=update-firstName0"220 newUrl = parseUrl[0] + "?" + parseUrl[1]221 } else if (parseUrl[2] && parseUrl[2] === "OK=update") {222 parseUrl[2] = "OFF=update-firstName0"223 newUrl = parseUrl[0] + "?" + parseUrl[1] + "?" + parseUrl[2]224 } else {225 newUrl = backURL226 }227 return res.redirect(newUrl)228 } else {229 return res.redirect(backURL + "?OFF=update-firstName0")230 }231 }232 } else {233 if (backURL.match("OK=update")) {234 parseUrl = backURL.split("\?");235 if (parseUrl[1] && parseUrl[1] === "OK=update") {236 parseUrl[1] = "OFF=update-firstName1"237 newUrl = parseUrl[0] + "?" + parseUrl[1]238 } else if (parseUrl[2] && parseUrl[2] === "OK=update") {239 parseUrl[2] = "OFF=update-firstName1"240 newUrl = parseUrl[0] + "?" + parseUrl[1] + "?" + parseUrl[2]241 } else {242 newUrl = backURL243 }244 return res.redirect(newUrl)245 } else {246 return res.redirect(backURL + "?OFF=update-firstName1")247 }248 }249 }250 if (req.param("lastName") !== "" && req.param("lastName") !== undefined && req.param("lastName") !== temp.lastName) {251 count = req.param("lastName").length252 if (count > 1 && count < 35) {253 var check = req.param("lastName").match(/[A-z\- éèàç]/g).length254 if (check === count) {255 temp.lastName = req.param("lastName")256 } else {257 if (backURL.match("OK=update")) {258 parseUrl = backURL.split("\?");259 if (parseUrl[1] && parseUrl[1] === "OK=update") {260 parseUrl[1] = "OFF=update-lastName0"261 newUrl = parseUrl[0] + "?" + parseUrl[1]262 } else if (parseUrl[2] && parseUrl[2] === "OK=update") {263 parseUrl[2] = "OFF=update-lastName0"264 newUrl = parseUrl[0] + "?" + parseUrl[1] + "?" + parseUrl[2]265 } else {266 newUrl = backURL267 }268 return res.redirect(newUrl)269 } else {270 return res.redirect(backURL + "?OFF=update-lastName0")271 }272 }273 } else {274 if (backURL.match("OK=update")) {275 parseUrl = backURL.split("\?");276 if (parseUrl[1] && parseUrl[1] === "OK=update") {277 parseUrl[1] = "OFF=update-lastName1"278 newUrl = parseUrl[0] + "?" + parseUrl[1]279 } else if (parseUrl[2] && parseUrl[2] === "OK=update") {280 parseUrl[2] = "OFF=update-lastName1"281 newUrl = parseUrl[0] + "?" + parseUrl[1] + "?" + parseUrl[2]282 } else {283 newUrl = backURL284 }285 return res.redirect(newUrl)286 } else {287 return res.redirect(backURL + "?OFF=update-lastName1")288 }289 }290 }291 if (req.param("pseudo") !== "" && req.param("pseudo") !== undefined && req.param("pseudo") !== temp.pseudo) {292 count = req.param("pseudo").length293 if (count > 1 && count < 36) {294 var check = req.param("pseudo").match(/[A-z0-9\- éèàç]/g).length295 if (check === count) {296 temp.pseudo = req.param("pseudo")297 } else {298 if (backURL.match("OK=update")) {299 parseUrl = backURL.split("\?");300 if (parseUrl[1] && parseUrl[1] === "OK=update") {301 parseUrl[1] = "OFF=update-pseudo0"302 newUrl = parseUrl[0] + "?" + parseUrl[1]303 } else if (parseUrl[2] && parseUrl[2] === "OK=update") {304 parseUrl[2] = "OFF=update-pseudo0"305 newUrl = parseUrl[0] + "?" + parseUrl[1] + "?" + parseUrl[2]306 } else {307 newUrl = backURL308 }309 return res.redirect(newUrl)310 } else {311 return res.redirect(backURL + "?OFF=update-pseudo0")312 }313 }314 } else {315 if (backURL.match("OK=update")) {316 parseUrl = backURL.split("\?");317 if (parseUrl[1] && parseUrl[1] === "OK=update") {318 parseUrl[1] = "OFF=update-pseudo1"319 newUrl = parseUrl[0] + "?" + parseUrl[1]320 } else if (parseUrl[2] && parseUrl[2] === "OK=update") {321 parseUrl[2] = "OFF=update-pseudo1"322 newUrl = parseUrl[0] + "?" + parseUrl[1] + "?" + parseUrl[2]323 } else {324 newUrl = backURL325 }326 return res.redirect(newUrl)327 } else {328 return res.redirect(backURL + "?OFF=update-pseudo1")329 }330 }331 }332 if (req.param("codeActive") !== "" && req.param("codeActive") !== undefined && req.param("codeActive") !== temp.codeActive) {333 if (req.param("codeActive").length > 1) {334 temp.codeActive = req.param("codeActive")335 } else {336 if (backURL.match("OK=update")) {337 parseUrl = backURL.split("\?");338 if (parseUrl[1] && parseUrl[1] === "OK=update") {339 parseUrl[1] = "OFF=update-codeActive0"340 newUrl = parseUrl[0] + "?" + parseUrl[1]341 } else if (parseUrl[2] && parseUrl[2] === "OK=update") {342 parseUrl[2] = "OFF=update-codeActive0"343 newUrl = parseUrl[0] + "?" + parseUrl[1] + "?" + parseUrl[2]344 } else {345 newUrl = backURL346 }347 return res.redirect(newUrl)348 } else {349 return res.redirect(backURL + "?OFF=update-codeActive0")350 }351 }352 }353 if (req.param("permit") !== "" && req.param("permit") !== undefined) {354 if (req.param("permit") === "member") {355 temp.admin = 0356 } else if (req.param("permit") === "admin") {357 temp.admin = 1358 } else {359 if (backURL.match("OK=update")) {360 parseUrl = backURL.split("\?");361 if (parseUrl[1] && parseUrl[1] === "OK=update") {362 parseUrl[1] = "OFF=update-permit"363 newUrl = parseUrl[0] + "?" + parseUrl[1]364 } else if (parseUrl[2] && parseUrl[2] === "OK=update") {365 parseUrl[2] = "OFF=update-permit"366 newUrl = parseUrl[0] + "?" + parseUrl[1] + "?" + parseUrl[2]367 } else {368 newUrl = backURL369 }370 return res.redirect(newUrl)371 } else {372 return res.redirect(backURL + "?OFF=update-permit")373 }374 }375 }376 if (req.param("language") !== "" && req.param("language") !== undefined) {377 if (req.param("language") === "English" || req.param("language") === "Français") {378 temp.language = req.param("language")379 } else {380 if (backURL.match("OK=update")) {381 parseUrl = backURL.split("\?");382 if (parseUrl[1] && parseUrl[1] === "OK=update") {383 parseUrl[1] = "OFF=update-language"384 newUrl = parseUrl[0] + "?" + parseUrl[1]385 } else if (parseUrl[2] && parseUrl[2] === "OK=update") {386 parseUrl[2] = "OFF=update-language"387 newUrl = parseUrl[0] + "?" + parseUrl[1] + "?" + parseUrl[2]388 } else {389 newUrl = backURL390 }391 return res.redirect(newUrl)392 } else {393 return res.redirect(backURL + "?OFF=update-language")394 }395 }396 }397 } else {398 if (backURL.match("OK=update") || backURL.match("OFF=update")) {399 parseUrl = backURL.split("\?");400 if (parseUrl[1] && (parseUrl[1] === "OK=update" || parseUrl[1] === "OFF=update")) {401 newUrl = parseUrl[0]402 } else if (parseUrl[2] && (parseUrl[2] === "OK=update" || parseUrl[2] === "OFF=update")) {403 newUrl = parseUrl[0] + "?" + parseUrl[1]404 } else {405 newUrl = backURL406 }407 return res.redirect(newUrl)408 } else {409 return res.redirect(backURL)410 }411 }412 }413 temp.save(function(err){414 if (err)415 return res.serverError(err);416 if (backURL.match("OK=update")) {417 return res.redirect(backURL)418 } else if (backURL.match("OFF=update")){419 parseUrl = backURL.split("\?");420 if (parseUrl[1] && parseUrl[1] === "OFF=update") {421 parseUrl[1] = "OK=update"422 newUrl = parseUrl[0] + "?" + parseUrl[1]423 } else if (parseUrl[2] && parseUrl[2] === "OFF=update") {424 parseUrl[2] = "OK=update"425 newUrl = parseUrl[0] + "?" + parseUrl[1] + "?" + parseUrl[2]426 } else {427 newUrl = backURL428 }429 return res.redirect(newUrl)430 } else {431 return res.redirect(backURL + "?OK=update")432 }433 });434 }435 });436 },...

Full Screen

Full Screen

deny-list.browser.js

Source:deny-list.browser.js Github

copy

Full Screen

...11test('domain-only blocks all subdomains and all paths', function(t) {12 setDenyList([13 'foo.com'14 ])15 t.equals(shouldCollectEvent(parseUrl('http://foo.com')), false)16 t.equals(shouldCollectEvent(parseUrl('http://foo.com/')), false)17 t.equals(shouldCollectEvent(parseUrl('http://foo.com/a')), false)18 t.equals(shouldCollectEvent(parseUrl('http://foo.com/a/b')), false)19 t.equals(shouldCollectEvent(parseUrl('http://www.foo.com')), false)20 t.equals(shouldCollectEvent(parseUrl('http://a.b.foo.com')), false)21 t.equals(shouldCollectEvent(parseUrl('http://a.b.foo.com/c/d')), false)22 t.equals(shouldCollectEvent(parseUrl('http://oo.com')), true, 'regression for length comparison')23 // other domains are allowed24 t.equals(shouldCollectEvent(parseUrl('http://bar.com')), true)25 t.end()26})27test('subdomain blocks further subdomains, but not parent domain', function(t) {28 setDenyList([29 'bar.foo.com'30 ])31 // deny32 t.equals(shouldCollectEvent(parseUrl('http://bar.foo.com')), false)33 t.equals(shouldCollectEvent(parseUrl('http://a.bar.foo.com')), false)34 // allow35 t.equals(shouldCollectEvent(parseUrl('http://foo.com')), true)36 t.equals(shouldCollectEvent(parseUrl('http://bar.com')), true)37 t.end()38})39test('* blocks all domains', function(t) {40 setDenyList([41 '*'42 ])43 // deny44 t.equals(shouldCollectEvent(parseUrl('http://foo.com')), false)45 t.equals(shouldCollectEvent(parseUrl('http://bar.com')), false)46 t.equals(shouldCollectEvent(parseUrl('http://a.foo.com')), false)47 t.equals(shouldCollectEvent(parseUrl('http://a.bar.com')), false)48 t.end()49})50test('path is blocking only with exact match', function(t) {51 setDenyList([52 'foo.com/a'53 ])54 t.equals(shouldCollectEvent(parseUrl('http://foo.com/a')), false)55 t.equals(shouldCollectEvent(parseUrl('http://foo.com')), true)56 t.equals(shouldCollectEvent(parseUrl('http://foo.com/b')), true)57 t.equals(shouldCollectEvent(parseUrl('http://foo.com/a/b')), true)58 setDenyList([59 'foo.com/a/b'60 ])61 t.equals(shouldCollectEvent(parseUrl('http://foo.com/a/b')), false)62 t.equals(shouldCollectEvent(parseUrl('http://foo.com/a')), true)63 t.end()64})65test('* blocks all domains', function(t) {66 setDenyList([67 '*'68 ])69 // deny70 t.equals(shouldCollectEvent(parseUrl('http://foo.com')), false)71 t.equals(shouldCollectEvent(parseUrl('http://bar.com')), false)72 t.equals(shouldCollectEvent(parseUrl('http://a.foo.com')), false)73 t.equals(shouldCollectEvent(parseUrl('http://a.bar.com')), false)74 t.end()75})76test('protocol is ignored when not specified', function(t) {77 setDenyList([78 'foo.com'79 ])80 t.equals(shouldCollectEvent(parseUrl('http://foo.com')), false)81 t.equals(shouldCollectEvent(parseUrl('https://foo.com')), false)82 t.end()83})84test('port is ignored when not specified', function(t) {85 setDenyList([86 'foo.com'87 ])88 t.equals(shouldCollectEvent(parseUrl('http://foo.com:8080')), false)89 t.equals(shouldCollectEvent(parseUrl('http://foo.com:8181')), false)90 t.end()91})92// test unexpected strings that don't represent URLs93test('invalid values', function(t) {94 setDenyList([95 '!@$%^*'96 ])97 t.equals(shouldCollectEvent(parseUrl('http://foo.com')), true)98 t.equals(shouldCollectEvent(parseUrl('http://bar.com')), true)99 setDenyList([100 '!@$%^*',101 'foo.com'102 ])103 t.equals(shouldCollectEvent(parseUrl('http://foo.com')), false)104 t.equals(shouldCollectEvent(parseUrl('http://bar.com')), true)105 t.end()106})107test('URL that contains protocol multiple times', function(t) {108 setDenyList([109 'https://example.com/http://foo.bar/'110 ])111 t.equals(shouldCollectEvent(parseUrl('https://example.com/http://foo.bar/')), false)112 t.equals(shouldCollectEvent(parseUrl('https://example.com')), true)113 setDenyList([114 'example.com'115 ])116 t.equals(shouldCollectEvent(parseUrl('https://example.com/http://foo.bar/')), false)117 t.end()...

Full Screen

Full Screen

iconGuesses.js

Source:iconGuesses.js Github

copy

Full Screen

1function parseUrl(url) {2 const a = document.createElement('a');3 a.href = url;4 return a;5}6const iconGuesses = [7 { fn: () => true, val: 'fas fa-link' },8 {9 fn: url => parseUrl(url).hostname.endsWith('behance.net'),10 val: 'fab fa-behance',11 },12 {13 fn: url => parseUrl(url).hostname.endsWith('blogger.com'),14 val: 'fab fa-blogger',15 },16 {17 fn: url => parseUrl(url).hostname.endsWith('bitbucket.org'),18 val: 'fab fa-bitbucket',19 },20 {21 fn: url => parseUrl(url).hostname.endsWith('codepen.io'),22 val: 'fab fa-codepen',23 },24 {25 fn: url => parseUrl(url).hostname.endsWith('deviantart.com'),26 val: 'fab fa-deviantart',27 },28 {29 fn: url => parseUrl(url).hostname.endsWith('discordapp.com'),30 val: 'fab fa-discord',31 },32 {33 fn: url => parseUrl(url).hostname.endsWith('dribbble.com'),34 val: 'fab fa-dribbble',35 },36 { fn: url => parseUrl(url).hostname.endsWith('ello.co'), val: 'fab fa-ello' },37 {38 fn: url => parseUrl(url).hostname.endsWith('etsy.com'),39 val: 'fab fa-etsy',40 },41 {42 fn: url => parseUrl(url).hostname.endsWith('facebook.com'),43 val: 'fab fa-facebook',44 },45 {46 fn: url => parseUrl(url).hostname.endsWith('github.com'),47 val: 'fab fa-github',48 },49 {50 fn: url => parseUrl(url).hostname.endsWith('gitlab.com'),51 val: 'fab fa-gitlab',52 },53 {54 fn: url => parseUrl(url).hostname.endsWith('goodreads.com'),55 val: 'fab fa-goodreads',56 },57 {58 fn: url => parseUrl(url).hostname.endsWith('instagram.com'),59 val: 'fab fa-instagram',60 },61 {62 fn: url => parseUrl(url).hostname.endsWith('keybase.io'),63 val: 'fab fa-keybase',64 },65 {66 fn: url => parseUrl(url).hostname.endsWith('kickstarter.com'),67 val: 'fab fa-kickstarter',68 },69 {70 fn: url => parseUrl(url).hostname.endsWith('last.fm'),71 val: 'fab fa-lastfm',72 },73 {74 fn: url => parseUrl(url).hostname.endsWith('medium.com'),75 val: 'fab fa-medium',76 },77 {78 fn: url => parseUrl(url).hostname.endsWith('patreon.com'),79 val: 'fab fa-patreon',80 },81 {82 fn: url => parseUrl(url).hostname.endsWith('paypal.com'),83 val: 'fab fa-paypal',84 },85 {86 fn: url => parseUrl(url).hostname.endsWith('pinterest.com'),87 val: 'fab fa-pinterest',88 },89 {90 fn: url => parseUrl(url).hostname.endsWith('plus.google.com'),91 val: 'fab fa-google-plus-g',92 },93 {94 fn: url => parseUrl(url).hostname.endsWith('ravelry.com'),95 val: 'fab fa-ravelry',96 },97 {98 fn: url => parseUrl(url).hostname.endsWith('reddit.com'),99 val: 'fab fa-reddit',100 },101 {102 fn: url => parseUrl(url).hostname.endsWith('skype.com'),103 val: 'fab fa-skype',104 },105 {106 fn: url => parseUrl(url).hostname.endsWith('slack.com'),107 val: 'fab fa-slack',108 },109 {110 fn: url => parseUrl(url).hostname.endsWith('snapchat.com'),111 val: 'fab fa-snapchat',112 },113 {114 fn: url => parseUrl(url).hostname.endsWith('soundcloud.com'),115 val: 'fab fa-soundcloud',116 },117 {118 fn: url => parseUrl(url).hostname.endsWith('stackoverflow.com'),119 val: 'fab fa-stackoverflow',120 },121 {122 fn: url => parseUrl(url).hostname.endsWith('steamcommunity.com'),123 val: 'fab fa-steam',124 },125 {126 fn: url => parseUrl(url).hostname.endsWith('teamspeak.com'),127 val: 'fab fa-teamspeak',128 },129 {130 fn: url => parseUrl(url).hostname.endsWith('tumblr.com'),131 val: 'fab fa-tumblr',132 },133 {134 fn: url => parseUrl(url).hostname.endsWith('twitch.tv'),135 val: 'fab fa-twitch',136 },137 {138 fn: url => parseUrl(url).hostname.endsWith('twitter.com'),139 val: 'fab fa-twitter',140 },141 {142 fn: url => parseUrl(url).hostname.endsWith('untappd.com'),143 val: 'fab fa-untappd',144 },145 {146 fn: url => parseUrl(url).hostname.endsWith('vimeo.com'),147 val: 'fab fa-vimeo',148 },149 {150 fn: url => parseUrl(url).hostname.endsWith('youtube.com'),151 val: 'fab fa-youtube',152 },153 {154 fn: url => parseUrl(url).hostname.includes('pora'),155 val: 'fab fa-diaspora',156 },157 {158 fn: url => parseUrl(url).hostname.includes('mastodon'),159 val: 'fab fa-mastodon',160 },161 { fn: url => parseUrl(url).protocol === 'mailto:', val: 'fas fa-envelope' },162];...

Full Screen

Full Screen

6.dependent.urlRelation.js

Source:6.dependent.urlRelation.js Github

copy

Full Screen

...9 it("should work", function(done)10 {11 var urlObj1,urlObj2;12 13 urlObj1 = parseUrl("http://fakeurl.com/dir1/dir2/index.html");14 urlObj2 = parseUrl("http://fakeurl.com/dir1/dir2/index.html");15 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.HASH);16 17 urlObj1 = parseUrl("http://fakeurl.com/dir1/dir2/index.html");18 urlObj2 = parseUrl("");19 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.HASH);20 21 urlObj1 = parseUrl("http://fakeurl.com/dir1/dir2/");22 urlObj2 = parseUrl("http://fakeurl.com/dir1/dir2/index.html");23 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.HASH);24 25 urlObj1 = parseUrl("http://fakeurl.com/dir1/dir2/");26 urlObj2 = parseUrl("");27 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.HASH);28 29 urlObj1 = parseUrl("http://fakeurl.com/dir1/dir2/index.html#hash");30 urlObj2 = parseUrl("http://fakeurl.com/dir1/dir2/index.html");31 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.PATH);32 33 urlObj1 = parseUrl("http://fakeurl.com/dir1/dir2/index.html#hash");34 urlObj2 = parseUrl("");35 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.PATH);36 37 urlObj1 = parseUrl("http://fakeurl.com/dir1/dir2/index.html?query");38 urlObj2 = parseUrl("http://fakeurl.com/dir1/dir2/index.html");39 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.FILENAME);40 41 urlObj1 = parseUrl("http://fakeurl.com/dir1/dir2/index.html?query");42 urlObj2 = parseUrl("");43 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.HASH);44 45 urlObj1 = parseUrl("http://fakeurl.com/dir1/dir2/index.html?query");46 urlObj2 = parseUrl("?query");47 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.HASH);48 49 urlObj1 = parseUrl("http://fakeurl.com/dir1/dir2/index.html?query");50 urlObj2 = parseUrl("#hash");51 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.PATH);52 53 urlObj1 = parseUrl("http://fakeurl.com/dir1/dir2/index2.html");54 urlObj2 = parseUrl("http://fakeurl.com/dir1/dir2/index1.html");55 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.DIRECTORY);56 57 urlObj1 = parseUrl("http://fakeurl.com/dir1/dir2/index2.html");58 urlObj2 = parseUrl("http://fakeurl.com/dir1/dir2/index.html");59 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.DIRECTORY);60 61 urlObj1 = parseUrl("http://fakeurl.com/dir1/index.html");62 urlObj2 = parseUrl("http://fakeurl.com/dir1/dir2/index.html");63 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.AUTH);64 65 urlObj1 = parseUrl("http://fakeurl.com/index.html");66 urlObj2 = parseUrl("http://fakeurl.com/dir1/dir2/index.html");67 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.AUTH);68 69 urlObj1 = parseUrl("http://fakeurl.com:81/dir1/dir2/index.html");70 urlObj2 = parseUrl("http://fakeurl.com/dir1/dir2/index.html");71 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.HOSTNAME);72 73 urlObj1 = parseUrl("http://fakeurl2.com/dir1/dir2/index.html");74 urlObj2 = parseUrl("http://fakeurl.com/dir1/dir2/index.html");75 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.PROTOCOL);76 77 urlObj1 = parseUrl("https://fakeurl.com/dir1/dir2/index.html");78 urlObj2 = parseUrl("http://fakeurl.com/dir1/dir2/index.html");79 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.NOTHING);80 81 urlObj1 = parseUrl("http://fakeurl.com/dir1/dir2/filename.html?query");82 urlObj2 = parseUrl("");83 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.HASH);84 85 // Will not resolve paths because there is no `from` and `to`86 urlObj1 = parseUrl("https://fakeurl.com/index.html");87 urlObj2 = parseUrl("../../../index.html");88 expect( urlRelation(urlObj1,urlObj2) ).to.equal(UrlComponent.AUTH);89 90 done();91 });...

Full Screen

Full Screen

parseUrl.spec.js

Source:parseUrl.spec.js Github

copy

Full Screen

1import { should } from "chai";2import parseUrl from "../../src/util/parseUrl";3describe("parseUrl", () => {4 it("should parse the hash path", () => {5 parseUrl("foo.bar.com/#/foo").path.should.equal("/foo");6 parseUrl("foo.bar.com/#/foo#bar").path.should.equal("/foo");7 parseUrl("foo.bar.com/foo?x=y#/bar").path.should.equal("/bar");8 parseUrl("foo.bar.com/#/").path.should.equal("/");9 parseUrl("foo.bar.com/#").path.should.equal("/");10 parseUrl("foo.bar.com/").path.should.equal("/");11 parseUrl("foo.bar.com").path.should.equal("/");12 parseUrl("foo.bar.com#foo").path.should.equal("/foo");13 parseUrl("foo.bar.com#/foo/bar/baz").path.should.equal("/foo/bar/baz");14 parseUrl("foo.bar.com#/foo/bar/baz/").path.should.equal("/foo/bar/baz");15 }); 16 it("should parse the hash search parameters", () => {17 parseUrl("foo.com/bar?x=y#?map-center=48.12,8.21").params["map-center"].should.equal("48.12,8.21");18 parseUrl("foo.com#?a=b&c=d").params.should.eql({a: "b", c:"d"});19 }); 20 it("should keep the original url", () => {21 parseUrl("foo.com/foo?bar=baz#hash/path?x=5").original.should.equal("foo.com/foo?bar=baz#hash/path?x=5");22 });23 it("should create a parsed url string", () => {24 parseUrl("foo.com/a/b?x=d#bar/baz/?baz=5").actual.should.equal("/bar/baz?baz=5");25 });26 it("should retrieve a value from a url that contains a subpage with .html-ending", () => {27 parseUrl("foo.com/businesscard.html#/?entry=5e7cbd595bd34d4fa9d8f26444c3a655")28 .params.entry.should.equal("5e7cbd595bd34d4fa9d8f26444c3a655");29 });...

Full Screen

Full Screen

common.test.js

Source:common.test.js Github

copy

Full Screen

1/* eslint no-unused-expressions: "off" */2require('should');3const parseUrl = require('../src/common');4describe('common.js', () => {5 describe('#parseUrl()', () => {6 const URL = 'http://www.abc.com';7 it('should return {} when url is empty', () => {8 parseUrl('').should.be.empty;9 });10 it('should return {} when url without "="', () => {11 parseUrl(`${URL}`).should.be.empty;12 parseUrl(`${URL}?`).should.be.empty;13 parseUrl(`${URL}?&`).should.be.empty;14 });15 it('should return {} when url without key', () => {16 parseUrl(`${URL}?=123`).should.be.empty;17 parseUrl(`${URL}?=123&`).should.be.empty;18 parseUrl(`${URL}?&=123`).should.be.empty;19 });20 it('should return a object', () => {21 parseUrl(`${URL}?name`).should.be.eql({ name: '' });22 parseUrl(`${URL}?name=`).should.be.eql({ name: '' });23 parseUrl(`${URL}?name=123`).should.be.eql({ name: '123' });24 parseUrl(`${URL}?name=123&age`).should.be.eql({ name: '123', age: '' });25 parseUrl(`${URL}?name=123&=`).should.be.eql({ name: '123' });26 parseUrl(`${URL}?name=123&&`).should.be.eql({ name: '123' });27 parseUrl(`${URL}?&name=123`).should.be.eql({ name: '123' });28 parseUrl(`${URL}?name=123&age=12`).should.be.eql({ name: '123', age: '12' });29 });30 });...

Full Screen

Full Screen

parseUrl.test.js

Source:parseUrl.test.js Github

copy

Full Screen

2describe('Function parseUrl', () => {3 test('works with correct data', () => {4 const url1 = 'https://domen/main/5/';5 const url2 = 'https://domen/about/3/';6 expect(parseUrl(url1).id).toBe('5');7 expect(parseUrl(url1).dataType).toBe('main');8 expect(parseUrl(url2).id).toBe('3');9 expect(parseUrl(url2).dataType).toBe('about');10 });11 test('works with incorrect data', () => {12 const url1 = 'https://domen/main/5';13 const url2 = 'https://domen/3/';14 const url3 = '/domen/main/5/';15 expect(parseUrl(url1).id).toBeNull();16 expect(parseUrl(url1).dataType).toBeNull();17 expect(parseUrl(url2).id).toBeNull();18 expect(parseUrl(url2).dataType).toBeNull();19 expect(parseUrl(url3).id).toBeNull();20 expect(parseUrl(url3).dataType).toBeNull();21 });22 test('works without data', () => {23 const url1 = '';24 const url2 = undefined;25 expect(parseUrl(url1).id).toBeNull();26 expect(parseUrl(url1).dataType).toBeNull();27 expect(parseUrl(url2).id).toBeNull();28 expect(parseUrl(url2).dataType).toBeNull();29 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { RequestHook } from 'testcafe';2import { parseUrl } from 'url';3class MyHook extends RequestHook {4 constructor (requestFilterRules, responseEventConfigureOpts) {5 super(requestFilterRules, responseEventConfigureOpts);6 }7 async onRequest (event) {8 const parsedUrl = parseUrl(event.requestOptions.url);9 console.log(parsedUrl);10 }11}12export default MyHook;13import { RequestHook } from 'testcafe';14import { parseUrl } from 'url';15class MyHook extends RequestHook {16 constructor (requestFilterRules, responseEventConfigureOpts) {17 super(requestFilterRules, responseEventConfigureOpts);18 }19 async onRequest (event) {20 const parsedUrl = parseUrl(event.requestOptions.url);21 console.log(parsedUrl);22 }23}24export default MyHook;25You can also import the parseUrl method from Node's url module in the test.js file. In this case, the parseUrl method of Node's url

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parseUrl } from 'testcafe-hammerhead';2import { parseProxyUrl } from 'testcafe-hammerhead';3import { resolveUrlAsDest } from 'testcafe-hammerhead';4import { resolveUrlAsProxyUrl } from 'testcafe-hammerhead';5import { stringifyResourceType } from 'testcafe-hammerhead';6const resourceTypeString = stringifyResourceType('script');7import { isSupportedProtocol } from 'testcafe-hammerhead';8import { isSpecialPage } from 'testcafe-hammerhead';9import { isShadowUIElement } from 'testcafe-hammerhead';10import { isShadowUIElement } from 'testcafe-hammerhead';11import { isShadowUIElement } from 'testcafe-hammerhead';12import { isIE } from 'testcafe-hammerhead';13const isIE = isIE();14import { isIE9 } from 'testcafe-hammerhead';15const isIE9 = isIE9();

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parseUrl } from 'testcafe-hammerhead';2test('Check url', async t => {3 await t.expect(parsedUrl.protocol).eql('http:');4 await t.expect(parsedUrl.host).eql('example.com:8080');5 await t.expect(parsedUrl.hostname).eql('example.com');6 await t.expect(parsedUrl.port).eql('8080');7 await t.expect(parsedUrl.pathname).eql('/pathname/');8 await t.expect(parsedUrl.search).eql('?search=test');9 await t.expect(parsedUrl.hash).eql('#hash');10});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parseUrl } from 'testcafe-hammerhead';2const url = require('url');3import { Selector } from 'testcafe';4import { parseUrl } from 'testcafe-hammerhead';5test('My Test', async t => {6 await t.expect(url.protocol).eql('http:');7 await t.expect(url.host).eql('example.com');8 await t.expect(url.port).eql('80');9 await t.expect(url.hostname).eql('example.com');10 await t.expect(url.pathname).eql('/path');11 await t.expect(url.search).eql('?param=value');12 await t.expect(url.hash).eql('');13});14import { Selector } from 'testcafe';15import { ClientFunction } from 'testcafe';16import { parseUrl } from

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parseUrl } from 'testcafe';2const parsedUrl = parseUrl(url);3console.log(parsedUrl);4{5}6import { parseUrl } from 'testcafe';7const parsedUrl = parseUrl(url);8console.log(parsedUrl);9{10}11import { parseUrl } from 'testcafe';12const parsedUrl = parseUrl(url);13console.log(parsedUrl);14{15}16import { parseUrl } from 'testcafe';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parseUrl } from 'testcafe-hammerhead';2test('TestCafe', async t => {3 await t.expect(url.protocol).eql('http:');4});5import { parseUrl } from 'testcafe-hammerhead';6test('TestCafe', async t => {7 await t.expect(url.protocol).eql('http:');8});9import { parseUrl } from 'testcafe/lib/utils/url';10Your name to display (optional):11Your name to display (optional):12import { parseUrl } from 'testcafe-hammerhead';13Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1import {ClientFunction} from 'testcafe';2const parseUrl = ClientFunction(() => {3 return window.location.href;4});5test('Test', async t => {6 await t.expect(parseUrl()).contains('example');7});8import { parseURL } from 'testcafe-browser-provider-electron';9test('Test', async t => {10 await t.expect(parseURL()).contains('example');11});12import { parseURL } from 'testcafe-browser-provider-electron';13test('Test', async t => {14 await t.expect(parseURL('windowName')).contains('example');15});16import { parseURL } from 'testcafe-browser-provider-chrome';17test('Test', async t => {18 await t.expect(parseURL()).contains('example');19});20import { parseURL } from 'testcafe-browser-provider-chrome';21test('Test',

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parseUrl } from 'testcafe-hammerhead';2test('Test', async t => {3 const url = parseUrl(testUrl);4 console.log(url);5});6export function parseUrl (url) {7 const parsed = urlUtils.parseProxyUrl(url);8 return parsed ? parsed.destUrl : url;9}10export function parseUrl (url) {11 const parsed = urlUtils.parseProxyUrl(url);12 return parsed ? parsed.destUrl : url;13}14export function parseUrl (url) {15 const parsed = urlUtils.parseProxyUrl(url);16 return parsed ? parsed.destUrl : url;17}18export function parseUrl (url) {19 const parsed = urlUtils.parseProxyUrl(url);20 return parsed ? parsed.destUrl : url;21}22export function parseUrl (url) {23 const parsed = urlUtils.parseProxyUrl(url);24 return parsed ? parsed.destUrl : url;25}26export function parseUrl (url) {27 const parsed = urlUtils.parseProxyUrl(url);28 return parsed ? parsed.destUrl : url;29}30export function parseUrl (url) {31 const parsed = urlUtils.parseProxyUrl(url);32 return parsed ? parsed.destUrl : url;33}34export function parseUrl (url) {35 const parsed = urlUtils.parseProxyUrl(url);36 return parsed ? parsed.destUrl : url;37}38export function parseUrl (url) {39 const parsed = urlUtils.parseProxyUrl(url);40 return parsed ? parsed.destUrl : url;41}42export function parseUrl (url) {43 const parsed = urlUtils.parseProxyUrl(url);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parseUrl } from 'testcafe-hammerhead';2console.log(testUrl);3import { parseUrl } from 'testcafe-hammerhead';4console.log(testUrl);5import { parseUrl } from 'testcafe-hammerhead';6console.log(testUrl);7import { parseUrl } from 'testcafe-hammerhead';8console.log(testUrl);9import { parseUrl } from 'testcafe-hammerhead';10console.log(testUrl);11import { parseUrl } from 'testcafe-hammerhead';12console.log(testUrl);13import { parseUrl } from 'testcafe-hammerhead';14console.log(testUrl);15import { parseUrl } from 'testcafe-hammerhead';16console.log(testUrl);17import { parseUrl } from 'testcafe-hammerhead';18console.log(testUrl);19import { parseUrl } from 'testcafe-hammerhead';20console.log(testUrl);21import { parseUrl } from 'testcafe-hammerhead';

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcafe automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful