How to use spaced method in wpt

Best JavaScript code snippet using wpt

spacedRepetition.js

Source:spacedRepetition.js Github

copy

Full Screen

1import createMainTemplate from './Template/mainTemplate'2import {3 createUserWord,4 getAgregateWord,5 getWordsToLearn,6 updateUserWord,7 getUserSettings,8 getUserStatistic,9 updateUserStatistic10} from './Api/Api'11import {12 addTranslate,13 createAudio,14 addCardInfo,15 shuffleArray,16 createStatics,17 createNotification18} from './Utils/Utils'19import { authorizationLoaderShow, authorizationLoaderHide } from '../authorization/loader';20// eslint-disable-next-line import/no-cycle 21import {setActiveStatus} from '../main-page/basicHeader'22// eslint-disable-next-line import/no-cycle 23 import showMainPage from '../main-page/showMainPage';24 import clearContainer from '../clear';25import mainPageHide from '../main-page/mainPageHide'26export default async function createSpacedRepetition() {27 authorizationLoaderShow()28 let wordPosition = 0;29 let currentMode = 'learn';30 let showTranslate = true;31 let pronunciationStatus = true;32 let tracks = [];33 const token = localStorage.getItem('token');34 const userId = localStorage.getItem('userId');35 const CURRENT_WORD_STAT = {36 totalAttempts: 0,37 successfulAttempts: 0,38 unsuccessfulAttempts: 0,39 }40 const MAIN = document.querySelector('main');41 MAIN.classList.add('spaced-repetition');42 const MAIN_WRAPPER = createMainTemplate();43 const CARD_HEADER = MAIN_WRAPPER.querySelector('.card__header');44 const CURRENT_PROGRESS = MAIN_WRAPPER.querySelector('.progress__current');45 const START_VALUE = MAIN_WRAPPER.querySelector('.progress__start-value');46 const END_WALUE = MAIN_WRAPPER.querySelector('.progress__end-value');47 const INPUT_CONTAINER = MAIN_WRAPPER.querySelector('.card__input-container');48 const INPUT_FIELD = MAIN_WRAPPER.querySelector('.card__input');49 const ANSWER = MAIN_WRAPPER.querySelector('.answer');50 const EXAMPLE_TRANSLATE = MAIN_WRAPPER.querySelector('.card__word-example-translate');51 const MEANING_TRANSLATE = MAIN_WRAPPER.querySelector('.card__explain-translate');52 const WORD_EXPLAIN = MAIN_WRAPPER.querySelector('.card__explain');53 const WORD_EXAMPLE = MAIN_WRAPPER.querySelector('.card__word-example');54 const WORD_TRANSCRIPTION = MAIN_WRAPPER.querySelector('.card__transcription');55 const CARD_BUTTONS = MAIN_WRAPPER.querySelector('.card__buttons');56 const DIFFICULTY_BUTTONS = MAIN_WRAPPER.querySelector('.card__difficulty-buttons');57 const ADDITIONAL_BUTTONS = MAIN_WRAPPER.querySelector('.card__additional-buttons');58 const CHECK_BUTTON = MAIN_WRAPPER.querySelector('.card__check-word-btn');59 const SKIP_BUTTON = MAIN_WRAPPER.querySelector('.card__skip-word-btn');60 const CARD_SPEAKER = MAIN_WRAPPER.querySelector('.card__pronunciation');61 const TRANSLATE_CHECKBOX = MAIN_WRAPPER.querySelector('.flip-switch input');62 const NAVIGATE_NEXT = MAIN_WRAPPER.querySelector('.navigate--next');63 const DELETE_BTN = MAIN_WRAPPER.querySelector('.card__delete-word-btn');64 const COMPLICATED_BTN = MAIN_WRAPPER.querySelector('.card__complicated-word-btn');65 const WORD_TRANSLATE = MAIN_WRAPPER.querySelector('.card__word-translate');66 const CARD_IMAGE = MAIN_WRAPPER.querySelector('.card__image');67 const PLAYER = createAudio(); 68 const SETTINGS = await getUserSettings(userId, token);69 const STATISTIC = await getUserStatistic(userId, token);70 71 72 const repeatPeriod = {73 easy: +(SETTINGS.optional.spacedRepetition.easyInterval),74 medium: +(SETTINGS.optional.spacedRepetition.mediumInterval),75 hard: +(SETTINGS.optional.spacedRepetition.hardInterval),76 complicated: +(SETTINGS.optional.spacedRepetition.hardInterval)77 }78 const CURRENT_DATE = new Date().toLocaleDateString("ru-Ru", {79 "year": "numeric",80 "month": "numeric",81 "day": "numeric"82 });83 if (STATISTIC.optional.spacedRepetition.dayStat.date !== CURRENT_DATE) {84 STATISTIC.optional.spacedRepetition.dayStat.date = CURRENT_DATE;85 STATISTIC.optional.spacedRepetition.dayStat.newWords = 0;86 STATISTIC.optional.spacedRepetition.dayStat.successfulAttempts = 0;87 STATISTIC.optional.spacedRepetition.dayStat.unsuccessfulAttempts = 0;88 STATISTIC.optional.spacedRepetition.dayStat.totalAttempts = 0;89 STATISTIC.optional.spacedRepetition.dayStat.correctAnswerSeries = 0;90 STATISTIC.optional.spacedRepetition.dayStat.totalWords = 0;91 STATISTIC.optional.spacedRepetition.dayStat.finalCorrectAnswerSeries = 0;92 }93 if (!SETTINGS.optional.spacedRepetition.translate) {94 WORD_TRANSLATE.classList.add('display-none');95 }96 if (!SETTINGS.optional.spacedRepetition.example) {97 WORD_EXAMPLE.classList.add('display-none');98 }99 if (!SETTINGS.optional.spacedRepetition.explanation) {100 WORD_EXPLAIN.classList.add('display-none');101 }102 if (!SETTINGS.optional.spacedRepetition.transcription) {103 WORD_TRANSCRIPTION.classList.add('display-none');104 }105 if (!SETTINGS.optional.spacedRepetition.showDifficult) {106 DIFFICULTY_BUTTONS.classList.add('display-none');107 } else {108 NAVIGATE_NEXT.classList.add('display-none');109 }110 if (!SETTINGS.optional.spacedRepetition.showDelete) {111 DELETE_BTN.classList.add('display-none');112 }113 if (!SETTINGS.optional.spacedRepetition.showHard) {114 COMPLICATED_BTN.classList.add('display-none');115 }116 if (!SETTINGS.optional.spacedRepetition.associateImage) {117 CARD_IMAGE.classList.add('display-none');118 }119 const newWordsToLearnNumber = SETTINGS.wordsPerDay - STATISTIC.optional.spacedRepetition.dayStat.newWords;120 const words = await getWordsToLearn(userId, token, newWordsToLearnNumber, SETTINGS.optional.spacedRepetition.group);121 if (SETTINGS.optional.spacedRepetition.cardsPerDay <= STATISTIC.optional.spacedRepetition.dayStat.totalWords) {122 MAIN.classList.remove('spaced-repetition');123 authorizationLoaderHide();124 createNotification('limit');125 return;126 }127 if (words.learn.length === 0 && words.train.length === 0) {128 129 MAIN.classList.remove('spaced-repetition');130 authorizationLoaderHide();131 createNotification('nothingToShow');132 return;133 }134 mainPageHide();135 136 if (words.learn.length === 0) currentMode = 'train';137 MAIN.append(MAIN_WRAPPER);138 authorizationLoaderHide();139 addCardInfo(words[currentMode][wordPosition]);140 START_VALUE.textContent = STATISTIC.optional.spacedRepetition.dayStat.totalWords;141 END_WALUE.textContent = SETTINGS.optional.spacedRepetition.cardsPerDay;142 CURRENT_PROGRESS.style.width = `${START_VALUE.textContent / END_WALUE.textContent * 100}%`;143 INPUT_FIELD.focus();144 const createNextCard = () => {145 if (currentMode === 'learn' && words[currentMode].length <= wordPosition) {146 wordPosition = 0;147 currentMode = 'train';148 words.train = shuffleArray(shuffleArray(words.train));149 }150 if ((currentMode ==='train' && words[currentMode].length <= wordPosition) || SETTINGS.optional.spacedRepetition.cardsPerDay === STATISTIC.optional.spacedRepetition.dayStat.totalWords) {151 const stat = createStatics(STATISTIC);152 const btn = stat.querySelector('.repetition-stat__confirm-btn');153 btn.onclick = () => {154 const mainPageLink = document.querySelector('.basic-header__item_main-page');155 clearContainer(document.querySelector('main')); 156 setActiveStatus(mainPageLink);157 MAIN.className = '';158 showMainPage();159 }160 document.querySelector('.spaced-repetition').append(stat);161 return;162 }163 164 NAVIGATE_NEXT.classList.add('visability-hidden');165 DIFFICULTY_BUTTONS.classList.add('visability-hidden');166 ADDITIONAL_BUTTONS.classList.add('visability-hidden');167 addCardInfo(words[currentMode][wordPosition]);168 CHECK_BUTTON.disabled = false;169 SKIP_BUTTON.disabled = false;170 INPUT_FIELD.disabled = false;171 NAVIGATE_NEXT.disabled = true;172 CURRENT_WORD_STAT.unsuccessfulAttempts = 0;173 CURRENT_WORD_STAT.successfulAttempts = 0;174 CURRENT_WORD_STAT.totalAttempts = 0;175 ANSWER.innerHTML = '';176 INPUT_FIELD.value = '';177 START_VALUE.textContent = +(START_VALUE.textContent) + 1;178 CURRENT_PROGRESS.style.width = `${START_VALUE.textContent / END_WALUE.textContent * 100}%`;179 EXAMPLE_TRANSLATE.textContent = '';180 MEANING_TRANSLATE.textContent = '';181 INPUT_FIELD.focus();182 tracks = [];183 if (SETTINGS.optional.spacedRepetition.translate) {184 tracks.push(`https://raw.githubusercontent.com/icexes/rslang-data/master/${words[currentMode][wordPosition].audio}`);185 }186 if (SETTINGS.optional.spacedRepetition.example) {187 tracks.push(`https://raw.githubusercontent.com/icexes/rslang-data/master/${words[currentMode][wordPosition].audioExample}`);188 }189 if (SETTINGS.optional.spacedRepetition.explanation) {190 tracks.push(`https://raw.githubusercontent.com/icexes/rslang-data/master/${words[currentMode][wordPosition].audioMeaning}`);191 }192 }193 const checkAnswer = () => {194 if (INPUT_FIELD.disabled === false) {195 if (document.querySelector('.answer span') !== null) {196 ANSWER.classList.add('answer--remove');197 setTimeout(() => {198 ANSWER.innerHTML = '';199 ANSWER.classList.remove('answer--remove');200 }, 500)201 }202 INPUT_FIELD.focus();203 }204 };205 const setWordToBackEnd = async (mode, difficulty = '') => {206 let wordDifficulty = difficulty;207 // eslint-disable-next-line dot-notation208 const wordId = `${words[currentMode][wordPosition]['_id']}`;209 let nextDate = new Date();210 let lastDate = new Date();211 if (mode === 'learn') {212 if (wordDifficulty === '') {213 if (CURRENT_WORD_STAT.unsuccessfulAttempts === 0) wordDifficulty = 'easy';214 else if (CURRENT_WORD_STAT.unsuccessfulAttempts < 3) wordDifficulty = 'medium';215 else wordDifficulty = 'hard';216 }217 nextDate.setDate(nextDate.getDate() + repeatPeriod[wordDifficulty]);218 nextDate = nextDate.toLocaleDateString("ru-Ru", {219 "year": "numeric",220 "month": "numeric",221 "day": "numeric"222 });223 lastDate = lastDate.toLocaleDateString("ru-Ru", {224 "year": "numeric",225 "month": "numeric",226 "day": "numeric"227 });228 await createUserWord({229 'userId': `${userId}`,230 'wordId': wordId,231 'word': {232 "difficulty": wordDifficulty,233 "optional": {234 wordStat: CURRENT_WORD_STAT,235 nextDate,236 lastDate,237 'totalShown' : 1238 }239 }240 }, token);241 if (wordDifficulty !== 'deleted') {242 words.train.push(await getAgregateWord(userId, wordId, token));243 }244 STATISTIC.optional.spacedRepetition.dayStat.newWords += 1;245 STATISTIC.learnedWords += 1;246 if (STATISTIC.optional.spacedRepetition.totalStat === undefined) {247 STATISTIC.optional.spacedRepetition.totalStat = {};248 }249 if (STATISTIC.optional.spacedRepetition.totalStat[lastDate] === undefined) {250 STATISTIC.optional.spacedRepetition.totalStat[lastDate] = {};251 STATISTIC.optional.spacedRepetition.totalStat[lastDate].words = 0;252 }253 STATISTIC.optional.spacedRepetition.totalStat[lastDate].words += 1;254 } else if (mode === 'train') {255 const {256 userWord257 } = words[currentMode][wordPosition];258 const finalWordStat = {259 totalAttempts: userWord.optional.wordStat.totalAttempts + CURRENT_WORD_STAT.totalAttempts,260 successfulAttempts: userWord.optional.wordStat.successfulAttempts + CURRENT_WORD_STAT.successfulAttempts,261 unsuccessfulAttempts: userWord.optional.wordStat.unsuccessfulAttempts + CURRENT_WORD_STAT.unsuccessfulAttempts,262 }263 userWord.optional.totalShown += 1;264 if (wordDifficulty === '') {265 if ((finalWordStat.successfulAttempts * 100) / finalWordStat.totalAttempts >= 95) {266 wordDifficulty = 'easy';267 } else if ((finalWordStat.successfulAttempts * 100) / finalWordStat.totalAttempts >= 75) {268 wordDifficulty = 'medium';269 } else {270 wordDifficulty = 'hard';271 }272 }273 if (userWord.difficulty !== 'complicated') {274 userWord.difficulty = wordDifficulty;275 }276 if (wordDifficulty === 'deleted') {277 userWord.difficulty = wordDifficulty;278 }279 if (wordDifficulty !== 'deleted') {280 nextDate.setDate(nextDate.getDate() + repeatPeriod[wordDifficulty]);281 }282 nextDate = nextDate.toLocaleDateString("ru-Ru", {283 "year": "numeric",284 "month": "numeric",285 "day": "numeric"286 });287 lastDate = lastDate.toLocaleDateString("ru-Ru", {288 "year": "numeric",289 "month": "numeric",290 "day": "numeric"291 });292 userWord.optional.wordStat = finalWordStat;293 userWord.optional.lastDate = lastDate;294 userWord.optional.nextDate = nextDate;295 updateUserWord(userId, wordId, userWord, token);296 }297 STATISTIC.optional.spacedRepetition.dayStat.totalWords += 1;298 STATISTIC.optional.spacedRepetition.dayStat.unsuccessfulAttempts += CURRENT_WORD_STAT.unsuccessfulAttempts;299 STATISTIC.optional.spacedRepetition.dayStat.successfulAttempts += CURRENT_WORD_STAT.successfulAttempts;300 STATISTIC.optional.spacedRepetition.dayStat.totalAttempts += CURRENT_WORD_STAT.totalAttempts;301 if (CURRENT_WORD_STAT.unsuccessfulAttempts === 0) {302 STATISTIC.optional.spacedRepetition.dayStat.correctAnswerSeries += 1;303 } else {304 if (STATISTIC.optional.spacedRepetition.dayStat.finalCorrectAnswerSeries < STATISTIC.optional.spacedRepetition.dayStat.correctAnswerSeries) {305 STATISTIC.optional.spacedRepetition.dayStat.finalCorrectAnswerSeries = STATISTIC.optional.spacedRepetition.dayStat.correctAnswerSeries306 }307 STATISTIC.optional.spacedRepetition.dayStat.correctAnswerSeries = 0;308 }309 updateUserStatistic(userId, token, STATISTIC);310 }311 if (SETTINGS.optional.spacedRepetition.translate) {312 tracks.push(`https://raw.githubusercontent.com/icexes/rslang-data/master/${words[currentMode][wordPosition].audio}`);313 }314 if (SETTINGS.optional.spacedRepetition.example) {315 tracks.push(`https://raw.githubusercontent.com/icexes/rslang-data/master/${words[currentMode][wordPosition].audioExample}`);316 }317 if (SETTINGS.optional.spacedRepetition.explanation) {318 tracks.push(`https://raw.githubusercontent.com/icexes/rslang-data/master/${words[currentMode][wordPosition].audioMeaning}`);319 }320 function checkWord(event, word) {321 event.preventDefault();322 let errors = 0;323 let currentAudio = 0;324 let resultString = '';325 const text = INPUT_FIELD.value;326 word.split('').forEach((symbol, index) => {327 if (symbol === text[index]) {328 resultString += `<span class='correct'>${symbol}</span>`329 } else {330 errors += 1;331 resultString += `<span class='wrong'>${symbol}</span>`332 }333 });334 if (text.trim().length !== word.length) {335 errors += 1;336 }337 CURRENT_WORD_STAT.totalAttempts += 1;338 if (errors) {339 CURRENT_WORD_STAT.unsuccessfulAttempts += 1;340 ANSWER.innerHTML = resultString;341 const answerElements = ANSWER.querySelectorAll('span');342 setTimeout(() => {343 answerElements.forEach(el => el.classList.add('default'))344 });345 INPUT_FIELD.value = '';346 INPUT_FIELD.focus();347 } else {348 CURRENT_WORD_STAT.successfulAttempts += 1;349 CHECK_BUTTON.disabled = true;350 SKIP_BUTTON.disabled = true;351 INPUT_FIELD.value = '';352 ANSWER.innerHTML = `<span class='answer--correct'>${words[currentMode][wordPosition].word}</span>`353 INPUT_FIELD.disabled = true;354 DIFFICULTY_BUTTONS.classList.remove('visability-hidden');355 ADDITIONAL_BUTTONS.classList.remove('visability-hidden');356 NAVIGATE_NEXT.classList.remove('visability-hidden');357 WORD_EXPLAIN.innerHTML = `Значение: ${words[currentMode][wordPosition].textMeaning}`;358 WORD_EXAMPLE.innerHTML = `Пример: ${words[currentMode][wordPosition].textExample}`;359 NAVIGATE_NEXT.disabled = false;360 if (showTranslate) {361 addTranslate(words[currentMode][wordPosition].textExampleTranslate, words[currentMode][wordPosition].textMeaningTranslate, SETTINGS.optional.spacedRepetition.example, SETTINGS.optional.spacedRepetition.explanation);362 }363 if (pronunciationStatus) {364 PLAYER.src = tracks[currentAudio];365 PLAYER.play();366 PLAYER.onended = () => {367 if (currentAudio < tracks.length - 1) {368 currentAudio += 1;369 PLAYER.src = tracks[currentAudio];370 PLAYER.play();371 }372 } 373 } 374 }375 }376 CARD_BUTTONS.addEventListener('click', async (event) => {377 if (event.target.closest('.card__check-word-btn')) {378 checkWord(event, words[currentMode][wordPosition].word);379 } else if (event.target.closest('.card__skip-word-btn')) {380 CURRENT_WORD_STAT.unsuccessfulAttempts += 1;381 CURRENT_WORD_STAT.successfulAttempts -= 1;382 INPUT_FIELD.value = words[currentMode][wordPosition].word;383 checkWord(event, words[currentMode][wordPosition].word);384 } else if ((event.target.closest('.card__difficulty-buttons') || event.target.closest('.card__additional-buttons')) && event.target.closest('button')) {385 386 NAVIGATE_NEXT.classList.add('visability-hidden');387 DIFFICULTY_BUTTONS.classList.add('visability-hidden');388 ADDITIONAL_BUTTONS.classList.add('visability-hidden');389 if (event.target.closest('.card__repeat-word-btn')) {390 // eslint-disable-next-line dot-notation391 const wordId = `${words[currentMode][wordPosition]['_id']}`;392 await setWordToBackEnd(currentMode);393 words.train.push(await getAgregateWord(userId, wordId, token));394 } else {395 await setWordToBackEnd(currentMode, event.target.getAttribute('difficulty'));396 }397 if (!PLAYER.paused) {398 PLAYER.pause();399 PLAYER.currentTime = 0;400 }401 wordPosition += 1;402 createNextCard();403 }404 });405 CARD_HEADER.addEventListener('click', (event) => {406 if (event.target === CARD_SPEAKER) {407 CARD_SPEAKER.classList.toggle('card__pronunciation--off');408 CARD_SPEAKER.classList.toggle('card__pronunciation--on');409 pronunciationStatus = !pronunciationStatus;410 if (!PLAYER.paused) {411 PLAYER.pause();412 PLAYER.currentTime = 0;413 } 414 } else if (event.target.closest('label')) {415 if (!TRANSLATE_CHECKBOX.checked) {416 EXAMPLE_TRANSLATE.classList.remove('set-opacity');417 MEANING_TRANSLATE.classList.remove('set-opacity');418 showTranslate = true;419 } else {420 EXAMPLE_TRANSLATE.classList.add('set-opacity');421 MEANING_TRANSLATE.classList.add('set-opacity');422 showTranslate = false;423 }424 }425 })426 NAVIGATE_NEXT.addEventListener('click', async () => {427 setWordToBackEnd(currentMode)428 if (!PLAYER.paused) {429 PLAYER.pause();430 PLAYER.currentTime = 0;431 }432 wordPosition += 1;433 createNextCard();434 });435 INPUT_CONTAINER.addEventListener('click', checkAnswer);436 document.addEventListener('keydown', () => {437 if (document.querySelector('.spaced-repetition') !== null) { 438 INPUT_FIELD.focus();439 }440 })441 document.addEventListener('keyup', (event) => {442 if (document.querySelector('.spaced-repetition') !== null) { 443 444 checkAnswer();445 if (event.code === 'Enter') {446 if (!CHECK_BUTTON.disabled === true) {447 checkWord(event, words[currentMode][wordPosition].word);448 }449 if (document.querySelector('.navigate--next') !== null) {450 if (!NAVIGATE_NEXT.classList.contains('visability-hidden') && !NAVIGATE_NEXT.classList.contains('display-none')) {451 const click = new Event('click', {452 "bubbles": true,453 "cancelable": false454 });455 NAVIGATE_NEXT.dispatchEvent(click);456 }457 458 }459 }460 461 }462 });...

