Best JavaScript code snippet using ava
EffectComposer.js
Source:EffectComposer.js  
1import {2	Clock,3	LinearFilter,4	Mesh,5	OrthographicCamera,6	PlaneGeometry,7	RGBAFormat,8	Vector2,9	WebGLRenderTarget10} from '../../../build/three.module.js';11import { CopyShader } from '../shaders/CopyShader.js';12import { ShaderPass } from '../postprocessing/ShaderPass.js';13import { MaskPass } from '../postprocessing/MaskPass.js';14import { ClearMaskPass } from '../postprocessing/MaskPass.js';15var EffectComposer = function ( renderer, renderTarget ) {16	this.renderer = renderer;17	if ( renderTarget === undefined ) {18		var parameters = {19			minFilter: LinearFilter,20			magFilter: LinearFilter,21			format: RGBAFormat22		};23		var size = renderer.getSize( new Vector2() );24		this._pixelRatio = renderer.getPixelRatio();25		this._width = size.width;26		this._height = size.height;27		renderTarget = new WebGLRenderTarget( this._width * this._pixelRatio, this._height * this._pixelRatio, parameters );28		renderTarget.texture.name = 'EffectComposer.rt1';29	} else {30		this._pixelRatio = 1;31		this._width = renderTarget.width;32		this._height = renderTarget.height;33	}34	this.renderTarget1 = renderTarget;35	this.renderTarget2 = renderTarget.clone();36	this.renderTarget2.texture.name = 'EffectComposer.rt2';37	this.writeBuffer = this.renderTarget1;38	this.readBuffer = this.renderTarget2;39	this.renderToScreen = true;40	this.passes = [];41	// dependencies42	if ( CopyShader === undefined ) {43		console.error( 'THREE.EffectComposer relies on CopyShader' );44	}45	if ( ShaderPass === undefined ) {46		console.error( 'THREE.EffectComposer relies on ShaderPass' );47	}48	this.copyPass = new ShaderPass( CopyShader );49	this.clock = new Clock();50};51Object.assign( EffectComposer.prototype, {52	swapBuffers: function () {53		var tmp = this.readBuffer;54		this.readBuffer = this.writeBuffer;55		this.writeBuffer = tmp;56	},57	addPass: function ( pass ) {58		this.passes.push( pass );59		pass.setSize( this._width * this._pixelRatio, this._height * this._pixelRatio );60	},61	insertPass: function ( pass, index ) {62		this.passes.splice( index, 0, pass );63		pass.setSize( this._width * this._pixelRatio, this._height * this._pixelRatio );64	},65	removePass: function ( pass ) {66		const index = this.passes.indexOf( pass );67		if ( index !== - 1 ) {68			this.passes.splice( index, 1 );69		}70	},71	isLastEnabledPass: function ( passIndex ) {72		for ( var i = passIndex + 1; i < this.passes.length; i ++ ) {73			if ( this.passes[ i ].enabled ) {74				return false;75			}76		}77		return true;78	},79	render: function ( deltaTime ) {80		// deltaTime value is in seconds81		if ( deltaTime === undefined ) {82			deltaTime = this.clock.getDelta();83		}84		var currentRenderTarget = this.renderer.getRenderTarget();85		var maskActive = false;86		var pass, i, il = this.passes.length;87		for ( i = 0; i < il; i ++ ) {88			pass = this.passes[ i ];89			if ( pass.enabled === false ) continue;90			pass.renderToScreen = ( this.renderToScreen && this.isLastEnabledPass( i ) );91			pass.render( this.renderer, this.writeBuffer, this.readBuffer, deltaTime, maskActive );92			if ( pass.needsSwap ) {93				if ( maskActive ) {94					var context = this.renderer.getContext();95					var stencil = this.renderer.state.buffers.stencil;96					//context.stencilFunc( context.NOTEQUAL, 1, 0xffffffff );97					stencil.setFunc( context.NOTEQUAL, 1, 0xffffffff );98					this.copyPass.render( this.renderer, this.writeBuffer, this.readBuffer, deltaTime );99					//context.stencilFunc( context.EQUAL, 1, 0xffffffff );100					stencil.setFunc( context.EQUAL, 1, 0xffffffff );101				}102				this.swapBuffers();103			}104			if ( MaskPass !== undefined ) {105				if ( pass instanceof MaskPass ) {106					maskActive = true;107				} else if ( pass instanceof ClearMaskPass ) {108					maskActive = false;109				}110			}111		}112		this.renderer.setRenderTarget( currentRenderTarget );113	},114	reset: function ( renderTarget ) {115		if ( renderTarget === undefined ) {116			var size = this.renderer.getSize( new Vector2() );117			this._pixelRatio = this.renderer.getPixelRatio();118			this._width = size.width;119			this._height = size.height;120			renderTarget = this.renderTarget1.clone();121			renderTarget.setSize( this._width * this._pixelRatio, this._height * this._pixelRatio );122		}123		this.renderTarget1.dispose();124		this.renderTarget2.dispose();125		this.renderTarget1 = renderTarget;126		this.renderTarget2 = renderTarget.clone();127		this.writeBuffer = this.renderTarget1;128		this.readBuffer = this.renderTarget2;129	},130	setSize: function ( width, height ) {131		this._width = width;132		this._height = height;133		var effectiveWidth = this._width * this._pixelRatio;134		var effectiveHeight = this._height * this._pixelRatio;135		this.renderTarget1.setSize( effectiveWidth, effectiveHeight );136		this.renderTarget2.setSize( effectiveWidth, effectiveHeight );137		for ( var i = 0; i < this.passes.length; i ++ ) {138			this.passes[ i ].setSize( effectiveWidth, effectiveHeight );139		}140	},141	setPixelRatio: function ( pixelRatio ) {142		this._pixelRatio = pixelRatio;143		this.setSize( this._width, this._height );144	}145} );146var Pass = function () {147	// if set to true, the pass is processed by the composer148	this.enabled = true;149	// if set to true, the pass indicates to swap read and write buffer after rendering150	this.needsSwap = true;151	// if set to true, the pass clears its buffer before rendering152	this.clear = false;153	// if set to true, the result of the pass is rendered to screen. This is set automatically by EffectComposer.154	this.renderToScreen = false;155};156Object.assign( Pass.prototype, {157	setSize: function ( /* width, height */ ) {},158	render: function ( /* renderer, writeBuffer, readBuffer, deltaTime, maskActive */ ) {159		console.error( 'THREE.Pass: .render() must be implemented in derived pass.' );160	}161} );162// Helper for passes that need to fill the viewport with a single quad.163Pass.FullScreenQuad = ( function () {164	var camera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );165	var geometry = new PlaneGeometry( 2, 2 );166	var FullScreenQuad = function ( material ) {167		this._mesh = new Mesh( geometry, material );168	};169	Object.defineProperty( FullScreenQuad.prototype, 'material', {170		get: function () {171			return this._mesh.material;172		},173		set: function ( value ) {174			this._mesh.material = value;175		}176	} );177	Object.assign( FullScreenQuad.prototype, {178		dispose: function () {179			this._mesh.geometry.dispose();180		},181		render: function ( renderer ) {182			renderer.render( this._mesh, camera );183		}184	} );185	return FullScreenQuad;186} )();...LoginRegistration.js
Source:LoginRegistration.js  
1import React, {useContext,useState} from "react";2import {TouchableOpacity,  Text, View , TextInput  ,StyleSheet} from 'react-native';34import {Context} from "../../App";56export default function LoginRegistration() {7    const [logInfo, setLogInfo] = useState({email: '', pass: '' , passConfirm:'',name:'',img:''});8    const [logOrReg , setLogOrReg] = useState('log')9    const [error,setErrorType] = useState('null')10    const {auth} = useContext(Context)11    const Registration = async ()=>{12        try {13            if(logInfo.pass.length <6) throw new Error('pass-lenght')14            if(logInfo.pass != logInfo.passConfirm) throw new Error('pass-not-confirm')15            const {user} = await auth.createUserWithEmailAndPassword(logInfo.email,logInfo.pass);16            await user.updateProfile({17                displayName: logInfo.name,18                photoURL:logInfo.img,19            })2021        }22        catch (e){23            setErrorType(e.message)2425        }26        finally {27            setLogInfo({email: '', pass: '' , passConfirm:'',name:'',img:''});28        }29    }30    const Logining = async ()=>{31        try {32            await auth.signInWithEmailAndPassword(logInfo.email,logInfo.pass);33        }34        catch (e){35            setErrorType(e.message)36        }37        finally {38            setLogInfo({email: '', pass: '' , passConfirm:'',name:'',img:''});39        }40    }41    return (42        <View>43            {(logOrReg =='log') ? LogForm() :RegForm()}44            <TouchableOpacity style = {styles.appButtonContainer } onPress={ ()=>{setErrorType('null'); setLogInfo({email: '', pass: '' , passConfirm:'',name:'',img:''}); setLogOrReg((logOrReg =='log') ?'reg':'log')  }}  ><Text style = {styles.appButtonText}>{(logOrReg =='log') ?'Sign Up':'Sign In'} </Text></TouchableOpacity>45            {46                (error != 'null')?<Text> Error,Check if the data is correct</Text> //FIX47                    :<></>48            }49        </View>50    )5152    function LogForm() {53        return (54            <View >55                <TextInput style = {styles.block} value={logInfo.email} onChangeText={text => setLogInfo({email: text, pass: logInfo.pass , passConfirm:logInfo.passConfirm,name:logInfo.name,img:logInfo.img})}56                           placeholder='Email'></TextInput>57                <View style = {styles.view}></View>58                <TextInput secureTextEntry={true} style = {styles.block}  value={logInfo.pass} onChangeText={text => setLogInfo({email: logInfo.email, pass: text, passConfirm:logInfo.passConfirm,name:logInfo.name,img:logInfo.img})}59                           placeholder='Password'></TextInput>60                <View style = {styles.view}></View>61                <TouchableOpacity style = {styles.appButtonContainer} onPress={Logining}  ><Text style = {styles.appButtonText}>Sign In</Text></TouchableOpacity>62                <View style = {styles.view}></View>63            </View>64        );65    }6667    function RegForm() {68        return (69            <View>70                <TextInput style = {styles.block} value={logInfo.name} onChangeText={text => setLogInfo({email: logInfo.email, pass: logInfo.pass , passConfirm:logInfo.passConfirm,name:text,img:logInfo.img})}71                           placeholder='Name'></TextInput>72                <View style = {styles.view}></View>73                <TextInput style = {styles.block} value={logInfo.img} onChangeText={text => setLogInfo({email: logInfo.email, pass: logInfo.pass , passConfirm:logInfo.passConfirm,name:logInfo.name,img:text})}74                           placeholder='Image (scr)'></TextInput>75                <View style = {styles.view}></View>76                <TextInput secureTextEntry={false} style = {styles.block} value={logInfo.email} onChangeText={text => setLogInfo({email: text, pass: logInfo.pass , passConfirm:logInfo.passConfirm,name:logInfo.name,img:logInfo.img})}77                           placeholder='Email'></TextInput>78                <View style = {styles.view}></View>79                <TextInput secureTextEntry={true} style = {styles.block} value={logInfo.pass} onChangeText={text => setLogInfo({email: logInfo.email, pass: text , passConfirm:logInfo.passConfirm,name:logInfo.name,img:logInfo.img})}80                           placeholder='Password'></TextInput>81                <View style = {styles.view}></View>82                <TextInput secureTextEntry={true} style = {styles.block} value={logInfo.passConfirm} onChangeText={text => setLogInfo({email: logInfo.email, pass: logInfo.pass , passConfirm:text,name:logInfo.name,img:logInfo.img})}83                           placeholder='Confirm Password'></TextInput>84                <View style = {styles.view}></View>85                <TouchableOpacity style = {styles.appButtonContainer} onPress={Registration}><Text style = {styles.appButtonText}>Sign Up</Text></TouchableOpacity>86                <View style = {styles.view}></View>87            </View>88        );89    }90}9192const styles = StyleSheet.create({93    block: {94        fontSize: 20,95        width:300,96        height:50,97        backgroundColor: 'white',98        borderRadius:10,99        alignItems:"center",100        justifyContent:"center",101        padding:10,102    },103    components: {104        flex: 1,105        justifyContent:"center",106        alignItems:"center",107        backgroundColor: '#e3e8e4',108        alignItems:"center",109        justifyContent:"center",110    },111    view: {112        margin:6,113    },114    button: {115        width:300,116        height:50,117        backgroundColor: "blue"118    },119    appButtonContainer: {120        elevation: 8,121        backgroundColor: "#009688",122        borderRadius: 10,123        paddingVertical: 10,124        paddingHorizontal: 115,125      },126      appButtonText: {127        fontSize: 18,128        color: "#fff",129        fontWeight: "bold",130        alignSelf: "center",131        textTransform: "uppercase",132      }133})
...password.js
Source:password.js  
1var length = readInt('How long? ');2function start(){3    generate(length);4    println(pass);5}6var pass = '';7var numKey = [];8function generate(length){9    for(var i = 0; i < length; i++){10        var h = Randomizer.nextInt(0,62);11        numKey.push(h);12    }13    for(var i = 0; i < numKey.length; i++){14            if(numKey[i] == 0){15                pass == pass + '0'16            }else if(numKey[i] == 1){17                pass = pass + '1'18            }else if(numKey[i] == 2){19                pass = pass + '2'20            }else if(numKey[i] == 3){21                pass = pass + '3'22            }else if(numKey[i] == 4){23                pass = pass + '4'24            }else if(numKey[i] == 5){25                pass = pass + '5'26            }else if(numKey[i] == 6){27                pass = pass + '6'28            }else if(numKey[i] == 7){29                pass = pass + '7'30            }else if(numKey[i] == 8){31                pass = pass + '8'32            }else if(numKey[i] == 9){33                pass = pass + '9'34            }else if(numKey[i] == 10){35                pass = pass + 'a'36            }else if(numKey[i] == 12){37                pass = pass + 'b'38            }else if(numKey[i] == 13){39                pass = pass + 'c'40            }else if(numKey[i] == 14){41                pass = pass + 'd'42            }else if(numKey[i] == 15){43                pass = pass + 'e'44            }else if(numKey[i] == 16){45                pass = pass + 'f'46            }else if(numKey[i] == 17){47                pass = pass + 'g'48            }else if(numKey[i] == 18){49                pass = pass + 'h'50            }else if(numKey[i] == 19){51                pass = pass + 'i'52            }else if(numKey[i] == 20){53                pass = pass + 'j'54            }else if(numKey[i] == 21){55                pass = pass + 'k'56            }else if(numKey[i] == 22){57                pass = pass + 'l'58            }else if(numKey[i] == 23){59                pass = pass + 'm'60            }else if(numKey[i] == 24){61                pass = pass + 'n'62            }else if(numKey[i] == 25){63                pass = pass + 'o'64            }else if(numKey[i] == 26){65                pass = pass + 'p'66            }else if(numKey[i] == 27){67                pass = pass + 'q'68            }else if(numKey[i] == 28){69                pass = pass + 'r'70            }else if(numKey[i] == 29){71                pass = pass + 's'72            }else if(numKey[i] == 30){73                pass = pass + 't'74            }else if(numKey[i] == 31){75                pass = pass + 'u'76            }else if(numKey[i] == 32){77                pass = pass + 'v'78            }else if(numKey[i] == 33){79                pass = pass + 'w'80            }else if(numKey[i] == 34){81                pass = pass + 'x'82            }else if(numKey[i] == 35){83                pass = pass + 'y'84            }else if(numKey[i] == 36){85                pass = pass + 'z'86            }else if(numKey[i] == 37){87                pass = pass + 'A'88            }else if(numKey[i] == 38){89                pass = pass + 'B'90            }else if(numKey[i] == 39){91                pass = pass + 'C'92            }else if(numKey[i] == 40){93                pass = pass + 'D'94            }else if(numKey[i] == 41){95                pass = pass + 'E'96            }else if(numKey[i] == 42){97                pass = pass + 'F'98            }else if(numKey[i] == 43){99                pass = pass + 'G'100            }else if(numKey[i] == 44){101                pass = pass + 'H'102            }else if(numKey[i] == 45){103                pass = pass + 'I'104            }else if(numKey[i] == 46){105                pass = pass + 'J'106            }else if(numKey[i] == 47){107                pass = pass + 'K'108            }else if(numKey[i] == 48){109                pass = pass + 'L'110            }else if(numKey[i] == 49){111                pass = pass + 'M'112            }else if(numKey[i] == 50){113                pass = pass + 'N'114            }else if(numKey[i] == 51){115                pass = pass + 'O'116            }else if(numKey[i] == 52){117                pass = pass + 'P'118            }else if(numKey[i] == 53){119                pass = pass + 'Q'120            }else if(numKey[i] == 54){121                pass = pass + 'R'122            }else if(numKey[i] == 55){123                pass = pass + 'S'124            }else if(numKey[i] == 56){125                pass = pass + 'T'126            }else if(numKey[i] == 57){127                pass = pass + 'U'128            }else if(numKey[i] == 58){129                pass = pass + 'V'130            }else if(numKey[i] == 59){131                pass = pass + 'W'132            }else if(numKey[i] == 60){133                pass = pass + 'X'134            }else if(numKey[i] == 61){135                pass = pass + 'Y'136            }else if(numKey[i] == 62){137                pass = pass + 'Z'138            }139    }...application-passwords.js
Source:application-passwords.js  
1/* global appPass, wp */2( function( $, appPass ) {3	var $appPassSection = $( '#application-passwords-section' ),4		$newAppPassForm = $appPassSection.find( '.create-application-password' ),5		$newAppPassField = $newAppPassForm.find( '.input' ),6		$newAppPassButton = $newAppPassForm.find( '.button' ),7		$appPassTwrapper = $appPassSection.find( '.application-passwords-list-table-wrapper' ),8		$appPassTbody = $appPassSection.find( 'tbody' ),9		$appPassTrNoItems = $appPassTbody.find( '.no-items' ),10		$removeAllBtn = $( '#revoke-all-application-passwords' ),11		tmplNewAppPass = wp.template( 'new-application-password' ),12		tmplAppPassRow = wp.template( 'application-password-row' ),13		tmplNotice = wp.template( 'application-password-notice' ),14		testBasicAuthUser = Math.random().toString( 36 ).replace( /[^a-z]+/g, '' ),15		testBasicAuthPassword = Math.random().toString( 36 ).replace( /[^a-z]+/g, '' );16	$.ajax( {17		url: appPass.root + appPass.namespace + '/test-basic-authorization-header',18		method: 'POST',19		beforeSend: function( xhr ) {20			xhr.setRequestHeader( 'Authorization', 'Basic ' + btoa( testBasicAuthUser + ':' + testBasicAuthPassword ) );21		},22		error: function( jqXHR ) {23			if ( 404 === jqXHR.status ) {24				$newAppPassForm.before( tmplNotice( {25					type: 'error',26					message: appPass.text.no_credentials27				} ) );28			}29		}30	} ).done( function( response ) {31		if ( response.PHP_AUTH_USER === testBasicAuthUser && response.PHP_AUTH_PW === testBasicAuthPassword ) {32			// Save the success in SessionStorage or the like, so we don't do it on every page load?33		} else {34			$newAppPassForm.before( tmplNotice( {35				type: 'error',36				message: appPass.text.no_credentials37			} ) );38		}39	} );40	$newAppPassButton.click( function( e ) {41		e.preventDefault();42		var name = $newAppPassField.val();43		if ( 0 === name.length ) {44			$newAppPassField.focus();45			return;46		}47		$newAppPassField.prop( 'disabled', true );48		$newAppPassButton.prop( 'disabled', true );49		$.ajax( {50			url: appPass.root + appPass.namespace + '/application-passwords/' + appPass.user_id + '/add',51			method: 'POST',52			beforeSend: function( xhr ) {53				xhr.setRequestHeader( 'X-WP-Nonce', appPass.nonce );54			},55			data: {56				name: name57			}58		} ).done( function( response ) {59			$newAppPassField.prop( 'disabled', false ).val( '' );60			$newAppPassButton.prop( 'disabled', false );61			$newAppPassForm.after( tmplNewAppPass( {62				name: name,63				password: response.password64			} ) );65			$appPassTbody.prepend( tmplAppPassRow( response.row ) );66			$appPassTwrapper.show();67			$appPassTrNoItems.remove();68		} );69	} );70	$appPassTbody.on( 'click', '.delete', function( e ) {71		e.preventDefault();72		var $tr = $( e.target ).closest( 'tr' ),73			slug = $tr.data( 'slug' );74		$.ajax( {75			url: appPass.root + appPass.namespace + '/application-passwords/' + appPass.user_id + '/' + slug,76			method: 'DELETE',77			beforeSend: function( xhr ) {78				xhr.setRequestHeader( 'X-WP-Nonce', appPass.nonce );79			}80		} ).done( function( response ) {81			if ( response ) {82				if ( 0 === $tr.siblings().length ) {83					$appPassTwrapper.hide();84				}85				$tr.remove();86			}87		} );88	} );89	$removeAllBtn.on( 'click', function( e ) {90		e.preventDefault();91		$.ajax( {92			url: appPass.root + appPass.namespace + '/application-passwords/' + appPass.user_id,93			method: 'DELETE',94			beforeSend: function( xhr ) {95				xhr.setRequestHeader( 'X-WP-Nonce', appPass.nonce );96			}97		} ).done( function( response ) {98			if ( parseInt( response, 10 ) > 0 ) {99				$appPassTbody.children().remove();100				$appPassSection.children( '.new-application-password' ).remove();101				$appPassTwrapper.hide();102			}103		} );104	} );105	$( document ).on( 'click', '.application-password-modal-dismiss', function( e ) {106		e.preventDefault();107		$( '.new-application-password.notification-dialog-wrap' ).hide();108	} );109	// If there are no items, don't display the table yet.  If there are, show it.110	if ( 0 === $appPassTbody.children( 'tr' ).not( $appPassTrNoItems ).length ) {111		$appPassTwrapper.hide();112	}...findNum.js
Source:findNum.js  
1//get the text for validation and then posting if valid2function getResults(){3  var contentText=document.getElementById('content-in').value;4      contentText=contentText.trim();5  var passArray=contentText.split("\n");6  var i;7  var line="";8  var passData="";9  var maxCharCount=0;10  var hasallfields=0;11  var valid=0;12  for (i = 0; i < passArray.length; i++) {13    line=passArray[i].trim();14    line = line.replace(/(\r\n|\n|\r)/gm,"");15    passData+=" " + line;16    maxCharCount=line.length;17      if(maxCharCount==0 || i==passArray.length-1) {18        if(passportHasAllData(passData)) {19          hasallfields++;20          if(passportValidate(passData)) {21            //console.log(passData);22            valid++;23          }24        }25        passData="";26      }27  }28  alert(`The number of passports with all the required fields is: ${hasallfields} \n while the fully valid passport number is ${valid}`);29  return(false);30}31//this function is checking only one pass's data.32function passportHasAllData(passText) {33  var valid=0;34  var neededData=["byr","iyr","eyr","hgt","hcl","ecl","pid"];35  var optional="cid";36    if(neededData.every(x => (passText.indexOf(x) > -1))) {37      valid=1;passportValidate38    }39 return(valid);40}41/*42  byr (Birth Year) - four digits; at least 1920 and at most 2002.43  iyr (Issue Year) - four digits; at least 2010 and at most 2020.44  eyr (Expiration Year) - four digits; at least 2020 and at most 2030.45  hgt (Height) - a number followed by either cm or in:46      If cm, the number must be at least 150 and at most 193.47      If in, the number must be at least 59 and at most 76.48  hcl (Hair Color) - a # followed by exactly six characters 0-9 or a-f.49  ecl (Eye Color) - exactly one of: amb blu brn gry grn hzl oth.50  pid (Passport ID) - a nine-digit number, including leading zeroes.51*/52function passportValidate(passText) {53  var field=passText.split(" ");54  var passCol;55  var passIndex;56  var passValue;57  var valid=1;58  var eyeColor=["amb","blu","brn","gry","grn","hzl","oth"];59  for(var i=0; i<field.length; i++) {60    passCol=field[i].trim().split(":");61    if(passCol.length > 1) {62      passIndex=passCol[0].trim();63      passValue=passCol[1].trim();64      switch (passIndex) {65        case "byr":66          if(!(passValue.match(/^\d{4}$/i) && passValue >=1920 && passValue <=2002)) {67            valid=0;68          }69          break;70        case "iyr":71          if(!(passValue.match(/^\d{4}$/i) && passValue >=2010 && passValue <=2020)) {72            valid=0;73          }74          break;75        case "eyr":76          if(!(passValue.match(/^\d{4}$/i) && passValue >=2020 && passValue <=2030)) {77            valid=0;78          }79          break;80        case "hgt":81          if(passValue.match(/cm$/)) {82            passValue=passValue.match(/^(\d{3})cm$/);83            if(!(passValue && passValue[1]>=150 && passValue[1]<=193)) {84              valid=0;85            } else {86              //console.log(passValue);87            }88          } else if (passValue.match(/in$/)) {89            passValue=passValue.match(/^(\d{2})in$/);90            if(!(passValue && passValue[1]>=59 && passValue[1]<=76)) {91              valid=0;92            } else {93              //console.log(passValue);94            }95          } else {96            valid=0;97          }98          break;99        case "hcl":100          if(!(passValue.match(/^#[0-9a-f]{6}$/))) {101            valid=0;102          }103          break;104        case "ecl":105          if(!(eyeColor.includes(passValue))) {106            valid=0;107          }108          break;109        case "pid":110          if(!(passValue.match(/^\d{9}$/i))) {111            valid=0;112          }113          break;114        default:115          // DO NOTHING for now116      } 117    }118  }119  return(valid);...loginMy.js
Source:loginMy.js  
12//è·åinputçææid3var user = document.getElementById("user");4var pwd = document.getElementById("pwd");5var surePwd = document.getElementById("surePwd");678//è·åspançææid9var user_pass = document.getElementById("user_pass");10var pwd_pass = document.getElementById("pwd_pass");11var surePwd_pass = document.getElementById("surePwd_pass");12function checkUser(){13    //妿æµç§°æªè¾å
¥ï¼åæç¤ºè¾å
¥æµç§°14    if(!user.value){15        user_pass.style.fontSize = "13px";16        user_pass.style.width="31%";17        user_pass.style.height="2em";18        user_pass.style.textAlign="center";19        user_pass.style.lineHeight="2em";20        user_pass.style.marginTop='0.05%'21        user_pass.innerHTML = 'ä½ è¿æ²¡æå¡«åç¨æ·åå¦ã';22        user_pass.style.display="block";23    }24    else if(user.value){25        user_pass.style.display="none";26    }27}2829//è¾å
¥å¯ç æç¤º30function checkUser1(){31    //妿æªè¾å
¥å¯ç ï¼åæç¤ºè¯·è¾å
¥å¯ç 32    if(!pwd.value){33        pwd_pass.style.fontSize = "13px";34        pwd_pass.style.width="31%";35        pwd_pass.style.height="2em";36        pwd_pass.style.textAlign="center";37        pwd_pass.style.lineHeight="2em";38        pwd_pass.innerHTML = 'ä½ è¿æ²¡æå¡«åå¯ç å¦ã';39        pwd_pass.style.display="block";40    }41    else{42        pwd_pass.innerHTML ='';43        pwd_pass.style.backgroundColor= "#fff";44        pwd_pass.style.border="none";45        pwd_pass.style.display="none";4647    }4849}5051//确认å¯ç æç¤º52function checkUser2(){53    //忬¡ç¡®è®¤å¯ç 54    if(!surePwd.value){55        surePwd_pass.style.fontSize = "13px";56        surePwd_pass.style.width="31%";57        surePwd_pass.style.height="2em";58        surePwd_pass.style.textAlign="center";59        surePwd_pass.style.lineHeight="2em";60        surePwd_pass.innerHTML = 'ä½ è¿æ²¡æå¡«åéªè¯ç å¦';61        surePwd_pass.style.display="block";62    }6364    else{65        surePwd_pass.innerHTML ='';66        surePwd_pass.style.backgroundColor= "#fff";67        surePwd_pass.style.border="none";68        surePwd_pass.style.display="none";69    }70}7172function  submitB(){7374    if(!user.value){75        user_pass.style.fontSize = "13px";76        user_pass.style.width="31%";77        user_pass.style.height="2em";78        user_pass.style.textAlign="center";79        user_pass.style.lineHeight="2em";80        user_pass.innerHTML = 'è¯·å¡«åæ¨çç¨æ·åã';81        user.focus();82        return false;83    }84    if(!pwd.value){85        pwd_pass.style.fontSize = "13px";86        pwd_pass.style.width="31%";87        pwd_pass.style.height="2em";88        pwd_pass.style.textAlign="center";89        pwd_pass.style.lineHeight="2em";90        pwd_pass.innerHTML = 'è¯·å¡«åæ¨çç¨æ·å¯ç ã';91        pwd.focus();92        return false;93    }9495    if(!surePwd_pass.value){96        surePwd_pass.style.fontSize = "13px";97        surePwd_pass.style.width="31%";98        surePwd_pass.style.height="2em";99        surePwd_pass.style.textAlign="center";100        surePwd_pass.style.lineHeight="2em";101        surePwd_pass.innerHTML = 'è¯·å¡«åæ¨çç»å½éªè¯ã';102        surePwd_pass.focus();103        return false;104    }105    else{106        var f = sendParam();107        return true;108    }109    110}
...change-pass-app.js
Source:change-pass-app.js  
1function checkForm(password){2    var check = 0;3    var submit = false;4    var oldPass = $("#oldPass").val();5    if(oldPass == ""){6        $("#errorOldPass").text("Máºt khẩu cÅ© không ÄÆ°á»£c bá» trá»ng!");7        $("#oldPass").css("border-color", "#dc3545"); 8        $("#lblOldPass").css("color", "#dc3545");9        check = 0;10    }11    else{12        if(oldPass != password){13            $("#errorOldPass").text("Máºt khẩu cÅ© không khá»p!");14            $("#oldPass").css("border-color", "#dc3545"); 15            $("#lblOldPass").css("color", "#dc3545");16            check = 0;17        }18        else{19            $("#errorOldPass").text("");20            $("#oldPass").removeAttr("style");21            $("#lblOldPass").css("color", "black"); 22        }     23        check++;24    }25    var newPass = $("#newPass").val();26    if(newPass == ""){27        $("#errorNewPass").text("Máºt khẩu má»i không ÄÆ°á»£c bá» trá»ng!");28        $("#newPass").css("border-color", "#dc3545"); 29        $("#lblNewPass").css("color", "#dc3545");30        check = 0;31    }32    else{     33        if(newPass.length < 7){34            $("#errorNewPass").text("Máºt khẩu Ãt nhất 7 ký tá»±!");35            $("#newPass").css("border-color", "#dc3545"); 36            $("#lblNewPass").css("color", "#dc3545");37            check = 0;38        }39        else{40            if(newPass == password){41                $("#errorNewPass").text("Máºt khẩu má»i không ÄÆ°á»£c giá»ng vá»i máºt khẩu cÅ©!");42                $("#newPass").css("border-color", "#dc3545"); 43                $("#lblNewPass").css("color", "#dc3545");44                check = 0;45            }46            else{47                $("#errorNewPass").text("");48                $("#newPass").removeAttr("style");49                $("#lblNewPass").css("color", "black");         50                check++;51            }          52        }      53    }54    var confirmPass = $("#confirmPass").val();55    if(confirmPass == ""){56        $("#errorConfirmPass").text("Xác nháºn máºt khẩu không ÄÆ°á»£c bá» trá»ng!");57        $("#confirmPass").css("border-color", "#dc3545"); 58        $("#lblConfirmPass").css("color", "#dc3545");59        check = 0;60    }61    else{     62        if(confirmPass != newPass){63            $("#errorConfirmPass").text("Xác nháºn máºt khẩu không khá»p!");64            $("#confirmPass").css("border-color", "#dc3545"); 65            $("#lblConfirmPass").css("color", "#dc3545");66            check = 0;67        }68        else{69            $("#errorConfirmPass").text("");70            $("#confirmPass").removeAttr("style");71            $("#lblConfirmPass").css("color", "black");         72            check++;73        }74        75    }76    if(check == 3){77        submit = true;78    }79    return submit;80}81var app = angular.module("change-pass-app", []);82app.controller("change-pass-ctrl", function ($scope, $http) {83	$scope.form = {};84    $scope.formPass = {};85	$scope.initialize = function () {86    $http.get("/rest/user/account").then((resp) => {87      $scope.form = resp.data;88      $scope.form.birthday = new Date($scope.form.birthday);89	  console.log(resp.data);90    });91  };92  $scope.initialize();93  $scope.update = function(){94	  if(checkForm($scope.form.password)){95        var item = angular.copy($scope.form);96        $http.put(`/rest/user/account/change-password`, item).then(resp => {97            location.reload();98        }).catch(error => {99            alert("Lá»i thêm sản phẩm")             100        }); 101	  }102  }...RegStep3.js
Source:RegStep3.js  
1import React from 'react';2import { PassInput } from "./PassInput";3import { FormLabel } from '@material-ui/core';4import '../auth.scss';5export const RegistrationStep3 = ({ value, onChange, onPassValidChange }) => {6  const [confirmPass, setValues] = React.useState("");7  const [isPassMatched, setPassMatch] = React.useState(null);8  const [strongPass, setStrongPass] = React.useState({9    capital: false,10    length: false,11    specChar: false,12    small: false,13    digits: false,14    isPassValid: false15  });16  const checkConfirmPassHandler = (pass) => {17    setValues(pass.target.value);18    if (value === pass.target.value) {19      setPassMatch(true);20      onPassValidChange(strongPass.isPassValid);21    } else if (value.length === pass.target.value.length) {22      onPassValidChange(false);23      setPassMatch(false);24    } else {25      setPassMatch(null);26      onPassValidChange(false);27    }28  };29  const passDigits = /[0-9]/;30  const passSmallLetters = /[a-z]/;31  const passUpperLetters = /[A-Z]/;32  const passSpecCharacters = /[-+_!@#$%^&*.,?]/;33  const handlerPassChange = (e) => {34    onChange(e);35    checkIsPassStrong(e.target.value)36  }37  const checkIsPassStrong = (val) => {38    setStrongPass({39      ...strongPass,40      length: val.length >= 8,41      digits: passDigits.test(val),42      small: passSmallLetters.test(val),43      capital: passUpperLetters.test(val),44      specChar: passSpecCharacters.test(val),45      isPassValid: val.length >= 8 && passDigits.test(val) && passSmallLetters.test(val) && passUpperLetters.test(val) && passSpecCharacters.test(val)46    });47  }48  return (49    <div className="regForm" id="reg-step3-company-details">50      <PassInput name="password" value={value} onChange={handlerPassChange} required={true}></PassInput>51      <PassInput name="confPassword" value={confirmPass} onChange={checkConfirmPassHandler}52        required={true} labelName="Confirm Password" isError={isPassMatched === false} errorMsg="Password doesn't match"></PassInput>53      <section className="sec-strong-pass-res">54        <FormLabel className={strongPass.specChar ? 'exist' : 'missing'} >Must contain special characters</FormLabel>55        <FormLabel className={strongPass.length   ? 'exist' : 'missing'} >Length must exceed 8 characters</FormLabel>56        <FormLabel className={strongPass.capital  ? 'exist' : 'missing'} >Must contain capital letters</FormLabel>57        <FormLabel className={strongPass.small    ? 'exist' : 'missing'} >Must contain small letters</FormLabel>58        <FormLabel className={strongPass.digits   ? 'exist' : 'missing'} >Must contain digits</FormLabel>59      </section>60    </div>61  )...Using AI Code Generation
1const test = require('ava');2test('foo', t => {3  t.pass();4});5test('bar', async t => {6  const bar = Promise.resolve('bar');7  t.is(await bar, 'bar');8});9const assert = require('assert');10describe('Array', function() {11  describe('#indexOf()', function() {12    it('should return -1 when the value is not present', function() {13      assert.equal([1, 2, 3].indexOf(4), -1);14    });15  });16});17describe('A suite', function() {18  it('contains spec with an expectation', function() {19    expect(true).toBe(true);20  });21});22test('two plus two is four', () => {23  expect(2 + 2).toBe(4);24});25var test = require('tape');26test('two plus two is four', function(t) {27  t.plan(1);28  t.equals(2 + 2, 4);29});30QUnit.test('hello test', function(assert) {31  assert.ok(1 == '1', 'Passed!');32});33describe('A suite', function() {Using AI Code Generation
1test('foo', t => {2    t.pass();3});4test('foo', t => {5    t.fail();6});7test('foo', t => {8    t.is(1, 1);9});10test('foo', t => {11    t.not(1, 2);12});13test('foo', t => {14    t.deepEqual({a: 1}, {a: 1});15});16test('foo', t => {17    t.notDeepEqual({a: 1}, {a: 2});18});19test('foo', t => {20    t.true(1);21});22test('foo', t => {23    t.false(0);24});25test('foo', t => {26    t.is(1, 1);27});28test('foo', t => {29    t.not(1, 2);30});31test('foo', t => {32    t.deepEqual({a: 1}, {a: 1});33});34test('foo', t => {35    t.notDeepEqual({a: 1}, {a: 2});36});37test('foo', t => {38    t.true(1);39});40test('foo', t => {41    t.false(0);42});43test('foo', t => {44    t.is(1, 1);45});46test('foo', t => {47    t.not(1, 2);48});49test('foo', t => {50    t.deepEqual({a: 1}, {a: 1});51});52test('foo', t => {53    t.notDeepEqual({a: 1}, {a: 2});54});Using AI Code Generation
1import test from 'ava';2test('foo', t => {3    t.pass();4});5test('bar', async t => {6    const bar = Promise.resolve('bar');7    t.is(await bar, 'bar');8});9"scripts": {10  },Using AI Code Generation
1import test from 'ava';2test('my passing test', t => {3	t.pass();4});5import test from 'ava';6test('my failing test', t => {7	t.fail();8});9import test from 'ava';10test('my passing test', t => {11	t.is(1, 1);12});13import test from 'ava';14test('my passing test', t => {15	t.not(1, 2);16});17import test from 'ava';18test('my passing test', t => {19	t.deepEqual({a: 1}, {a: 1});20});21import test from 'ava';22test('my passing test', t => {23	t.notDeepEqual({a: 1}, {a: 2});24});25import test from 'ava';26test('my passing test', t => {27	t.true(1);28});29import test from 'ava';30test('my passing test', t => {31	t.false(0);32});33import test from 'ava';34test('my passing test', t => {35	t.regex('abc', /a/);36});37import test from 'ava';38test('my passing test', t => {39	t.notRegex('abc', /b/);40});41import test from 'ava';42test('my passing test', t => {43	t.ifError(0);44});45import test from 'ava';46test('my passing test', t => {47	t.throws(() => {48		throw new Error('error');49	});50});51import test from 'ava';52test('my passing test', t => {53	t.notThrows(() => {54		return 1;55	});56});57import test from 'ava';58test('my passing test', t => {59	t.plan(1);60	return Promise.resolve(3).then(n => {61		t.is(n, 3);62	});63});64import testUsing AI Code Generation
1var test = require('ava');2test('foo', t => {3    t.pass();4});5test('bar', async t => {6    const bar = Promise.resolve('bar');7    t.is(await bar, 'bar');8});9var test = require('ava');10test('foo', t => {11    t.pass();12});13test('bar', async t => {14    const bar = Promise.resolve('bar');15    t.is(await bar, 'bar');16});17var test = require('ava');18test('foo', t => {19    t.pass();20});21test('bar', async t => {22    const bar = Promise.resolve('bar');23    t.is(await bar, 'bar');24});25var test = require('ava');26test('foo', t => {27    t.pass();28});29test('bar', async t => {30    const bar = Promise.resolve('bar');31    t.is(await bar, 'bar');32});33var test = require('ava');34test('foo', t => {35    t.pass();36});37test('bar', async t => {38    const bar = Promise.resolve('bar');39    t.is(await bar, 'bar');40});41var test = require('ava');42test('foo', t => {43    t.pass();44});45test('bar', async t => {46    const bar = Promise.resolve('bar');47    t.is(await bar, 'bar');48});49var test = require('ava');50test('foo', t => {51    t.pass();52});53test('bar', async t => {Using AI Code Generation
1test('test 1', t => {2  t.pass();3});4test('test 2', t => {5  t.fail();6});7test('test 3', t => {8  t.true(true);9});10test('test 4', t => {11  t.false(false);12});13test('test 5', t => {14  t.is(1, 1);15});16test('test 6', t => {17  t.not(1, 2);18});19test('test 7', t => {20  t.deepEqual({a:1}, {a:1});21});22test('test 8', t => {23  t.notDeepEqual({a:1}, {a:2});24});25test('test 9', t => {26  t.throws(() => {27    throw new Error('error');28  });29});30test('test 10', t => {31  t.notThrows(() => {32    throw new Error('error');33  });34});35test('test 11', t => {36  t.regex('foo', /foo/);37});38test('test 12', t => {39  t.notRegex('foo', /bar/);40});41test('test 13', t => {42  t.ifError(false);43});44test('test 14', t => {45  t.snapshot('foo');46});47test('test 15', t => {48  t.plan(2);49  t.pass();50  t.pass();51});52test('test 16', t => {53  t.log('foo');54});55test('test 17', t => {56  t.debug('foo');57});58test('test 18', t => {59  t.timeout(100Using AI Code Generation
1const test = require('ava')2test('my passing test', t => {3  t.pass()4})5const test = require('ava')6test('my passing test', t => {7  t.pass()8})9const test = require('ava')10test('my passing test', t => {11  t.pass()12})13const test = require('ava')14test('my passing test', t => {15  t.pass()16})17const test = require('ava')18test('my passing test', t => {19  t.pass()20})21const test = require('ava')22test('my passing test', t => {23  t.pass()24})25const test = require('ava')26test('my passing test', t => {27  t.pass()28})29const test = require('ava')30test('my passing test', t => {31  t.pass()32})33const test = require('ava')34test('my passing test', t => {35  t.pass()36})37const test = require('ava')38test('my passing test', t => {39  t.pass()40})41const test = require('ava')42test('my passing test', t => {43  t.pass()44})45const test = require('ava')46test('my passing test', t => {47  t.pass()48})49const test = require('ava')50test('my passing test', t => {Using AI Code Generation
1import test from 'ava';2import { get } from 'axios';3test('GET /', async (t) => {4  t.pass();5});6import test from 'ava';7import { get } from 'axios';8test('GET /', async (t) => {9  t.pass();10});11import test from 'ava';12import { get } from 'axios';13test('GET /', async (t) => {14  t.pass();15});16test('GET /hello', async (t) => {17  t.is(data, 'Hello World!');18});19import test from 'ava';20import { get } from 'axios';21test('GET /', async (t) => {22  t.pass();23});24test('GET /hello', async (t) => {25  t.is(data, 'Hello World!');26});27test('GET /hello?name=John', async (t) => {28  t.is(data, 'Hello John!');29});30import test from 'ava';31import { getLearn 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!!
