Best JavaScript code snippet using best
lab.js
Source:lab.js
1/*2*/3function start(e) {4 $(document).mousemove(function(event){5 var p = $( "#svgimage2");6 var position = p.position();7 console.log('position = ' + position.left + ', ' + position.top);8 var myX = event.pageX - Math.round(position.left); // - 159 var myY = event.pageY - Math.round(position.top) + 500; // - 1510 11 $("#s5").html("<div style='position:absolute; border-style:none; TOP:"12 + event.pageY + "px; LEFT:"13 + event.pageY + "px; '>" + "&nbs &nbs ("14 + myX + ", "15 + myY + ")"16 + "</div>");17 });18}19function analyze() {20 var m, n;21 var remain = document.getElementById('content').textContent;22 //console.log('remain = ' + remain);23 var subs = '';24 var i = 0;25 do {26 i++;27 m = remain.search("<path");28 console.log('m = ' + m);29 remain = remain.slice(m);30 if ( m == -1){ // skip 31 return;32 }33 m = remain.search('d=');34 console.log('d= m = ' + m);35 remain = remain.slice(m);36 m = remain.search(/m/i);37 console.log('m m = ' + m);38 n = remain.search(/m/i);39 console.log('z n = ' + n);40 subs = remain.slice(m, n+1); // z ä¹è¦å
å«41 console.log('subs = ' + subs);42 43 var subs2 = subs.replace('440', '480');44 var subs2 = subs2.replace('462', '262');45 46 var path = image.path(subs).fill('black').stroke({color:'grey', width:5}).draggable();47 //remain = remain.slice(n+1); // z ä¹è¦ç§»é¤48 //console.log('remain = ' + remain);49 //var pathString = "M382 371C440 281 80 162 82 314 84 467 324 462 382 371z"50 //var newPath = Snap.path.toCubic(pathString);51 path.plot(subs2).draggable();52 //path.animate(2000).plot(subs2).loop(true, true).draggable();53 var newPath = Snap.path.toCubic(subs);54 console.log(' newPath.length = ' + newPath.length);55 console.table(' newPath = ' + newPath);56 57 newPath.forEach(function(element) {58 console.log(element);59 });60 for (var i = 0; i < (newPath.length - 1); i++) {61 for (var j = 0; j < newPath[i].length; j++) {62 console.log(' newPath[' + i + '][j] = ' + newPath[i][j] );63 }64 // if ( newPath[i][1] == 'M' || newPath[i][1] == 'm' ) { //M i == 065 if ( i == 0 ){ //M i ==066 var circle = image.circle(20).fill('red').stroke('blue').move(newPath[i][1]-10, newPath[i][2]-10).draggable();67 } else { C68 var circle = image.circle(10).fill('pink').stroke('blue').move(newPath[i][1]-5, newPath[i][2]-5).draggable();69 var circle = image.circle(10).fill('pink').stroke('blue').move(newPath[i][3]-5, newPath[i][4]-5).draggable();70 var circle = image.circle(10).fill('pink').stroke('blue').move(newPath[i][5]-5, newPath[i][6]-5).draggable();71 }72 }73 //for(var i = 0; i < newPath.length; i++){74 //for(var i = 0; i < (newPath.length - 1); i++){ //æµé·å çº z èå¤åºäºçæå¾ä¸åé»75 // for(var i = 0; i < (newPath.length - 1); i++){ //æµé·å çº z èå¤åºäºçæå¾ä¸åé»76 // var segment = newPath[i], point;77 // segment.shift();78 // point = setUpPoint(segment);79 // }80 m = subs.search(/c/i);81 console.log('m = subs.search(/c/i);');82 console.log('m = ' + m);83 n = subs.search(/z/i);84 console.log('n = subs.search(/z/i);');85 console.log('n = ' + n);86 //move = 382 37187 var move = '';88 move = subs.slice(1, m);89 console.log('move.length = ' + move.length);90 console.log('move = ' + move);91 // https://stackoverflow.com/questions/40282519/split-string-by-multiple-spaces-nodejs92 var temp;93 temp = move.trim().split(/\s+/);94 console.log('temp.length = ' + temp.length);95 console.log('temp = ' + temp);96 console.log('temp[0] = ' + temp[0]);97 console.log('temp[1] = ' + temp[1]);98 99 var x, y;100 x = parseInt(temp[0],10);101 y = parseInt(temp[1],10);102 console.log('x = ' + x);103 console.log('y = ' + y);104 var circle = image.circle(20).fill('red').stroke('blue').move(x-10, y-10).draggable();105 /*106 temp.forEach(function(element) {107 newPath.push(element);108 });109 */110 var newPath = [];111 console.log('newPath = ' + newPath);112 subs = subs.slice(m+1, n); // C ä¹è¦ç§»é¤ (大寫C), z ä¹è¦ç§»é¤ 113 console.log('subs = ' + subs);114 temp = subs.trim().split(/\s+/);115 /*116 temp.forEach(function(element) {117 newPath.push(element);118 });119 */120 newPath.push([temp[0],temp[1]]);121 console.log('newPath = ' + newPath);122 //var newPath = Snap.path.toCubic(subs);123 console.log(' newPath.length = ' + newPath.length);124 /*125 //for(var i = 0; i < newPath.length; i++){126 //for(var i = 0; i < (newPath.length - 1); i++){ // æµé·å çº z èå¤åºäºçæå¾ä¸åé»127 for(var i = 0; i < (newPath.length - 1); i++){ // æµé·å çº z èå¤åºäºçæå¾ä¸åé»128 var segment = newPath[i], point;129 segment.shift();130 point = setUpPoint(segment);131 }132 */133 } while (m > 0);134}135function saveText(text, filename) {136 var a = document.createElement('a');137 a.setAttribute('href', 'data:text/plain;charset=utf-u,' + encodeURIComponent(text));138 a.setAttribute('download', filename);139 a.click()140}141function readFiles(files){142 // files is a FileList of File objects. List some properties.143 var output = [];144 for (var i = 0, f; f = files[i]; i++) {145 output.push('<li><strong>', escape(f.name), '</strong> (', f.type || 'n/a', ') - ',146 f.size, ' bytes, last modified: ',147 f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a',148 '</li>');149 }150 document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';151 //document.getElementById('content').innerHTML = ''; 152 //document.getElementById('svgimage').innerHTML = '';153 // Loop through the FileList and render image files as thumbnails.154 for (var i = 0, f; f = files[i]; i++) {155 var reader = new FileReader();156 reader.readAsText(files[i], 'UTF-8');157 reader.onload = function(evt) {158 document.getElementById('content').innerHTML = evt.target.result;159 document.getElementById('svgimage').innerHTML = evt.target.result;160 // svg.js161 image = SVG('svgimage2').size(512, 512); // global162 image.svg(document.getElementById('content').textContent);163 //console.log(document.getElementById('content').textContent);164 analyze();165 }166 }167}168function handleFileSelect(evt) {169 var files = evt.target.files; // FileList object170 readFiles(files);171}172function handleFileSelect_drag(evt) {173 evt.stopPropagation();174 evt.preventDefault();175 var files = evt.dataTransfer.files; // FileList object.176 readFiles(files);177}178function handleDragOver(evt) {179 evt.stopPropagation();180 evt.preventDefault();181 evt.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.182}183function start(e) {184 document.getElementById('files').addEventListener('change', handleFileSelect, false);185 var dropZone = document.getElementById('drop_zone');186 dropZone.addEventListener('dragover', handleDragOver, false);187 dropZone.addEventListener('drop', handleFileSelect_drag, false);188 // listener189 document.getElementById('content').addEventListener("input", function(){190 document.getElementById('svgimage').innerHTML = document.getElementById('content').value;191 });192 document.getElementById('save').addEventListener("click", function(){193 var fn = document.getElementById('svgfilename').value;194 saveText( document.getElementById('content').value , fn);195 });196 // animation197 setInterval(function(){ 198 document.getElementById("drop_zone").style.borderColor = "Crimson";199 document.getElementById("drop_zone").style.color = "Crimson";200 document.getElementById("files").style.color = "Crimson";201 }, 500);202 setInterval(function(){ 203 document.getElementById("drop_zone").style.borderColor = "gray";204 document.getElementById("drop_zone").style.color = "gray";205 document.getElementById("files").style.color = "gray";206 }, 1000);207}...
pathTransformer.ts
Source:pathTransformer.ts
1import {Path} from "../Path";2import {Operation} from "../action/Operation";3export function pathTransform(path: Path, operation: Operation, options: { affinity?: 'forward' | 'backward' | null } = {}): Path | null {4 const { affinity = 'forward' } = options5 if (path.length === 0) return path;6 if (operation.type === "insert_node") {7 if (Path.equals(operation.path, path) || Path.endsBefore(operation.path, path) || Path.isAncestor(operation.path, path)) {8 let newPath = [...path];9 newPath[operation.path.length - 1] += 1;10 return newPath;11 } else {12 return path;13 }14 } else if (operation.type === "remove_node") {15 if (Path.equals(operation.path, path) || Path.isAncestor(operation.path, path)) {16 return null;17 } else if (Path.endsBefore(operation.path, path)) {18 let newPath = [...path];19 newPath[operation.path.length - 1] -= 120 return newPath;21 } else {22 return path;23 }24 } else if (operation.type === "merge_node") {25 if (Path.equals(operation.path, path) || Path.endsBefore(operation.path, path)) {26 let newPath = [...path];27 newPath[operation.path.length - 1] -= 128 return newPath;29 } else if (Path.isAncestor(operation.path, path)) {30 let newPath = [...path];31 newPath[operation.path.length - 1] -= 132 newPath[operation.path.length] += operation.position33 return newPath;34 } else {35 return path;36 }37 } else if (operation.type === "split_node") {38 if (Path.equals(operation.path, path)) {39 if (affinity === 'forward') {40 let newPath = [...path];41 newPath[path.length - 1] += 142 return newPath;43 } else if (affinity === 'backward') {44 // Nothing, because it still refers to the right path.45 return path;46 } else {47 return null;48 }49 } else if (Path.endsBefore(operation.path, path)) {50 let newPath = [...path];51 newPath[operation.path.length - 1] += 152 return newPath;53 } else if (Path.isAncestor(operation.path, path) && path[operation.path.length] >= operation.position) {54 let newPath = [...path];55 newPath[operation.path.length - 1] += 1;56 newPath[operation.path.length] -= operation.position;57 return newPath;58 } else {59 return path;60 }61 } else if (operation.type === "move_node") {62 if (Path.equals(operation.path, operation.newPath)) {63 return path;64 }65 if (Path.isAncestor(operation.path, path) || Path.equals(operation.path, path)) {66 let newPath = [...operation.newPath];67 if (Path.endsBefore(operation.path, operation.newPath) && operation.path.length < operation.newPath.length) {68 newPath[operation.path.length - 1] -= 169 }70 return newPath.concat(path.slice(operation.path.length));71 } else if (Path.isSibling(operation.path, operation.newPath) && (Path.isAncestor(operation.newPath, path) || Path.equals(operation.newPath, path))) {72 if (Path.endsBefore(operation.path, path)) {73 let newPath = [...path];74 newPath[operation.path.length - 1] -= 1;75 return newPath;76 } else {77 let newPath = [...path];78 newPath[operation.path.length - 1] += 1;79 return newPath;80 }81 } else if (Path.endsBefore(operation.newPath, path) || Path.equals(operation.newPath, path) || Path.isAncestor(operation.newPath, path)) {82 let newPath = [...path];83 if (Path.endsBefore(operation.path, path)) {84 newPath[operation.path.length - 1] -= 185 }86 newPath[operation.newPath.length - 1] += 187 return newPath;88 } else if (Path.endsBefore(operation.path, path)) {89 let newPath = [...path];90 if (Path.equals(operation.newPath, path)) {91 newPath[operation.newPath.length - 1] += 192 }93 newPath[operation.path.length - 1] -= 194 return newPath;95 } else {96 return path;97 }98 } else {99 return path;100 }...
get-docs-path-from-developer-path.js
Source:get-docs-path-from-developer-path.js
1const patterns = require('../patterns')2const { latest } = require('../enterprise-server-releases')3const { getVersionedPathWithLanguage } = require('../path-utils')4// This function takes a known pre-migration path from developer.github.com and5// infers and returns a current, correct docs.github.com path.6module.exports = function getDocsPathFromDeveloperPath (oldDeveloperPath, allRedirects, pageMap) {7 let newPath = oldDeveloperPath8 // Look up the old path in the redirects object BEFORE modifying /v3 and /v4 paths9 // in case there is a frontmatter redirect.10 // e.g. /v3/activity/event_types -> /en/developers/webhooks-and-events/github-event-types11 newPath = allRedirects[newPath] || newPath12 // oneoff redirect13 const v3OrgPreReceiveHooks = '/v3/orgs/pre_receive_hooks'14 if (newPath.endsWith(v3OrgPreReceiveHooks)) {15 newPath = newPath.replace(v3OrgPreReceiveHooks, '/v3/enterprise-admin/organization_pre_receive_hooks')16 }17 // oneoff redirect18 const v3RepoPreReceiveHooks = '/v3/repos/pre_receive_hooks'19 if (newPath.endsWith(v3RepoPreReceiveHooks)) {20 newPath = newPath.replace(v3RepoPreReceiveHooks, '/v3/enterprise-admin/repository_pre_receive_hooks')21 }22 // oneoff redirect23 const v3OrgHooks = '/v3/orgs/hooks'24 if (newPath.endsWith(v3OrgHooks)) {25 newPath = newPath.replace(v3OrgHooks, '/v3/orgs/webhooks')26 }27 // oneoff redirect28 const v3RepoHooks = '/v3/repos/hooks'29 if (newPath.endsWith(v3RepoHooks)) {30 newPath = newPath.replace(v3RepoHooks, '/v3/repos/webhooks')31 }32 // oneoff redirect for a dotcom developer path to Enterprise-only path on docs.github.com33 const oauthAuthorizations = '/v3/oauth_authorizations'34 if (newPath.endsWith(oauthAuthorizations)) {35 newPath = newPath.replace(oauthAuthorizations, '/enterprise-server/v3/oauth_authorizations')36 }37 // Change /v4/foo/bar to /v4/foo#bar38 // Change /v3/foo/bar to /v3/foo#bar39 // Then we can look up the hashless path in the redirect object,40 // get the new path like /graphql/reference/foo or /rest/reference/foo,41 // and add the #bar fragment back after.42 let fragment43 if (patterns.oldApiPath.test(newPath)) {44 // pathParts = [ '', 'v4', 'foo', 'bar' ]45 const pathParts = newPath.split('/')46 // lastSegment = bar47 const lastSegment = pathParts.pop()48 // newPath = /v4/foo49 newPath = pathParts.join('/')50 // Underscores in the final segment of REST paths (`/admin_stats`)51 // get changed to hyphens when they become fragments (`#admin-stats`).52 // GraphQL paths rarely have underscores, but when they do, they are preserved (`__directive`).53 fragment = newPath.includes('/v3/')54 ? lastSegment55 .replace(/_/g, '-')56 // this is a special oneoff replacement57 .replace('org-pre-receive-hooks', 'organization-pre-receive-hooks')58 .replace('repo-pre-receive-hooks', 'repository-pre-receive-hooks')59 : lastSegment60 }61 // do a second lookup to find /v4/foo or /v3/foo without the last segment62 newPath = allRedirects[newPath] || newPath63 // old developer routes that include 'enterprise-admin' should always redirect to enterprise server64 if (fragment && newPath.includes('/rest/reference/enterprise-admin') && !patterns.enterpriseServer.test(newPath)) {65 newPath = getVersionedPathWithLanguage(newPath, `enterprise-server@${latest}`, 'en')66 }67 // show an error if the page to be redirected to doesn't exist68 // but only if the current collection of pages includes REST and GraphQL reference pages69 if (process.env.NODE_ENV !== 'test' && !pageMap[newPath] && pageMap['/en/rest/reference'] && pageMap['/en/graphql/reference']) {70 console.error(`can't find ${newPath}! based on ${oldDeveloperPath}`)71 }72 // add fragment back in and return73 return fragment74 ? newPath + '#' + fragment75 : newPath...
utils.ts
Source:utils.ts
1export const addSpaces = (path: any) => {2 let newPath = path;3 newPath = newPath.split('M').join(' M ');4 newPath = newPath.split('m').join(' m ');5 newPath = newPath.split('L').join(' L ');6 newPath = newPath.split('l').join(' l ');7 newPath = newPath.split('H').join(' H ');8 newPath = newPath.split('h').join(' h ');9 newPath = newPath.split('V').join(' V ');10 newPath = newPath.split('v').join(' v ');11 newPath = newPath.split('Q').join(' Q ');12 newPath = newPath.split('q').join(' q ');13 newPath = newPath.split('Z').join(' Z ');14 newPath = newPath.split('z').join(' z ');15 newPath = newPath.split(',').join(' ');16 newPath = newPath.split(' ').join(' ');17 return newPath.trim();18};19export const isJsonString = (str: string) => {20 try {21 JSON.parse(str);22 } catch (e) {23 return false;24 }25 return true;26};27export const getFontFileName = (metadata: string) => {28 return metadata.match(/[a-zA-Z0-9\[\]\-\,]*\.ttf/g);...
Using AI Code Generation
1var BestPath = require('./BestPath');2var bestPath = new BestPath();3var path = bestPath.newPath([1,2,3,4,5]);4console.log(path);5var BestPath = require('./BestPath');6var bestPath = new BestPath();7var path = bestPath.newPath([1,2,3,4,5]);8console.log(path);9var BestPath = require('./BestPath');10var bestPath = new BestPath();11var path = bestPath.newPath([1,2,3,4,5]);12console.log(path);13var BestPath = require('./BestPath');14var bestPath = new BestPath();15var path = bestPath.newPath([1,2,3,4,5]);16console.log(path);17var BestPath = require('./BestPath');18var bestPath = new BestPath();19var path = bestPath.newPath([1,2,3,4,5]);20console.log(path);21var BestPath = require('./BestPath');22var bestPath = new BestPath();23var path = bestPath.newPath([1,2,3,4,5]);24console.log(path);25var BestPath = require('./BestPath');26var bestPath = new BestPath();27var path = bestPath.newPath([1,2,3,4,5]);28console.log(path);
Using AI Code Generation
1var BestPath = require('./BestPath.js');2var path = new BestPath();3path.newPath(5, 6, 7, 8);4path.newPath(3, 4, 5, 6);5path.newPath(1, 2, 3, 4);6path.newPath(8, 9, 10, 11);7path.newPath(6, 7, 8, 9);8var BestPath = require('./BestPath.js');9var path = new BestPath();10path.newPath(5, 6, 7, 8);11path.newPath(3, 4, 5, 6);12path.newPath(1, 2, 3, 4);13path.newPath(8, 9, 10, 11);14path.newPath(6, 7, 8, 9);15path.newPath(10, 11, 12, 13);16path.newPath(12, 13, 14, 15);17path.newPath(14, 15, 16, 17);18path.newPath(16, 17, 18, 19);19path.newPath(18, 19, 20, 21);20path.newPath(20, 21, 22, 23);21path.newPath(22, 23, 24, 25);22path.newPath(24, 25, 26, 27);23path.newPath(26, 27, 28, 29);24path.newPath(28, 29, 30, 31);25path.newPath(30, 31, 32, 33);26path.newPath(32, 33, 34, 35);27path.newPath(34, 35, 36, 37);28path.newPath(36, 37, 38, 39);29path.newPath(38, 39, 40, 41);30path.newPath(40, 41, 42, 43);31path.newPath(42, 43, 44, 45);32path.newPath(44, 45, 46, 47);33path.newPath(46, 47, 48, 49);34path.newPath(48, 49,
Using AI Code Generation
1var BestRoute = require('./bestRoute.js');2var myBestRoute = new BestRoute();3var path = myBestRoute.newPath('A', 'C');4console.log(path);5module.exports = BestRoute;6function BestRoute() {7 this.newPath = function (start, end) {8 return 'A-B-C';9 }10}
Using AI Code Generation
1var br = require("./BestRoute");2var bestRoute = new br.BestRoute();3var path = bestRoute.newPath("a", "b", 5);4console.log(path);5var br = require("./BestRoute");6var bestRoute = new br.BestRoute();7bestRoute.addEdge("a", "b", 5);8bestRoute.addEdge("b", "c", 4);9bestRoute.addEdge("c", "d", 8);10bestRoute.addEdge("d", "c", 8);11bestRoute.addEdge("d", "e", 6);12bestRoute.addEdge("a", "d", 5);13bestRoute.addEdge("c", "e", 2);14bestRoute.addEdge("e", "b", 3);15bestRoute.addEdge("a", "e", 7);16console.log(bestRoute.graph);17{ a: [ { to: 'b', distance: 5 }, { to: 'd', distance: 5 }, { to: 'e', distance: 7 } ],18 b: [ { to: 'c', distance: 4 }, { to: 'e', distance: 3 } ],19 c: [ { to: 'd', distance: 8 }, { to: 'e', distance: 2 } ],20 d: [ { to: 'c', distance: 8 }, { to: 'e', distance: 6 } ],21 e: [ { to: 'b', distance: 3 } ] }22var br = require("./BestRoute");23var bestRoute = new br.BestRoute();24bestRoute.addEdge("a", "b", 5);25bestRoute.addEdge("b", "c", 4);26bestRoute.addEdge("c", "d", 8);27bestRoute.addEdge("d", "c", 8);28bestRoute.addEdge("d", "e", 6);29bestRoute.addEdge("a", "d", 5);30bestRoute.addEdge("c", "e", 2);31bestRoute.addEdge("e", "b
Using AI Code Generation
1var bestRouteFinder = require('./bestRouteFinder');2var path = require('path');3var routeFinder = new bestRouteFinder.BestRouteFinder();4var filePath = path.join(__dirname, 'data', 'routeData.csv');5routeFinder.newPath(filePath, 'A', 'B', function(err, route){6 if(err){7 console.log(err);8 }else{9 console.log(route);10 }11});
Using AI Code Generation
1var bestRoute = new BestRoute();2var map = new google.maps.Map(document.getElementById("map"), {3 center: {lat: 32.7157, lng: -117.1611},4});5var directionsDisplay = new google.maps.DirectionsRenderer();6var directionsService = new google.maps.DirectionsService();7var marker = new google.maps.Marker({8 position: {lat: 32.7157, lng: -117.1611},9});10var infowindow = new google.maps.InfoWindow({11});12google.maps.event.addListener(marker, 'click', function() {13 infowindow.open(map, marker);14});15google.maps.event.addListener(marker, 'dragend', function() {16 var pos = marker.getPosition();17 var latlng = new google.maps.LatLng(pos.lat(), pos.lng());18 var geocoder = new google.maps.Geocoder();19 geocoder.geocode({'location': latlng}, function(results, status) {20 if (status === google.maps.GeocoderStatus.OK) {21 if (results[1]) {22 var address = results[1].formatted_address;23 document.getElementById('start').value = address;24 }25 }26 });27});28document.getElementById('findRoute').addEventListener('click', function() {29 var start = document.getElementById('start').value;30 var end = document.getElementById('end').value;31 var mode = document.getElementById('travelMode').value;
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!!