Full Screen

Full Screen

comments.ts

Source:comments.ts Github

copy

Full Screen

...14 set value( s: string | SingleLineCommentOpts ) { this.update( s ); }15 get comment(): string { return this._comment; }16 set comment( s: string ) { this.update( { comment:s } ); }17 18 get spaced(): boolean { return this._spaced; }19 set spaced( newVal: boolean ) { this.update( { spaced:newVal } ); }20 protected update( inp: string | SingleLineCommentOpts = {} ) {21 inp = SingleLineComment.identify( inp );22 this._comment = inp.comment || this._comment || "";23 this._spaced = inp.spaced || this._spaced || true;24 this._value = `//${ this._spaced ? " " : "" }${ this._comment }`;25 }26 // identify and parse out the intrinsic values of a multiline comment27 static identify( inp: string | SingleLineCommentOpts = "" ): SingleLineCommentOpts {28 if( typeof inp == "string" ) {29 inp = { comment:inp };30 // inp = { comment:[ inp ].flat(), slashNewline:{}, spaced:{}, starred:[] };31 inp.spaced = inp.comment.indexOf( "// " ) == 0 || inp.comment[ 0 ] == " ";32 inp.comment = inp.comment.replace( /^(\/\/ |\/\/| )/g, "" );33 } else inp = { comment:inp.comment || "", spaced:inp.spaced || true };34 return <SingleLineComment>inp;35 }36 toMultiLine(): MultiLineComment { return new MultiLineComment( `${ this._spaced ? " " : "" }${ this._comment }${ this._spaced ? " " : "" }` ); }37}38export interface DirtyMultiLineCommentOpts {39 starred?: boolean | boolean[];40 slashNewline?: boolean | boolean[] | { start: boolean, end: boolean };41 comment?: string[] | string;42 spaced?: boolean | boolean[] | { start: boolean, end: boolean };43}44export interface MultiLineCommentOpts{45 starred?: boolean[];46 slashNewline?: { start: boolean, end: boolean };47 comment?: string[];48 spaced?: { start: boolean, end: boolean };49}50export class MultiLineComment {51 protected _value: string;52 protected _comment: string[];53 protected _starred: boolean[];54 protected _slashNewline: { start: boolean, end: boolean };55 protected _spaced: { start: boolean, end: boolean };56 constructor( s: string | string[] | DirtyMultiLineCommentOpts = "" ) { this.update( s ); }57 get value(): string { return this._value; }58 set value( newVal: string | string[] | DirtyMultiLineCommentOpts ) { this.update( newVal ); }59 get lines(): string[] { return this._comment; }60 set lines( newVal: string[] ) { this.update( { comment:newVal } ); }61 62 get comment(): string { return this._comment.join( "\n" ); }63 set comment( newVal: string | string[] ) { this.update( { comment:newVal } ); }64 get starred(): boolean[] { return this._starred; }65 set starred( newVal: boolean | boolean[] ) { this.update( { starred:newVal } ); }66 get slashNewline(): { start: boolean, end: boolean } { return this._slashNewline; }67 set slashNewline( newVal: boolean | boolean[] | { start: boolean, end: boolean } ) { this.update( { slashNewline:newVal } ); }68 get spaced(): { start: boolean, end: boolean } { return this._spaced; }69 set spaced( newVal: boolean | boolean[] | { start: boolean, end: boolean } ) { this.update( { spaced:newVal } ); }70 protected update( inp: string | string[] | DirtyMultiLineCommentOpts = {} ) {71 ( { comment:this._comment, starred:this._starred, slashNewline:this._slashNewline, spaced:this._spaced } = MultiLineComment.identify( inp ) );72 var temp = this._comment;73 this._value = `/*${ this._spaced.start ? " " : "" }${ this._slashNewline.start ? "\n" : "" }${ temp.map( ( e, i ) => { return `${ this._starred[ i ] ? " * " : "" }${ e }`; } ).join( "\n" ) }${ this._slashNewline.end ? "\n" : "" }${ this._spaced.end ? " " : "" }*/`;74 }75 // identify and parse out the intrinsic values of a multiline comment76 static identify( inp: string | string[] | DirtyMultiLineCommentOpts = "" ): MultiLineCommentOpts {77 var retVal;78 if( typeof inp == "string" ) inp = inp.split( "\n" );79 if( inp instanceof Array ) {80 retVal = { comment:[ inp ].flat(), slashNewline:{}, spaced:{}, starred:[] };81 // @TODO better way to implement82 retVal.spaced.start = retVal.comment[ 0 ].indexOf( "/* " ) == 0;83 retVal.slashNewline.start = retVal.comment[ 0 ].match( /^(\/\* |\/\*)$/g )?.length > 0;...

