How to use exec_result method in wpt

Best JavaScript code snippet using wpt

Command.js

Source:Command.js Github

copy

Full Screen

1'use strict';2function Command()3{4 // red-cursor command5 var cd = /^ *cd *(~|\/|\.|\.\.|\w+)?\/? *;?$/;6 var ls = /^ *(ls|dir) *;?$/;7 var clear = /^ *clear *;?$/;8 var echo = /^ *(echo *|echo .*?);?$/;9 var df = /^ *df *;?$/;10 var pwd = /^ *pwd *;?$/;11 var cat = /^ *cat *([a-zA-Z0-9._-]+|&gt; *[a-zA-Z0-9_.-]+)? *;?$/;12 var history = /^ *history *;?$/;13 var bc = /^ *bc *(#[a-fA-F0-9]{3,6})? *;?$/;14 var fs = /^ *fs *([1-9][0-9])? *;?$/;15 var date = /^ *date *;?$/;16 var help = /^ *help *;?$/;17 var open = /^ *open *([^ ]+)? *;?$/;18 // badges command19 var badge = /^ *badge *([1-9]|10)(\.\.(?:[1-9]|10))? *(["'])((?:(?!\3).)*:(?:(?!\3).)*)\3 *(?:(default|#[0-9a-f]{3,6}):(default|#[0-9a-f]{3,6}))? *;?/i;20 // 0 = all21 // 1 = 1-2022 // 2 = ..1-20 or undefined23 // 3 = ' or "24 // 4 = "prefix:suffix"25 // 5 = default or prefix-color26 // 6 = default or suffix-color27 // line command28 var line = /^ *line *([1-5]) *(\d+) *(?:(default|#[0-9a-f]{3,6}))? *;?/i;29 // 0 = all30 // 1 = style31 // 2 = length32 // 3 = color33 // button command34 var button = /button *(["'])((?:(?!\1).)*)\1 *(?:(none|default|#[0-9a-f]{3,6}))? *;?/i;35 // 0 = all36 // 1 = " or '37 // 2 = text38 // 3 = color | default | none39 // badge-font-size40 var bfs = /^ *bfs *([5-9]|[1-9][0-9])? *;?$/;41 // print height, width and font-size42 var hwf = /^ *hwf *;?$/;43 // shows an input to copy from for old browsers44 var shc = /^ *shc *;?$/;45 // badges-theme46 // G => git-hub,47 // S => stack-overflow48 // T => twitter49 // F => face-book50 var theme = /^ *theme *(G|S|T|F) *;?$/;51 // set the text-fill for button and path52 var TF = /^ *TF(?:=(default|#[0-9a-fA-F]{3,6})) *;?$/;53 // path-stroke (color for stroke)54 var BS = /^ *BS(?:=(none|default|#[0-9a-fA-F]{3,6})) *;?$/;55 // delimiter56 var DLM = /^ *DLM(?:=([0-9]|[1-9][0-9])) *;?$/;57 // button-base-width 5-9958 var BCL = /^ *BCL(?:=([5-9]|[1-9][0-9])) *;?$/;59 // path-stroke-width for button60 var BSW = /^ *BSW(?:=([0-9])) *;?$/;61 var active_clipboard = false;62 // handle two key-press for Alter key63 // var twice_alt_flag = false;64 // storing each command as history65 this.histories = [];66 this.h_index = 0;67 var line_buffer_backup = '';68 // store the xxx.exec( command ) result69 var exec_result = null;70 // check if a command is valid or NOT71 this.check = function( command )72 {73 if( ( exec_result = cd.exec( command ) ) )74 {75 // var arg = cd.exec( command )[ 1 ];76 this.cd( exec_result[ 1 ] );77 }78 else79 if( ls.exec( command ) )80 {81 this.ls();82 }83 else84 if( clear.exec( command ) )85 {86 this.clear();87 }88 else89 if( echo.exec( command ) )90 {91 var string = command.replace( /\s+/g, ' ' )92 .replace( '$PATH', path.PATH );93 text( string.substr( 5, string.length ) + ' ' );94 screen.newline();95 }96 else97 if( df.exec( command ) )98 {99 this.df();100 }101 else102 if( pwd.exec( command ) )103 {104 text( path.pwd.join( '/' ) );105 screen.newline();106 }107 else108 if( ( exec_result = cat.exec( command ) ) )109 {110 // var arg = cat.exec( command )[ 1 ];111 this.cat( exec_result[ 1 ] );112 }113 else114 if( history.exec( command ) )115 {116 this.history();117 }118 else119 if( ( exec_result = bc.exec( command ) ) )120 {121 var color = exec_result[ 1 ];122 if( color === undefined )123 {124 screen.background();125 text( 'reset to default' );126 screen.newline();127 }128 else129 {130 screen.background( color );131 }132 }133 else134 if( ( exec_result = fs.exec( command ) ) )135 {136 var size = exec_result[ 1 ];137 if( size === undefined )138 {139 screen.font_size();140 print( [141 'reset to default: 15px',142 'range is from 10 to 99.',143 ] );144 }145 else146 {147 screen.font_size( size );148 }149 }150 else151 if( date.exec( command ) )152 {153 text( Date() );154 screen.newline();155 }156 else157 if( help.exec( command ) )158 {159 this.help();160 }161 else162 if( ( exec_result = open.exec( command ) ) )163 {164 var media = exec_result[ 1 ];165 if( media === undefined )166 {167 text( 'argument required be a media type' );168 screen.newline();169 }170 else171 {172 var cwd = path.cwd();173 if( media in path.root[ cwd ] && path.root[ cwd ][ media ] === 'media' )174 {;175 window.open( './' + cwd + '/' + media, '_blank', path.readable[ cwd ][ media ] );176 }177 else178 {179 text( '(' + media + ')' + ' is not media type' );180 screen.newline();181 }182 }183 }184 else185 if( ( exec_result = badge.exec( command ) ) )186 {187 // var array = badge.exec( command );188 exec_result[ 5 ] = ( exec_result[ 5 ] === undefined ? badges.colors[ 0 ] : exec_result[ 5 ] );189 exec_result[ 6 ] = ( exec_result[ 6 ] === undefined ? badges.colors[ 1 ] : exec_result[ 6 ] );190 badges.colors[ 0 ] = ( exec_result[ 5 ] === 'default' ? '#434343' : exec_result[ 5 ] );191 badges.colors[ 1 ] = ( exec_result[ 6 ] === 'default' ? '#CB0000' : exec_result[ 6 ] );192 var begin = parseInt( exec_result[ 1 ] );193 if( exec_result[ 2 ] !== undefined )194 {195 var end = parseInt( exec_result[ 2 ].substr( 2, 2 ) );196 }197 var ps = exec_result[ 4 ].split( ':' );198 print( [199 'style : ' + begin + ' to ' + end,200 'prefix: "' + ps[ 0 ] + '" color: ' + exec_result[ 5 ],201 'suffix: "' + ps.slice( 1, ps.length ) + '" color: ' + exec_result[ 6 ],202 ] );203 // for 1..10204 if( end > begin )205 {206 while( begin <= end )207 {208 exec_result[ 1 ] = begin;209 text( begin + ' => ' )210 badges.create( exec_result );211 ++begin;212 }213 }214 // for 10..1215 else216 if( end < begin )217 {218 while( begin >= end )219 {220 exec_result[ 1 ] = begin;221 text( begin + ' => ' )222 badges.create( exec_result );223 --begin;224 }225 }226 else227 {228 // create SVG and add it to div.display229 badges.create( exec_result );230 }231 var display = doc.class( 'display' );232 clipboard.value = '';233 if( end === undefined )234 {235 var temp = display[ display.length - 1 ].innerHTML236 clipboard.value = temp;237 temp = temp.replace( />/, ">\n" )238 .replace( /<\/([a-z]+)>/gi, "</$1>\n" );239 if( enable_svg_log === true )240 {241 console.log( temp );242 }243 text( 'char-height/max-width : ' + badges.char_height + '/' + badges.max_width + '(px)' );244 screen.newline();245 clipboard.select();246 if( document.execCommand("Copy") === true )247 {248 text( 'copy style [' + begin + '] to clipboard was successful' );249 }250 else251 {252 text( 'copy style [' + begin + '] to clipboard was unsuccessful' );253 }254 }255 else256 {257 text( 'nothing was copied to your clipboard.' );258 }259 screen.newline();260 }261 else // print help for badge command262 if( command.search( /^ *badge/ ) === 0 )263 {264 print( [265 'badge [style] [prefix:suffix] [default|#prefix-color:default|#suffix-color]',266 'style is between 1 to 20',267 'prefix and suffix should be surrounded using single-quote or double-quote',268 'prefix-color and suffix color are optional',269 'example: badge 1 "one:one"',270 "example: badge 1 'one:one'",271 'NOTE that colon ":" is the delimiter and necessary',272 'for more example: cd doc/ then cat how-to-use or just hit alt-h',273 ]);274 }275 else // run line command276 if( ( exec_result = line.exec( command ) ) )277 {278 // var exec_result = line.exec( command );279 exec_result[ 3 ] = ( exec_result[ 3 ] === undefined ? lines.color : exec_result[ 3 ] );280 lines.color = ( exec_result[ 3 ] === 'default' ? '#CB0000' : exec_result[ 3 ] );281 print( [282 'style : ' + exec_result[ 1 ],283 'length: ' + exec_result[ 2 ],284 'color : ' + lines.color285 ] );286 // create SVG-line and add it to div.display287 lines.create( exec_result );288 var display = doc.class( 'display' );289 clipboard.value = '';290 var temp = display[ display.length - 1 ].innerHTML291 clipboard.value = temp;292 temp = temp.replace( />/, ">\n" )293 .replace( /<\/([a-z]+)>/gi, "</$1>\n" );294 if( enable_svg_log === true )295 {296 console.log( temp );297 }298 text( 'char-height/max-width : ' + lines.char_height + '/' + lines.max_width + '(px)' );299 screen.newline();300 clipboard.select();301 if( document.execCommand("Copy") === true )302 {303 text( 'copy style [' + exec_result[ 1 ] + '] to clipboard was successful' );304 }305 else306 {307 text( 'copy style [' + exec_result[ 1 ] + '] to clipboard was unsuccessful' );308 }309 screen.newline();310 }311 else // print help for line command312 if( command.search( /^ *line/ ) === 0 )313 {314 print( [315 'line [style] [length] [default|#color]',316 'style is between 1 to 5',317 'color is optional. the default value: "#CB0000"',318 'example: line 1 100',319 'example: line 5 100 #0F0',320 ]);321 }322 else // button command323 if( ( exec_result = button.exec( command ) ) )324 {325 // we need the index 2, and 3326 // var exec_result = button.exec( command );327 var temp = {328 undefined : buttons.fill,329 'default' : '#434343',330 'none' : 'none',331 };332 buttons.fill = temp[ exec_result[ 3 ] ];333 // when there is hex-color, temp returns 'undefined' to buttons.fill will be undefined334 if( buttons.fill === undefined )335 {336 buttons.fill = exec_result[ 3 ];337 }338 print( [339 'text/fill : ' + exec_result[ 2 ].match( /^(?:[()<>])?(.*?)(?:[()<>])?$/ )[ 1 ] + '/' + buttons.text_fill ,340 'button-fill : ' + buttons.fill,341 ]);342 // create a button and add it to div.display, exec_result[ 2 ] is the "text"343 buttons.create( exec_result[ 2 ] );344 var display = doc.class( 'display' );345 clipboard.value = '';346 var temp = display[ display.length - 1 ].innerHTML347 clipboard.value = temp;348 temp = temp.replace( />/, ">\n" )349 .replace( /<\/([a-z]+)>/gi, "</$1>\n" );350 if( enable_svg_log === true )351 {352 console.log( temp );353 }354 text( 'button-height/button-width : ' + buttons.button_height + '/' + buttons.button_width + '(px)' );355 screen.newline();356 clipboard.select();357 if( document.execCommand("Copy") === true )358 {359 text( 'copy style [' + buttons.style + '] to clipboard was successful' );360 }361 else362 {363 text( 'copy style [' + buttons.style + '] to clipboard was unsuccessful' );364 }365 screen.newline();366 }367 else // print help for button command368 if( command.search( /^ *button */ ) === 0 )369 {370 print( [371 'button "text" [default|#background-color]',372 'color is optional; default value: "#434334"',373 'example: button "home"',374 'example: button "home" #0F0',375 ]);376 }377 else // badge-font-size (for both badge and button)378 if( ( exec_result = bfs.exec( command ) ) )379 {380 var size = exec_result[ 1 ];381 if( size === undefined )382 {383 doc.id( 'badge-font-size' ).style.fontSize = '15px';384 print( [385 'reset to default: 15px',386 'range is from 5 to 99.'387 ] );388 }389 else390 {391 print( [392 'set (badge/button/line) font-size to: ' + size + 'px',393 'run the command without argument to reset it.'394 ] );395 doc.id( 'badge-font-size' ).style.fontSize = ( size + 'px' );396 }397 // update hwf: height, width and font-size398 badges.init();399 buttons.init();400 lines.init();401 }402 else // print a help for bfs command403 if( command.search( /^ *bfs/ ) === 0 )404 {405 print( [406 'wrong number, range is from 5 to 99',407 'for resetting to default use it without argument',408 ] );409 }410 else411 if( hwf.exec( command ) )412 {413 print( [414 'char-height: ' + badges.char_height,415 'char-width : ' + badges.char_width,416 'font-size : ' + badges.font_size,417 ] );418 }419 else // toggle input.clipboard420 if( shc.exec( command ) )421 {422 if( active_clipboard === false )423 {424 clipboard.style.top = '10px';425 active_clipboard = true;426 }427 else428 {429 clipboard.style.top = '-100px';430 active_clipboard = false;431 }432 }433 else // badge-text-color434 if( TF.exec( command ) )435 {436 badges.text_color = TF.exec( command )[ 1 ];437 buttons.text_fill = badges.text_color;438 badges.text_color = badges.text_color === 'default' ? '#FFF' : badges.text_color;439 buttons.text_fill = buttons.text_fill === 'default' ? '#FFF' : buttons.text_fill;440 text( 'set text-color to ' + badges.text_color );441 screen.newline();442 }443 else // badge-text-color help444 if( command.search( /^ *TF/ ) === 0 )445 {446 print( [447 'TF ' + badges.text_color,448 'add a hex color and change the default',449 'or reset it: TF=default',450 ] );451 }452 else // badge delimiter for separation453 if( ( exec_result = DLM.exec( command ) ) )454 {455 badges.delimiter = parseInt( exec_result[ 1 ] );456 lines.delimiter = badges.delimiter;457 print( [458 'set delimiter to ' + badges.delimiter,459 'you can reset it using DLM=0'460 ] );461 }462 else // print help for DLM463 if( command.search( /^ *DLM/ ) === 0 )464 {465 print( [466 'DLM ' + badges.delimiter,467 'A number between 1 to 99',468 'default is 0',469 ] );470 }471 else // button-max-width472 if( (exec_result = BCL.exec( command ) ) )473 {474 buttons.char_length = parseInt( exec_result[ 1 ] );475 print( [476 'set button-char-length to ' + buttons.char_length,477 'you can reset it using BCL=10'478 ] );479 }480 else // print help for BCL481 if( command.search( /^ *BCL/ ) === 0 )482 {483 print( [484 'BCL ' + buttons.char_length,485 'A number between 5 to 99',486 'default is 10',487 ] );488 }489 else // button-stroke-width490 if( ( exec_result = BSW.exec( command ) ) )491 {492 buttons.stroke_width = parseInt( exec_result[ 1 ] )493 print( [494 'set button-stroke-width to ' + buttons.stroke_width,495 'you can reset it using BSW=10'496 ] );497 }498 else // print help for stroke-width499 if( command.search( /^ *BSW/ ) === 0 )500 {501 print( [502 'BSW ' + buttons.stroke_width,503 'A number between 0 to 9',504 'default is 0.',505 ] );506 }507 else // button path-stroke508 if( ( exec_result = BS.exec( command ) ) )509 {510 buttons.stroke = exec_result[ 1 ];511 buttons.stroke = buttons.stroke === 'default' ? '#434343' : buttons.stroke;512 text( 'set button-stroke to ' + buttons.stroke );513 screen.newline();514 }515 else // badge-text-color help516 if( command.search( /^ *BS/ ) === 0 )517 {518 print( [519 'BS ' + buttons.stroke,520 'add a hex color and change the default',521 'or reset it: BS=default',522 ] );523 }524 else // badge-theme525 if( ( exec_result = theme.exec( command ) ) )526 {527 // git-hub #CB0000528 // stack overflow #FF8000529 // twitter #1DA1F2530 // face-book #4867AA531 switch( exec_result[ 1 ] )532 {533 case 'G':534 badges.colors[ 1 ] = '#CB0000';535 break;536 case 'S':537 badges.colors[ 1 ] = '#FF8000';538 break;539 case 'T':540 badges.colors[ 1 ] = '#1DA1F2';541 break;542 case 'F':543 badges.colors[ 1 ] = '#4867AA';544 break;545 default:546 badges.colors[ 1 ] = '#CB0000';547 break;548 }549 text( 'set background-suffix-color to ' + badges.colors[ 1 ] );550 screen.newline();551 }552 else // print help for badge-theme553 if( command.search( /^ *theme/ ) === 0 )554 {555 print( [556 'default badge-theme is github (G)',557 'but you can also use:',558 'stack-overflow => (S)',559 'titter => (T)',560 'facebook => (F)',561 ] );562 }563 // end of commands processing564 // if on the main.js we do not check for empty line565 // then here we should use and [if-else] statement566 // since I have used it on main.js, just [else] will be enough.567 else568 {569 text( command + ': command not found' );570 screen.newline();571 }572 }573 // handle Alter key574 this.alter = function( char )575 {576 switch( char )577 {578 // Alter + l: off/on console.log()579 case 'l':580 if( enable_log === true )581 {582 console.log( 'console log was disabled.' );583 enable_log = false;584 }585 else586 {587 console.log( 'console log was enabled.' );588 enable_log = true;589 }590 break;591 // open new table and goes to source code on git-hub592 case 'b':593 window.open( 'https://github.com/k-five/badge-for-git', '_blank' ).focus();594 break;595 case 'v':596 if( enable_svg_log === false )597 {598 enable_svg_log = true;599 text( 'log SVG-code to console was enabled.' );600 }601 else602 {603 enable_svg_log = false;604 text( 'log SVG-code to console was disabled.' );605 }606 screen.newline();607 screen.hide_cursor();608 screen.prompt( path.get() );609 screen.add( 'SPAN', 'row' );610 screen.cursor();611 screen.newline();612 break;613 // Alt-h print how-to-use614 case 'h':615 text( 'how-to-use:' );616 screen.newline();617 print( path.readable[ 'doc' ][ 'how-to-use' ] );618 screen.hide_cursor();619 screen.prompt( path.get() );620 screen.add( 'SPAN', 'row' );621 screen.cursor();622 screen.newline();623 break;624 // Alt-n print NOTE625 case 'n':626 text( 'NOTE:' );627 screen.newline();628 print( path.readable[ 'doc' ][ 'NOTE' ] );629 screen.hide_cursor();630 screen.prompt( path.get() );631 screen.add( 'SPAN', 'row' );632 screen.cursor();633 screen.newline();634 break;635 // Alt-c print contributor636 case 'c':637 text( 'contributor:' );638 screen.newline();639 print( path.readable[ 'doc' ][ 'contributor' ] );640 screen.hide_cursor();641 screen.prompt( path.get() );642 screen.add( 'SPAN', 'row' );643 screen.cursor();644 screen.newline();645 break;646 default:647 break;648 }649 }650 // handle Control + key651 this.control = function( char )652 {653 switch( char )654 {655 case 'u':656 if( screen.cursor_pos === 0 )657 {658 line_buffer_backup = screen.get( 'row' ).innerHTML;659 screen.get( 'row' ).innerHTML = '';660 screen.line_buffer = ''661 }662 break;663 case 'y':664 screen.get( 'row' ).innerHTML += line_buffer_backup;665 screen.line_buffer += line_buffer_backup;666 break;667 // clear the screen668 case 'l':669 screen.clear()670 screen.prompt( path.get() );671 screen.add( 'SPAN', 'row', screen.line_buffer );672 screen.cursor();673 screen.newline();674 // see init.js675 if( enable_log )676 {677 console.log( 'clear the screen with Control + L' );678 }679 break;680 // print help, equivalent to type: help681 case 'h':682 command.help();683 screen.hide_cursor();684 screen.prompt( path.get() );685 screen.add( 'SPAN', 'row' );686 screen.cursor();687 screen.newline();688 default:689 break;690 }691 }692 this.shift = function( char )693 {694 // currently nothing695 }696 this.ls = function()697 {698 var reserve_space = 20;699 var format_width = ( reserve_space * screen.char_width );700 var widnow_width = window.innerWidth;701 var max_width = format_width;702 var size = 0;703 var cwd = path.cwd();704 var files = path.root[ cwd ];705 var width = window.innerWidth;706 var file;707 for( file in files )708 {709 // concatenation file name + ( 20 - file.length ) space for formatting output710 // like printf( "%-20s", file );711 text( file + " ".repeat( reserve_space - file.length ), path.root[ cwd ][ file ] );712 max_width += format_width;713 // if we are close/near to edge of window then we should add new line714 if( max_width >= widnow_width )715 {716 screen.newline();717 max_width = format_width;718 }719 }720 if( file !== undefined )721 {722 screen.newline();723 }724 }725 this.cd = function( arg )726 {727 var cwd = path.cwd();728 switch( arg )729 {730 // if the cd has no argument731 case undefined:732 break;733 case '~':734 path.pwd = [ 'home', 'badge-for-git' ];735 break;736 case '/':737 text( "cd: / Permission denied" );738 screen.newline();739 break;740 case '.':741 break;742 case '..':743 // if the last index of pwd equals "badge-for-git", then we do not have744 // permission to go further, it is just a dummy745 if( cwd === 'badge-for-git' )746 {747 text( "cd: " + path.pwd[ 1 ] + "/: Permission denied" );748 screen.newline();749 }750 else751 {752 // now we are not in the home directory and thus we can go back753 path.pwd.pop();754 cwd = path.cwd();755 for( var file in path.root[ cwd ] )756 {757 text( file );758 screen.newline();759 }760 }761 break;762 default:763 if( path.root[ cwd ][ arg ] === 'directory' && arg in path.root[ cwd ] )764 {765 path.pwd.push( arg );766 cwd = path.cwd();767 for( var file in path.root[ cwd ] )768 {769 text( file );770 screen.newline();771 }772 }773 else774 {775 text( 'cd (' + arg + ') No such file or directory' );776 screen.newline();777 }778 break;779 }780 } // end of cd781 this.clear = function()782 {783 screen.clear()784 screen.prompt( path.get() );785 screen.add( 'SPAN', 'row' );786 screen.cursor();787 screen.newline();788 if( enable_log )789 {790 console.log( 'clear the screen with clear command' );791 }792 }793 this.df = function()794 {795 var df =796 [797 'Filesystem 1K-blocks Used Available Use% Mounted on',798 'udev 1011376 0 1011376 0% /dev',799 'tmpfs 206316 8956 197360 5% /run',800 '/dev/sda3 196730180 25927424 160786400 14% /',801 'tmpfs 1031568 596 1030972 1% /dev/shm',802 'tmpfs 5120 4 5116 1% /run/lock',803 'tmpfs 1031568 0 1031568 0% /sys/fs/cgroup',804 'tmpfs 206316 60 206256 1% /run/user/1000'805 ];806 print( df );807 }808 this.cat = function( arg )809 {810 var redirect = false;811 if( arg.indexOf( '&gt;' ) != -1 )812 {813 redirect = true;814 arg = arg.substr( arg.indexOf( '&gt;' ) + 4, arg.lenght ).trim();815 }816 else817 {818 arg = arg.trim();819 }820 var cwd = path.cwd();821 if( arg in path.root[ cwd ] )822 {823 if( path.root[ cwd ][ arg ] === 'readable' )824 {825 if( redirect === true )826 {827 //write();828 }829 else830 {831 print( path.readable[ cwd ][ arg ] );832 }833 }834 else835 {836 text( arg + ' is a ' + path.root[ cwd ][ arg ] + ' and NOT readable' )837 screen.newline();838 }839 }840 else841 {842 text( '(' + arg + ') was not found in ' + cwd + ' directory' )843 screen.newline();844 }845 }846 this.history = function()847 {848 var length = this.histories.length;849 if( length > 0 )850 {851 var index = 0;852 while( index < length )853 {854 text( ( index + 1 ) + ': ' + this.histories[ index ] );855 screen.newline();856 ++index;857 }858 }859 }860 this.help = function()861 {862 var h =863 [864 'cmd: arg: des:',865 '......................',866 'ls No list files and directories' ,867 'cd Yes navigation between directories',868 'bc Yes set/reset background color',869 'fs Yes set/reset font size',870 'df No dumpy file-system report',871 'cat Yes read the contents of a file',872 'pwd No print current path',873 'echo Yes echos its arguments',874 'date No print date in GMT',875 'help No print (this) help',876 'open Yes open a media',877 'clear No clear the screen',878 'history No print all entered commands',879 '',880 'badge Yes mine command, create badge',881 'bfs Yes badge-font-size, set font-size for badges (all)',882 'hwf No show height, width, and font-size',883 'shc No show clipboard for copying source code',884 ' You no need to use this command since by',885 ' default it will be copied to your clipboard.',886 ' It is there for old-browsers.',887 'theme Yes set a theme default is G. use: G,S,T or F',888 ' G:github, S:stack-overflow, T:twitter, F:facebook',889 'TF= Yes text-fill, (button/badge) default: #FFF',890 'DLM= Yes delimiter, default: 0, range[5-99]',891 'BCL= yes button-char-length, default: 10, range[5-99]',892 'BS= Yes button-stroke, default: #CB0000',893 'BSW= Yes button-stroke-width, default: 0, range[0-9]',894 '',895 'some key bindings:',896 '..................',897 'Control + l : clear the screen',898 'Control + h : print help',899 'Alter + l : enable/disable console.log()',900 'Alter + b : open source code of the application',901 'Alter + h : print "how-to-use" file in doc directory',902 'Alter + n : print "NOTE" file in doc directory',903 'Alter + c : print "contributor" file in doc directory',904 'Alter + v : enable/disable logging SVG-source-code in console',905 'TAB : tab completion for file/directory names',906 'Alter + u : cut the whole line (= left side of the cursor)',907 'Alter + y : paste (= yank) the last line by Alter-u',908 ];909 print( h );910 // if there is the 'guide', then it will return non-null;911 // otherwise it will return null. But with doc.class it does not return912 // "null" and return "undefined". Thus if we use "class" if statement913 // should use "undefined" and if we use "id" it should use "null"914 var guide = doc.id( 'guide' );915 if( guide !== null )916 {917 doc.id( 'terminal' ).removeChild( guide );918 var copyright = document.createElement( 'SPAN' );919 copyright.innerHTML = '<p id="copyright">badge-for-git Copyright &copy; ' + ( ( Date().toString().split( ' ' ) )[3] ) + ' Shakiba <sup><a href="https://github.com/k-five/badge-for-git" target="_blank">src</a></sup></p>';920 document.body.appendChild( copyright );921 }922 } // end of help923 function text( string, class_name = "text" )924 {925 var span = document.createElement( 'SPAN' );926 var contents = document.createTextNode( string );927 span.appendChild( contents );928 doc.id( 'terminal' ).appendChild( span );929 span.classList.add( class_name );930 }931 function print( contents )932 {933 var length = contents.length;934 var index = 0;935 while( index < length )936 {937 text( contents[ index ] );938 screen.newline();939 ++index;940 }941 }942}...

Full Screen

Full Screen

regular_expressions.js

Source:regular_expressions.js Github

copy

Full Screen

1console.log("learning regular expressions");2// to find a match or matches form a string we use regular expression for it 3// to write anything of regular expression we put that thing in backslashes4// to use two flags at once we write tehm together like this -> gi5let reg = /harry/ // this is a regular expression literal 6console.log(reg);7console.log(reg.source);// source means what you have written in regular expression literal8let str = "hello harry how are you, are you fine because i am fine harry and one more thing harry loved programming"9// functions to match expressions10// -----------------------------------------------------------------------------------------11// 1. exec() - this function will return an array when find match and null when nothing matches12let exec_result = reg.exec(str);13console.log(exec_result);14exec_result = reg.exec(str); // at this time second and third occurence are not logged in console because this function starts from the string starting and print the same occurrance. To prevent this we use flag in the regular expression like below 15reg = /harry/g // it means global and tells that check all whole string16exec_result = reg.exec(str);17console.log(exec_result);18exec_result = reg.exec(str);19console.log(exec_result);20exec_result = reg.exec(str);21console.log(exec_result);22exec_result = reg.exec(str);23console.log(exec_result);24reg = /harry/i // it means case insensitive 25str = "hello hArry how are you, are you fine because i am fine Harry and one more thing harRY loved programming"26exec_result = reg.exec(str);27console.log(exec_result);28exec_result = reg.exec(str);29console.log(exec_result);30exec_result = reg.exec(str);31console.log(exec_result);32//-------------------------------------------------------------------------------------------33// 2. test -> return true or false respective of match found34exec_result = reg.test(str);35console.log(exec_result);36reg = /harry/37exec_result = reg.test(str);38console.log(exec_result);39//-------------------------------------------------------------------------------------------40// 3. match -> this returns null when match not found and returns an array when match found41// difference between match() and exec() is, exec() only return one occurrence and match() return all the occurrence when regular expression in global 42reg = /harry/g43str = "hello harry how are you, are you fine because i am fine harry and one more thing harry loved programming"44exec_result = str.match(reg);45console.log(exec_result);46//-------------------------------------------------------------------------------------------47// 4. search() -> it returns index of first match or returns -1 integer48reg = /harry/g49str = "hello harry how are you, are you fine because i am fine harry and one more thing harry loved programming"50exec_result = str.search(reg);51console.log(exec_result)52str = "hello hArry how are you, are you fine because i am fine Harry and one more thing harRY loved programming"53exec_result = str.search(reg);54console.log(exec_result);55//-------------------------------------------------------------------------------------------56// 5. replace -> returns new replaced string with all the replacement57reg = /harry/g58str = "hello harry how are you, are you fine because i am fine harry and one more thing harry loved programming"59exec_result = str.replace(reg, "REPLACED");60console.log(exec_result);61str = "hello hArry how are you, are you fine because i am fine Harry and one more thing harRY loved programming"62exec_result = str.replace(reg, "REPLACED");63console.log(exec_result);...

Full Screen

Full Screen

MMM-NotificationTrigger.js

Source:MMM-NotificationTrigger.js Github

copy

Full Screen

...59 payload_result = fire.payload60 }61 var exec_result = fire.exec62 if (exec_result && typeof exec_result == "function") {63 exec_result = exec_result(payload)64 }65 if(fire.delay) {66 setTimeout((fire, trigger, payload, exec) => {67 this.sendNotification(fire, payload)68 if (exec) {69 this.sendSocketNotification("EXEC", {70 trigger:trigger,71 fire: fire,72 exec: exec73 })74 }75 }, fire.delay, fire.fire, trigger.trigger, payload_result, exec_result)76 } else {77 this.sendNotification(fire.fire, payload_result)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.log(err);4 wpt.getTestResults(data.data.testId, function(err, data) {5 if (err) return console.log(err);6 console.log(data);7 });8});9#### runTest(url, options, callback)10* `options` - Options for the test (see below)11* `callback` - callback function(err, data) where data is the JSON response from WPT12* `location` - Location to test from (default: 'Dulles:Chrome')13* `timeout` - Test timeout in seconds (default: 300)14* `firstViewOnly` - Only test the first view (default: false)15* `run` - Number of times to repeat the test (default: 1)16* `pollResults` - Poll for test results every X seconds (default: 5)17* `connectivity` - Emulated connection type (default: 'Cable')18* `bwDown` - Emulated download bandwidth (default: 0)19* `bwUp` - Emulated upload bandwidth (default: 0)20* `latency` - Emulated latency (default: 0)21* `plr` - Packet loss rate (default: 0)22* `mobile` - Emulate a mobile device (default: false)23* `mobileDevice` - Mobile device to emulate (default: 'Nexus 5')24* `mobileCarrier` - Mobile carrier to emulate (default: 'Verizon')25* `noExternals` - Don't load any external resources (default: false)26* `spof` - Simulate a single point of failure (default: false)27* `video` - Record video of the test (default: false)28* `timeline` - Record timeline data (default: false)29* `trace` - Record a network trace (default: false)30* `sensitive` - Include any sensitive data in the test (default: false)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 console.log(data);4 wpt.exec_result(data, function(err, data) {5 console.log(data);6 });7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4 videoParams: {5 }6};7wpt.runTest(url, options, function(err, data) {8 if (err) return console.log(err);9 wpt.exec_result(data.data.testId, function(err, data) {10 if (err) return console.log(err);11 console.log(data);12 });13});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var test = new wpt('www.webpagetest.org', '<your key>');5test.runTest(testUrl, options, function(err, data) {6 if (err) return console.error(err);7 test.getTestResults(data.data.testId, function(err, data) {8 if (err) return console.error(err);9 console.log(data.data.median.firstView.SpeedIndex);10 });11});12### `WptApi(url, key, [options])`13### `runTest(url, [options], [callback])`

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptool = require('wptool');2var path = require('path');3var fs = require('fs');4var cmd = "dir";5var args = ["/b"];6var options = {cwd: path.dirname(__filename)};7var cb = function(err, stdout, stderr) {8 if (err) {9 console.log("Error: " + err);10 return;11 }12 console.log("Result: " + stdout);13}14wptool.exec_result(cmd, args, options, cb);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var api = new wpt('A.2a8d0b4d0c9e9b9e1c8a4a0f1c1d1b1d');3api.runTest(test_url, function(err, data) {4 if (err) return console.error(err);5 api.getTestResults(data.data.testId, function(err, data) {6 if (err) return console.error(err);7 console.log(data);8 });9});10var wpt = require('webpagetest');11var api = new wpt('API_KEY');12api.runTest('URL', options, callback);

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