Best JavaScript code snippet using best
Site_File.js
Source:Site_File.js  
1// Copyright 2000, 2001, 2002, 2003, 2004, 2005 Macromedia, Inc. All rights reserved.2	function receiveArguments()3	{		4		var itemID = arguments[0];5		var scope = arguments[1];6		var docPath;7		if (scope == 'site') 8		{9			docPath = "site";10		}11		else if (scope == 'document')12		{13			docPath = dw.getDocumentPath('document');14		}15		else if (scope == 'docSelection')16		{17			if (dw.getDocumentDOM())18			{19				docPath = dw.getDocumentDOM().getSelectionSrc();20			}21			else22			{23				return;24			}25		}26		if (itemID == "unlock")27		{28			if (scope == 'document')29			{30				dw.getDocumentDOM().makeEditable();31			}32			else33			{34				site.makeEditable();35			}36		}37		else if (itemID == "connect")38		{39			site.setConnectionState(!site.getConnectionState());40		}41		else if (itemID == "sethomepage")42		{43			site.setAsHomePage();44		}45		else if (itemID == "put")46		{47			if (site.canPut(docPath))48				site.put(docPath);49		}50		else if (itemID == "get")51		{52			if (site.canGet(docPath))53				site.get(docPath);54		}55		else if (itemID == "checkout")56		{57			if (site.canCheckOut(docPath))58				site.checkOut(docPath);59		}60		else if (itemID == "checkin")61		{62			if (site.canCheckIn(docPath))63				site.checkIn(docPath);64		}65		else if (itemID == "undocheckout")66		{67			if (site.canUndoCheckOut(docPath))68				site.undoCheckOut(docPath);69		}70		else if (itemID == "checkedoutby")71		{72			if (site.canShowCheckedOutBy(docPath))73				site.showCheckedOutBy(docPath);74		}75		else if (itemID == "findlocal")76		{77			site.locateInSite("local", docPath);78		}79		else if (itemID == "findremote")80		{81			site.locateInSite("remote", docPath);82		}83		else if (itemID == "findlocalremote")84		{85			site.locateInSite(site.getFocus(), docPath);86		}87		else if (itemID == "togglemap")88		{89			dw.toggleFloater('site map');90		}91		else if (itemID == "togglehidden")92		{93			site.toggleHiddenFiles();94		}95		else if (itemID == "compare")96		{97			site.compareFiles(docPath)98		}99		else if (itemID == "sync")100		{101			site.synchronize(scope);102		}103		else if (itemID == "selectnewer")104		{105			site.selectNewer(scope);106		}107		else if (itemID == "selectcheckedout")108		{109			site.selectCheckedOutFiles();110		}111		else if (itemID == "open")112		{113			if ((scope != "shortcutkey") || site.canOpen())114				site.open();115		}116		else if (itemID == "refresh")117		{118			site.refresh(scope);119		}120		else if (itemID == "deploysupportfiles")121		{122			site.showTestingServerBinDeployDialog();123		}124		else if (itemID == "newfile")125		{126			if (scope == "shortcut")127			{128				if (dw.getFocus() == 'site')129				{130					if ((site.getFocus() == 'site map') && site.canAddLink())131					{132						site.addLinkToNewFile()133					}134					else if ((site.getFocus() != 'site map') && site.canMakeNewFile())135					{136						site.makeNewDreamweaverFile();137					}138				}139				else140				{141					site.makeNewDreamweaverFile();142				}143			}144			else145			{	146				site.makeNewDreamweaverFile();147			}148		}149		else if (itemID == "newfolder")150		{151			site.makeNewFolder();152		}153		else if (itemID == "definesites")154		{155			site.defineSites();156		}157		else if (itemID == "removeconnectionscripts")158		{159			alert(MMDB.removeConnectionScripts());160		}161		else if (itemID == "reports")162		{163			MM.CheckOutError = 0;164			dw.showReportsDialog();165		}166   }167   function canAcceptCommand()168   {   		169		var itemID = arguments[0];170		var scope = arguments[1];171		var docPath;172		if (scope == 'site') 173		{174			docPath = "site";175		}176		else if (scope == 'document')177		{178			docPath = dw.getDocumentPath('document');179		}180		else if (scope == 'docSelection')181		{182			if (dw.getDocumentDOM())183			{184				docPath = dw.getDocumentDOM().getSelectionSrc();185			}186			else187			{188				return false;189			}190		}191		if (itemID == "unlock")192		{193			if (scope == 'document')194			{195				return dw.getDocumentDOM().canMakeEditable();196			}197			else198			{199				return site.canMakeEditable();200			}201		}202		else if (itemID == "connect")203		{204			return ((scope != 'document') && site.canConnect());205		}206		else if (itemID == "sethomepage")207		{208			if (site.getSelection().length == 1)209			{210				var urlPrefix = "file:///";211				var strTemp = site.getSelection()[0].substr(urlPrefix.length);212				213				if (strTemp.indexOf("/") == (-1))214					return false;215				216				if ((DWfile.getAttributes(site.getSelection()[0]) == null) ||217					(DWfile.getAttributes(site.getSelection()[0]).indexOf('D') == (-1)))218				{219					return true;220				}221			}222			223			return false;224		}225		else if (itemID == "put")226		{227			return site.canPut(docPath);228		}229		else if (itemID == "get")230		{231			return site.canGet(docPath);232		}233		else if (itemID == "checkout")234		{235			return site.canCheckOut(docPath);236		}237		else if (itemID == "checkin")238		{239			return site.canCheckIn(docPath);240		}241		else if (itemID == "undocheckout")242		{243			return site.canUndoCheckOut(docPath);244		}245		else if (itemID == "checkedoutby")246		{247			return site.canShowCheckedOutBy(docPath);248		}249		else if (itemID == "findlocal")250		{251			return site.canLocateInSite("local", docPath);252		}253		else if (itemID == "findremote")254		{255			return site.canLocateInSite("remote", docPath);256		}257		else if (itemID == "findlocalremote")258		{259			return site.canLocateInSite(site.getFocus(), docPath);260		}261		else if (itemID == "compare")262		{263			return site.canCompareFiles(docPath);264		}265		else if (itemID == "sync")266		{267			return site.canSynchronize();268		} 269		else if (itemID == "selectnewer")270		{271			return site.canSelectNewer(scope);272		}273		else if (itemID == "selectcheckedout")274		{275			return site.canSelectCheckedOutFiles();276		}277		else if (itemID == "open")278		{279			return site.canOpen();280		}281		else if (itemID == "refresh")282		{283			if (scope == "local")284			{285				return ((dw.getFocus(true) == 'site') && site.canRefresh('local'));286			}287			else if (scope == "remote")288			{289				return ((dw.getFocus(true) == 'site') && site.canRefresh('remote'));290			}291			else if (scope == "all")292			{293				return (site.canRefresh('local') || site.canRefresh('remote'));294			}295		}296		else if (itemID == "deploysupportfiles")297		{298			return (!site.serverActivity() &&299					((site.getServerModelNameForSite().indexOf('.NET') >= 0) ||300						(((dw.getFocus() == 'document') || (dw.getFocus() == 'textView')) &&301						(dw.getDocumentDOM().serverModel.getServerName().indexOf('.NET') >= 0))));302		}303		else if (itemID == "newfile")304		{305			return site.canMakeNewFile();306		}307		else if (itemID == "newfolder")308		{309			return site.canMakeNewFolder();310		}311		else if (itemID == "removeconnectionscripts")312		{313			return (!site.serverActivity() && (site.getCurrentSite() != ''));314		}315		else if (itemID == "reports")316		{317			return (dw.getFocus() != "browser");318		}319		320		return true;321   }322   function setMenuText()323   {324		var itemID = arguments[0];325		var scope = arguments[1];326 		327 		if (itemID == "connect")328		{329			if (site.getConnectionState() == true)330			{331				return MENU_Disconnect;332			}333			else334			{335				return MENU_Connect;336			}337		}338		else if (itemID == "togglemap")339		{340			if (dw.getFloaterVisibility("site map"))341			{342				return MENU_SiteFiles;343			}344			else345			{346				return MENU_SiteMap;347			}348		}349		else if (itemID == "compare")350		{351			if (scope == "document")352			{353   				if (site.isTestingServerSelected())354   					return MENU_CompareWithTesting;355   				else356   					return MENU_CompareWithRemote;357			}358			else359			{360   				if (site.canCompareFiles(scope))361   				{362   					var numSelectedFiles = site.getSelection().length363   					if (!site.isSiteMode())364   					{365   						return MENU_Compare;366   					}367   					else if (site.getFocus() == 'remote')368   					{369   						if (numSelectedFiles == 2)370   						{371   							if (site.isTestingServerSelected())372   								return MENU_CompareTesting;373   							else374   								return MENU_CompareRemote;375   						}376   						else377   							return MENU_CompareWithLocal;378   					}379   					else380   					{381   						if (numSelectedFiles == 2)382   							return MENU_CompareLocal;383   						else384   						{385   							if (site.isTestingServerSelected())386   								return MENU_CompareWithTesting;387   							else388   								return MENU_CompareWithRemote;389   						}390   					}391   				}392   				else 393   				{394   					if (!site.isSiteMode())395   						return MENU_Compare;396    				else if (site.isTestingServerSelected())397   						return MENU_CompareWithTesting;398   					else399   						return MENU_CompareWithRemote;400  				}401			}402		}403		404		return "";405   }406   407   function isCommandChecked()408   {409		var itemID = arguments[0];410		411  		if (itemID == "togglehidden")412		{413			return site.hiddenFilesShowing();414		}415		416		return false;417   }...admin-reording-collection.component.sandbox.ts
Source:admin-reording-collection.component.sandbox.ts  
1import { sandboxOf } from 'angular-playground';2import { DbService } from 'projects/redmond-fire-library/src/lib/services/db.service';3import { SharedModule } from 'projects/redmond-fire-admin/src/app/@shared/shared.module';4import { AdminReorderingCollectionComponent } from './admin-reordering-collection.component';5import { BrowserAnimationsModule } from '@angular/platform-browser/animations';6import { Observable, of } from 'rxjs';7import { SiteContentService } from '../../../services/site-content.service';8class SiteContentMockService {9  sends = 0;10  allOrderedProjects$:Observable<any[]> = of([11    {12      "order": 0,13      "docPath": "admin/projects/collection/6kpWHkET3NGdhwNJPlar",14      "title": "Verilife Rosemont"15    },16    {17      "order": 1,18      "docPath": "admin/projects/collection/FyGXu6sqp7P6MFPA72lS",19      "title": "Verilife River North"20    },21    {22      "order": 2,23      "docPath": "admin/projects/collection/bJERTiRYDTncZdmxHYPw",24      "title": "Pinterest"25    },26    {27      "order": 3,28      "docPath": "admin/projects/collection/E8JddPWTaUcxo8tL9Xcu",29      "title": "G2"30    },31    {32      "order": 4,33      "docPath": "admin/projects/collection/B8reemXwomGIJe5xBHDz",34      "title": "175 W Jackson"35    },36    {37      "order": 5,38      "docPath": "admin/projects/collection/tLmko2gZq8Xs76wluEt7",39      "title": "Billtrust"40    },41    {42      "order": 6,43      "docPath": "admin/projects/collection/vUAuOgtQ5Qp6hm2LVD03",44      "title": "Verilife Arlington Heights"45    },46    {47      "order": 7,48      "docPath": "admin/projects/collection/IrsIuuvtx2wsywEfi7Uv",49      "title": "PerkSpot"50    },51    {52      "order": 8,53      "docPath": "admin/projects/collection/Cep6LotM5Q3CMl3E4GIc",54      "title": "Litera "55    },56    {57      "order": 9,58      "docPath": "admin/projects/collection/t50QFGzIj8jCtQ1ol83l",59      "title": "Help At Home"60    },61    {62      "order": 10,63      "docPath": "admin/projects/collection/LnTAnwmFwW5ogLPMrvrp",64      "title": "Intermatic"65    },66    {67      "order": 11,68      "docPath": "admin/projects/collection/Um25cFijxB1m3fasres4",69      "title": "WellCare"70    },71    {72      "order": 12,73      "docPath": "admin/projects/collection/YEYF3hoGL3g2GAoOey2a",74      "title": "CardConnect"75    },76    {77      "order": 13,78      "docPath": "admin/projects/collection/LhuBd5MW4EUiiY6RkxEB",79      "title": "Codeverse Chicago "80    },81    {82      "order": 14,83      "docPath": "admin/projects/collection/5wK9Bxcc0XVwrBLhblLG",84      "title": "Fermilab"85    },86    {87      "order": 15,88      "docPath": "admin/projects/collection/jdTWbA9oeLKtvtVYZwWG",89      "title": "Oak Wealth Advisors"90    },91    {92      "order": 16,93      "docPath": "admin/projects/collection/iO8ynS3m1JQhd1B5LOlt",94      "title": "Servcorp on Lake"95    },96    {97      "order": 17,98      "docPath": "admin/projects/collection/YmYj8rZfdun3uOcrfeA4",99      "title": "Hanmi Bank"100    },101    {102      "order": 18,103      "docPath": "admin/projects/collection/facMKvKTGa86lzLkXsm8",104      "title": "ParkerGale"105    },106    {107      "order": 19,108      "docPath": "admin/projects/collection/FF7DtqGlJhahjN1usmUy",109      "title": "Servcorp on Wacker"110    },111    {112      "order": 20,113      "docPath": "admin/projects/collection/HM04eW5SC6dA85pJBOV1",114      "title": "Jellyvision"115    },116    {117      "order": 21,118      "docPath": "admin/projects/collection/Qudu2DmWjeDRZcsLT05Y",119      "title": "The Onion"120    },121    {122      "order": 22,123      "docPath": "admin/projects/collection/2Vdij7wuPYMpCGP4Qt0S",124      "title": "Industrious"125    },126    {127      "order": 23,128      "docPath": "admin/projects/collection/1NDKrLzSXbwt1dTrcjqt",129      "title": "Codeverse Wilmette"130    },131    {132      "order": 24,133      "docPath": "admin/projects/collection/3jhMmo7bYElrw8oIQKPd",134      "title": "ABC Supply"135    },136    {137      "order": 25,138      "docPath": "admin/projects/collection/zD3dn4lCHy6X2Ot9rYsi",139      "title": "Codeverse Naperville"140    },141    {142      "order": 26,143      "docPath": "admin/projects/collection/qcW1qOsh2mDzJEmkNE5g",144      "title": "205 W. Randolph"145    }146  ].map(d => { return { ...d, docId: d.docPath.split('/').pop() } }));147}148class DbMockService {149  150  updateAt(docPath, doc) {151    console.log('updated: ', docPath)152  }153}154export default sandboxOf(AdminReorderingCollectionComponent, {155   imports: [SharedModule, BrowserAnimationsModule],156  providers: [157    {158      provide: SiteContentService,159      useClass: SiteContentMockService160    },161    {162      provide: DbService,163      useClass: DbMockService164    }165  ]166}).add('default', {167  template: `168    <div class="w-screen h-screen bg-cyan">169    <button mat-raised-button class="bg-yellow text-black"170      (click)="reorderingProjects.opened = !reorderingProjects.opened">toggle</button>171      <app-admin-reordering-collection #reorderingProjects></app-admin-reordering-collection>172    </div>173    `,174  context: {175    opened: false,176    }...server.js
Source:server.js  
1const express = require('express');2const path = require('path');3const apiRoutes = require('./routes/api');4const PORT = process.env.PORT || 8080;5const app = express();6app.get('/download-spec/term/2020', (req, res) => {7  const docPath = path.join(__dirname, '/public', 'specterm2020.docx');8  res.download(docPath, 'spec.docx', function(err) {9    if (err) {10      throw err;11    }12  })13})14app.get('/download-spec/term/2021', (req, res) => {15  const docPath = path.join(__dirname, '/public', 'specterm2021.docx');16  res.download(docPath, 'spec.docx', function(err) {17    if (err) {18      throw err;19    }20  })21})22app.get('/download-spec/cohort/2020', (req, res) => {23  const docPath = path.join(__dirname, '/public', 'speccohort2020.docx');24  res.download(docPath, 'spec.docx', function(err) {25    if (err) {26      throw err;27    }28  })29})30app.get('/download-spec/cohort/2021', (req, res) => {31  const docPath = path.join(__dirname, '/public', 'speccohort2021.docx');32  res.download(docPath, 'spec.docx', function(err) {33    if (err) {34      throw err;35    }36  })37})38app.get('/download-module-spec', (req, res) => {39  const docPath = path.join(__dirname, '/public', 'module-spec.docx');40  res.download(docPath, 'spec.docx', function(err) {41    if (err) {42      throw err;43    }44  })45})46app.use(apiRoutes);47app.use(express.static("public")); 48app.use(express.urlencoded({ extended: true }));49app.use(express.json());50app.listen(PORT, () => {51  console.log(`Server is listening on http://localhost:${PORT}`);...Using AI Code Generation
1var BestDoc = require('./bestDoc');2var doc = new BestDoc();3console.log(doc.docPath());4module.exports = BestDoc;5function BestDoc() {6    this.docPath = function() {7    }8}9You can also use the module.exports and require method to export and import functions:10var docPath = require('./bestDoc');11console.log(docPath());12module.exports = function() {13}14The following code will show you how to export and import multiple functions and classes:15var BestDoc = require('./bestDoc');16var doc = new BestDoc();17console.log(doc.docPath());18module.exports = {19    docPath: function() {20    }21};22function BestDoc() {23    this.docPath = function() {24    }25}26You can also export and import objects:27var BestDoc = require('./bestDoc');28var doc = new BestDoc();29console.log(doc.docPath());30module.exports = {31};32function BestDoc() {33    this.docPath = function() {34    }35}36You can also export and import objects:37var BestDoc = require('./bestDoc');38var doc = new BestDoc();39console.log(doc.docPath());Using AI Code Generation
1var BestPath = require('./bestPath');2var bestPath = new BestPath();3var path = bestPath.docPath('test');4console.log(path);5var BestPath = require('./bestPath');6var bestPath = new BestPath();7var path = bestPath.docPath('test');8console.log(path);9var BestPath = require('./bestPath');10var bestPath = new BestPath();11var path = bestPath.docPath('test');12console.log(path);13var BestPath = require('./bestPath');14var bestPath = new BestPath();15var path = bestPath.docPath('test');16console.log(path);17var BestPath = require('./bestPath');18var bestPath = new BestPath();19var path = bestPath.docPath('test');20console.log(path);21var BestPath = require('./bestPath');22var bestPath = new BestPath();23var path = bestPath.docPath('test');24console.log(path);25var BestPath = require('./bestPath');26var bestPath = new BestPath();27var path = bestPath.docPath('test');28console.log(path);29var BestPath = require('./bestPath');30var bestPath = new BestPath();31var path = bestPath.docPath('test');32console.log(path);33var BestPath = require('./bestPath');34var bestPath = new BestPath();35var path = bestPath.docPath('test');36console.log(path);37var BestPath = require('./bestPath');38var bestPath = new BestPath();39var path = bestPath.docPath('test');40console.log(path);41var BestPath = require('./bestUsing AI Code Generation
1var bestiary = require('bestiary');2var path = require('path');3var docPath = bestiary.docPath('test');4console.log(docPath);5var testPath = path.join(docPath, 'test.txt');6console.log(testPath);Using AI Code Generation
1var BestDoc = require('./best-doc');2var doc = new BestDoc();3doc.set('title','A new document');4doc.set('author','John Smith');5doc.set('content','This is the content of the document');6console.log(doc.docPath('title'));Using AI Code Generation
1var bestDoc = require('bestdoc');2var docPath = bestDoc.docPath;3var docDir = docPath('test.txt');4console.log(docDir);5var bestDoc = require('bestdoc');6var docDir = bestDoc.docDir;7var docPath = docDir('test.txt');8console.log(docPath);9var bestDoc = require('bestdoc');10var docPath = bestDoc.docPath;11var docDir = docPath('test.txt');12console.log(docDir);13var bestDoc = require('bestdoc');14var docDir = bestDoc.docDir;15var docPath = docDir('test.txt');16console.log(docPath);17var bestDoc = require('bestdoc');18var docPath = bestDoc.docPath;19var docDir = docPath('test.txt');20console.log(docDir);21var bestDoc = require('bestdoc');22var docDir = bestDoc.docDir;23var docPath = docDir('test.txt');24console.log(docPath);25var bestDoc = require('bestdoc');26var docPath = bestDoc.docPath;27var docDir = docPath('test.txt');28console.log(docDir);29var bestDoc = require('bestdoc');30var docDir = bestDoc.docDir;31var docPath = docDir('test.txt');32console.log(docPath);33var bestDoc = require('bestdoc');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!!