Full Screen

Full Screen

index.ts

Source:index.ts Github

copy

Full Screen

1import {2 Recommend,3 RecommendNameSpaced,4 SongList,5 SongListNameSpaced,6 TopList,7 TopListNameSpaced,8 Artists,9 ArtistsNameSpaced10} from '@/pages/news/children/module'11import Header, { HeaderNameSpaced } from '@/pages/header/module'12import Main, { MainNameSpaced } from '@/pages/main/module'13import Footer, { FooterNameSpaced } from '@/pages/footer/module'14import Auth, { AuthNameSpaced } from '@/pages/auth/module'15import Song, { SongNameSpaced } from '@/pages/list/module'16import Artist, { ArtistNameSpaced } from '@/pages/artist/module'17import Download, { DownloadNameSpaced } from '@/pages/download/module'18import LocalMusic, { LocalMusicNameSpaced } from '@/pages/music/module'19import Setting, { SettingNameSpaced } from '@/pages/setting/module'20import Search, { SearchNameSpaced } from '@/pages/search/module'21import Cloud, { CloudNameSpaced } from '@/pages/cloud/module'22import Layout, { LayoutNameSpaced } from '@/layout/module'23export * from '@/pages/footer/module'24export * from '@/pages/news/children/module'25export * from '@/pages/download/module'26export * from '@/pages/main/module'27export * from '@/pages/header/module'28export * from '@/pages/list/module'29export * from '@/pages/artist/module'30export * from '@/pages/music/module'31export * from '@/pages/setting/module'32export * from '@/pages/search/module'33export * from '@/pages/cloud/module'34export * from '@/layout/module'35export {36 RecommendNameSpaced,37 SongListNameSpaced,38 TopListNameSpaced,39 ArtistsNameSpaced,40 HeaderNameSpaced,41 MainNameSpaced,42 FooterNameSpaced,43 AuthNameSpaced,44 SongNameSpaced,45 ArtistNameSpaced,46 DownloadNameSpaced,47 LocalMusicNameSpaced,48 SettingNameSpaced,49 SearchNameSpaced,50 CloudNameSpaced,51 LayoutNameSpaced52}53const modules = {54 [LayoutNameSpaced]: Layout,55 [RecommendNameSpaced]: Recommend,56 [SongListNameSpaced]: SongList,57 [TopListNameSpaced]: TopList,58 [ArtistsNameSpaced]: Artists,59 [HeaderNameSpaced]: Header,60 [FooterNameSpaced]: Footer,61 [MainNameSpaced]: Main,62 [AuthNameSpaced]: Auth,63 [SongNameSpaced]: Song,64 [ArtistNameSpaced]: Artist,65 [DownloadNameSpaced]: Download,66 [LocalMusicNameSpaced]: LocalMusic,67 [SettingNameSpaced]: Setting,68 [CloudNameSpaced]: Cloud,69 [SearchNameSpaced]: Search70}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('webpagetest');2const wptClient = wpt('www.webpagetest.org');3const fs = require('fs');4const util = require('util');5const exec = util.promisify(require('child_process').exec);6const { performance } = require('perf_hooks');7const axios = require('axios');8const { exit } = require('process');9const { URL } = require('url');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Barack Obama');3page.get()4 .then(function(resp) {5 console.log(resp);6 })7 .catch(function(err) {8 console.log(err);9 });

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = new WebPageTest('www.webpagetest.org','A.9b9c0c9a28f1d4d4b8a8e1e0c0e7d2b2', { runs: 1, fvonly: 1, location: 'Dulles:Chrome' });2 if (err) return console.error(err);3 console.log('Test status: ' + data.statusText);4 console.log('Test ID: ' + data.data.testId);5 console.log('Test URL: ' + data.data.summary);6 console.log('Test results: ' + data.data.userUrl);7 console.log('Test results: ' + data.data.jsonUrl);8 console.log('Test results: ' + data.data.xmlUrl);9 console.log('Test results: ' + data.data.csvUrl);10 console.log('Test results: ' + data.data.harUrl);11 console.log('Test results: ' + data.data.pagespeedUrl);12 console.log('Test results: ' + data.data.videoUrl);13 console.log('Test results: ' + data.data.runs);14 console.log('Test results: ' + data.data

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var api = new wpt('www.webpagetest.org');3var options = {4};5api.runTest(testURL, options, function(err, data) {6 if (err) return console.error(err);7 console.log('Test status:', data.statusText);8 console.log('Test ID:', data.data.testId);9 console.log('Test results:', data.data.summary);10 console.log('Test results:', data.data.average);11 console.log('Test results:', data.data.median);12 console.log('Test results:', data.data.standardDeviation);13 console.log('Test results:', data.data.median.firstView);14 console.log('Test results:', data.data.median.firstView.SpeedIndex);15 console.log('Test results:', data.data.median.firstView.TTFB);16 console.log('Test results:', data.data.median.firstView.render);17 console.log('Test results:', data.data.median.firstView.fullyLoaded);18 console.log('Test results:', data.data.median.firstView.SpeedIndex);19 console.log('Test results:', data.data.median.firstView.requests);20 console.log('Test results:', data.data.median.firstView.bytesIn);21 console.log('Test results:', data.data.median.firstView.bytesOut);22 console.log('Test results:', data.data.median.firstView.bytesInDoc);23 console.log('Test results:', data.data.median.firstView.bytesOutDoc);24 console.log('Test results:', data.data.median.firstView.connections);25 console.log('Test results:', data.data.median.firstView.requestsDoc);26 console.log('Test results:', data.data.median.firstView.requestsFull);27 console.log('Test results:', data.data.median.firstView.responses_200);28 console.log('Test results:', data.data.median.firstView.responses_404);29 console.log('Test results:', data.data.median.firstView.responses_other);30 console.log('Test results:', data.data.median.firstView.result);31 console.log('Test results:', data.data.median.firstView.test

Full Screen

Using AI Code Generation

copy

Full Screen

1var WebPageTest = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.9e2d0e1f7a1b8d6f0c0f3a6b7d6e8c6a');3}, function(err, data) {4 if (err) return console.error(err);5 console.log('Test submitted for %s', data.data.testUrl);6 console.log('View your test at %s', data.data.summary);7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var WebPageTest = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.7d1f1a6c7a8b3d6c7d3b3c3b7e8f2c1e');3}, function(err, data) {4 if (err) return console.error(err);5 console.log('Test Results: %j', data.data.runs[1].firstView);6 console.log('View the test at: %s', data.data.userUrl);7});

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 wpt 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