Best JavaScript code snippet using best
prepareFilesToCopy.ts
Source:prepareFilesToCopy.ts
1import path from 'path';2import { filenameToPostInstallEntry } from '../src/util/postinstallFilenamesConvertor';3import { ProjectNames } from './projectNames';4export interface IFilesToCopy {5 from: string;6 to: string;7}8export function prepareFilesToSave(): Array<IFilesToCopy> {9 return [10 {11 path: path.resolve(ProjectNames.E2E_TESTS_FOLDER, ProjectNames.E2E_PLUGINS_SUBFOLDER),12 name: ProjectNames.E2E_PLUGINS_FILE,13 },14 {15 path: path.resolve(ProjectNames.E2E_TESTS_FOLDER, ProjectNames.E2E_SUPPORT_SUBFOLER),16 name: ProjectNames.E2E_SUPPORT_FILE,17 },18 {19 path: path.resolve(ProjectNames.CONFIG_FOLDER),20 name: ProjectNames.E2E_TSCONFIG_FILE,21 },22 {23 path: path.resolve(ProjectNames.E2E_TESTS_FOLDER, ProjectNames.E2E_PAGE_OBJECTS_FOLDER),24 name: ProjectNames.GITIGNORE_FILE,25 },26 {27 path: path.resolve('.'),28 name: ProjectNames.CYPRESS_CUCUMBER_CONFIG_FILE,29 },30 {31 path: path.resolve(ProjectNames.E2E_TESTS_FOLDER, ProjectNames.E2E_CONFIG_SUBFOLDER),32 name: ProjectNames.CYPRESS_INTEGRATION_CONFIG_FILE,33 },34 {35 path: path.resolve(ProjectNames.E2E_TESTS_FOLDER, ProjectNames.E2E_CONFIG_SUBFOLDER),36 name: ProjectNames.CYPRESS_UNIT_CONFIG_FILE,37 },38 ].map(fileInfo => ({39 from: path.resolve(fileInfo.path, fileInfo.name),40 to: path.resolve(ProjectNames.POSTINSTALL_FOLDER, filenameToPostInstallEntry(fileInfo.name)),41 }));42}43export function prepareSavedFilesToCopy(projectBasePath: string, libraryTemplatesPath: string): Array<IFilesToCopy> {44 return [45 {46 resultDir: path.resolve(projectBasePath, ProjectNames.E2E_TESTS_FOLDER, ProjectNames.E2E_PAGE_OBJECTS_FOLDER),47 name: ProjectNames.GITIGNORE_FILE,48 },49 {50 resultDir: path.resolve(projectBasePath, ProjectNames.E2E_TESTS_FOLDER, ProjectNames.E2E_PLUGINS_SUBFOLDER),51 name: ProjectNames.E2E_PLUGINS_FILE,52 },53 {54 resultDir: path.resolve(55 projectBasePath, ProjectNames.E2E_TESTS_FOLDER,56 ProjectNames.E2E_FEATURES_SUBFOLER, ProjectNames.E2E_FEATURES_COMMON_SUBFOLDER57 ),58 name: ProjectNames.E2E_FEATURES_COMMON_BEFORE_FILE,59 },60 {61 resultDir: path.resolve(projectBasePath),62 name: ProjectNames.CYPRESS_CUCUMBER_CONFIG_FILE,63 },64 {65 resultDir: path.resolve(projectBasePath, ProjectNames.E2E_TESTS_FOLDER, ProjectNames.E2E_CONFIG_SUBFOLDER),66 name: ProjectNames.CYPRESS_INTEGRATION_CONFIG_FILE,67 },68 {69 resultDir: path.resolve(projectBasePath, ProjectNames.E2E_TESTS_FOLDER, ProjectNames.E2E_CONFIG_SUBFOLDER),70 name: ProjectNames.CYPRESS_UNIT_CONFIG_FILE,71 },72 {73 resultDir: path.resolve(projectBasePath, ProjectNames.E2E_TESTS_FOLDER),74 name: ProjectNames.E2E_TSCONFIG_FILE,75 outputName: ProjectNames.OUTPUT_TSCONFIG_FILE,76 },77 {78 resultDir: path.resolve(projectBasePath, ProjectNames.E2E_TESTS_FOLDER, ProjectNames.E2E_SUPPORT_SUBFOLER),79 name: ProjectNames.E2E_SUPPORT_FILE,80 },81 {82 resultDir: path.resolve(projectBasePath),83 name: ProjectNames.CYPRESS_ENV_FILE,84 },85 ].map(fileInfo => ({86 from: path.resolve(libraryTemplatesPath, filenameToPostInstallEntry(fileInfo.name)),87 to: path.resolve(fileInfo.resultDir, (fileInfo.outputName || fileInfo.name)),88 }));89}90export function prepareDirectoriesToCreate(projectBasePath): Array<string> {91 const PROJECT_E2E_PATH = path.resolve(projectBasePath, ProjectNames.E2E_TESTS_FOLDER);92 const PROJECT_PLUGINS_PATH = path.resolve(PROJECT_E2E_PATH, ProjectNames.E2E_PLUGINS_SUBFOLDER);93 const PROJECT_SUPPORT_PATH = path.resolve(PROJECT_E2E_PATH, ProjectNames.E2E_SUPPORT_SUBFOLER);94 const PROJECT_PAGE_OBJECTS_PATH = path.resolve(PROJECT_E2E_PATH, ProjectNames.E2E_PAGE_OBJECTS_FOLDER);95 const PROJECT_TESTS_COMMON_PATH = path.resolve(96 PROJECT_E2E_PATH, ProjectNames.E2E_FEATURES_SUBFOLER, ProjectNames.E2E_FEATURES_COMMON_SUBFOLDER97 );98 const PROJECT_E2E_CONFIG_PATH = path.resolve(PROJECT_E2E_PATH, ProjectNames.E2E_CONFIG_SUBFOLDER);99 return [100 PROJECT_PLUGINS_PATH, PROJECT_SUPPORT_PATH, PROJECT_PAGE_OBJECTS_PATH,101 PROJECT_TESTS_COMMON_PATH, PROJECT_E2E_CONFIG_PATH,102 ];...
Task.js
Source:Task.js
1import { DOM } from "./DOM.js";2import {parse, format} from 'date-fns';3class Task{4 constructor(title, description, dueDate, priority){5 this.title = title;6 this.description = description;7 this.dueDate = dueDate;8 this.priority = priority;9 this.status = "unchecked"10 this.id = title.hashCode();11 } 12 static add(projectName){13 event.preventDefault(); //Disable refresh after submit14 const title = document.getElementById("title").value;15 const description = document.getElementById("description").value || null;16 let dueDay = document.getElementById("due-date").value;17 dueDay = parse(dueDay.replace("-",".").replace("-",".").replace("-","."), "yyyy.MM.dd", new Date())18 dueDay = format(dueDay, 'dd MMM yyyy');19 console.log(dueDay)20 const dueDate = dueDay || "No date";21 const priority = document.getElementById("priority").value;22 //add validation logic.. pendent to do this 23 const newTask = new Task(title, description, dueDate, priority);24 this.storeKey(newTask.id, projectName);25 window.localStorage.setItem(newTask.id, JSON.stringify(newTask));26 DOM.showAllTasks(projectName);27 }28 29 static getKeysByProject(projectName){30 let filteredKeys = {31 "id":[],32 "projectName": []33 }34 let keys = JSON.parse(window.localStorage.getItem("taskKeys"));35 if(projectName == "Inbox"){36 return keys;37 }38 if(projectName == "Today"){39 keys = Task.getTodayKeys(keys);40 return keys;41 }42 for(let el in keys["projectName"]){43 if( keys["projectName"][el] == projectName){44 filteredKeys.id.push(keys["id"][el]);45 filteredKeys.projectName.push(keys["projectName"][el])46 };47 }48 return filteredKeys;49 }50 static storeKey(id, projectName){51 if(window.localStorage.getItem("taskKeys") == null){52 let taskIdentification = {53 id: [id],54 projectName : [projectName]55 };56 window.localStorage.setItem("taskKeys", JSON.stringify(taskIdentification));57 return;58 }59 60 let taskIdentification = JSON.parse(window.localStorage.getItem("taskKeys"));61 taskIdentification["id"].push(id);62 taskIdentification["projectName"].push(projectName);63 window.localStorage.setItem("taskKeys", JSON.stringify(taskIdentification));64 65 }66 static addProject(){67 event.preventDefault(); //Disable refresh after submit68 let projectName = document.getElementById("projectName").value;69 if(window.localStorage.getItem("projectNames") == null){70 let projectNames = {71 projectName: [projectName]72 }73 window.localStorage.setItem("projectNames", JSON.stringify(projectNames));74 return;75 }76 let projectNames = JSON.parse(window.localStorage.getItem("projectNames"));77 projectNames["projectName"].push(projectName);78 window.localStorage.setItem("projectNames", JSON.stringify(projectNames));79 }80 static getProjectNames(){81 if(JSON.parse(window.localStorage.getItem("projectNames")) == null) return null;82 let projectNames = JSON.parse(window.localStorage.getItem("projectNames"));83 projectNames = projectNames["projectName"].map(name => name)84 return projectNames;85 }86 static toggleStatus(taskId){87 let task = JSON.parse(window.localStorage.getItem(taskId));88 if(task.status == "checked") task.status = "unchecked";89 else task.status = "checked";90 window.localStorage.setItem(taskId, JSON.stringify(task));91 }92 static delete(taskId){93 window.localStorage.removeItem(taskId);94 let projectNames = JSON.parse(window.localStorage.getItem("taskKeys"));95 96 for(let i in projectNames["id"]){97 if(projectNames["id"][i] == taskId){98 projectNames["id"].splice(i,1);99 projectNames["projectName"].splice(i,1);100 window.localStorage.setItem("taskKeys", JSON.stringify(projectNames));101 return;102 }103 }104 }105 static getTodayKeys(keys){106 const task = Objetct.keys(localStorage);107 108 return keys;109 }110 111}...
index.js
Source:index.js
1import Vue from "vue";2import Vuex from "vuex";3import Dexie from "dexie";4import { exportDB, importInto } from "dexie-export-import";5import download from "downloadjs";6Vue.use(Vuex);7let DATABASE_NAME = "MyWayDB2";8const dbPromise = () => {9 let db = new Dexie(DATABASE_NAME);10 db.version(1).stores({11 projects: "name"12 });13 return db;14};15export default new Vuex.Store({16 state: {17 projectNames: [],18 project: {19 userMode: false,20 groups: [],21 name: ""22 }23 },24 mutations: {25 empty(state, values) {26 state.project = values.project;27 state.projectNames = values.projectNames;28 },29 update(state, values) {30 state.project = values.project;31 state.projectNames = values.projectNames;32 }33 },34 actions: {35 async load(context, projectName, isInitial) {36 const db = await dbPromise();37 let projectNames = await db.projects.toCollection().keys();38 if (!projectNames) {39 projectNames = [];40 }41 let project = await db.projects.get(projectName);42 if (!project) {43 // Make a fresh project.44 project = {45 name: projectName,46 groups: [],47 freshGroup: null,48 switchCount: 2,49 talkoverMode: "yes",50 userMode: false51 };52 for (let i = 0; i < 7; i++) {53 project.groups.push({54 id: "" + i,55 clips: [],56 nextClipId: 0,57 keyCode: null,58 keyName: null,59 highlighted: false,60 sequence: [],61 oldSequenceIndex: 0,62 sequenceIndex: 0,63 mode: "Sequence",64 keyMode: "Standard",65 active: true,66 icon: "circle-fill",67 color: "#007bff"68 });69 }70 project.freshGroup = project.groups.splice(7)[0];71 }72 context.commit(isInitial ? "empty" : "update", {73 project: project,74 projectNames: projectNames75 });76 },77 async saveProject(context, project) {78 if (project.name == "") {79 for (let i = 1; ; i++) {80 let newName = "Unnamed project" + (i > 1 ? " " + i : "");81 if (context.getters.projectNames.every(n => n != newName)) {82 project.name = newName;83 break;84 }85 }86 }87 const db = await dbPromise();88 await db.projects.put(project);89 this.dispatch("load", project.name, /* isInitial= */ false);90 },91 async deleteProject(context, projectName) {92 const db = await dbPromise();93 await db.projects.delete(projectName);94 this.dispatch("load", "", /* isInitial= */ false);95 },96 async downloadProjects() {97 const db = await dbPromise();98 const blob = await exportDB(db, { noTransaction: true });99 download(blob, "myway-export.json", "application/json");100 },101 async importProjects(context, blob) {102 const db = await dbPromise();103 await importInto(db, blob);104 this.dispatch("load", "", /* isInitial= */ false);105 }106 },107 getters: {108 project: state => state.project,109 projectNames: state => state.projectNames110 }...
Using AI Code Generation
1var BestProject = require("./BestProject.js");2var bp = new BestProject();3bp.projectNames();4function BestProject(){5 this.projectNames = function(){6 console.log("Project 1");7 console.log("Project 2");8 console.log("Project 3");9 }10}11module.exports = BestProject;12var bp = require("./BestProject.js");13var BestProject = require("./BestProject.js");14var bp = new BestProject();15bp.projectNames();16var BestProject = require("./BestProject.js");17var bp = new BestProject();18bp.projectNames();19var BestProject = require("./BestProject.js");20var bp = BestProject();21bp.projectNames();22var BestProject = require("./BestProject.js");23var bp = BestProject();24bp.projectNames();25var BestProject = require("./BestProject.js");26var bp = new BestProject();27bp.projectNames();28var BestProject = require("./BestProject.js");29var bp = new BestProject();30bp.projectNames();31var BestProject = require("./BestProject.js");32var bp = BestProject();33bp.projectNames();
Using AI Code Generation
1var Bestbuy = require('./bestbuy.js');2var bb = new Bestbuy();3bb.projectNames(function(err, names) {4 if (err) {5 console.log("Error: " + err);6 } else {7 console.log("Project Names: " + names);8 }9});10var fs = require('fs');11var Bestbuy = function() {12};13Bestbuy.prototype.projectNames = function(callback) {14 fs.readdir('.', function(err, files) {15 if (err) {16 callback(err);17 } else {18 callback(null, files);19 }20 });21};22module.exports = Bestbuy;
Using AI Code Generation
1var BestProject = require('./BestProject');2var bestProject = new BestProject();3var projectNames = bestProject.projectNames();4console.log(projectNames);5var BestProject = require('./BestProject');6var bestProject = new BestProject();7var projectNames = bestProject.projectNames();8console.log(projectNames);9var BestProject = require('./BestProject');10var bestProject = new BestProject();11var projectNames = bestProject.projectNames();12console.log(projectNames);13var BestProject = require('./BestProject');14var bestProject = new BestProject();15var projectNames = bestProject.projectNames();16console.log(projectNames);17var BestProject = require('./BestProject');18var bestProject = new BestProject();19var projectNames = bestProject.projectNames();20console.log(projectNames);21var BestProject = require('./BestProject');22var bestProject = new BestProject();23var projectNames = bestProject.projectNames();24console.log(projectNames);25var BestProject = require('./BestProject');26var bestProject = new BestProject();27var projectNames = bestProject.projectNames();28console.log(projectNames);29var BestProject = require('./BestProject');30var bestProject = new BestProject();31var projectNames = bestProject.projectNames();
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!!