frankcollins3 / fill_container

codecamp team project updated with new icon screen menu + puppeteer icon search, GraphQL, redux, relational psql !mongo, and accuweatherAPI
1 stars 0 forks source link

retrieve value && string properties like .length from .match() [5:15pm] #184

Closed frankcollins3 closed 1 year ago

frankcollins3 commented 1 year ago

let splitEmail:any = value.match(splitAtDot) console.log(emailStr: ${splitEmail} ${typeof splitEmail} ${splitEmail.length})

heres the code:

    const inputOnChange = (event:any) => {
        let value:string = event.target.value
        if (inputType === 'username') {            
            inputHandler(event, SET_USERNAME_INPUT)
        }
        if (inputType === 'email') {
            const splitHelper = event.target.value.split('@.')
            const splitAtDot = /@([^.]*)\./
            let splitEmail:any = value.match(splitAtDot)
            console.log(`emailStr: ${splitEmail} ${typeof splitEmail}`)

    //         let emailString:string = splitEmail?.toString().trim()
    //         console.log('emailString')
    //         console.log(`emailStr: ${emailString} ${typeof emailString} ${emailString.length}`)
    // if (emailString?.includes('g') && splitEmail.includes('m') && splitEmail.includes('a') && splitEmail.includes('i') && splitEmail.includes('l') && emailString !== 'gmail') {
    //             console.log("the letters includes gmail but there is a typo")
    //         }
            console.log('splitEmail')
            console.log(splitEmail)
            inputHandler(event, SET_EMAIL_INPUT)

        }
        if (inputType === 'age') {
            inputHandler(event, SET_AGE_INPUT)
        }
        if (inputType === 'password') {
            let hasNums4 = RegexObject.hasNums.test(parseInt(PASSWORD_INPUT))        
            const statePromise = new Promise( (resolve, reject) => {
                resolve([ SET_PASSWORD_INPUT({payload: value}) ])
            })                 
            statePromise
            .then( () => {return})                                  
            .catch( (err) => console.log(err))
        }
    }

context from which expression is run. Already verified to work with hasNums regex for password constraints checker const regexDefaults: RegexDefaults = { RstringAfterPeriod: /^..(.)$/, RreturnLettersAthruZ: /[a-z]/g, RreturnNumbers: /[0-9]/g, RhasCaps: /[A-Z]/g, RhasNums: /[A-Z]/g, RnoWhiteSpace: /\s/g, MsplitAtDot: /@([^.])./,
McharAfterComma: /,(.
)/ };

[5:17pm]

frankcollins3 commented 1 year ago

typeof === 'object' emailStr: @gmail.,gmail object

somehow the truthy block of this ternary operator runs splitEmail !== null || splitEmail !== undefined ? console.log(splitEmail[0]) : console.log('hey null!')

from browsertools:
emailStr: null object

  // value said to be null which I knew since it's been null null null until [@ . ] characters meet match

splitEmail !== null || splitEmail !== undefined && splitEmail[0] ? console.log(splitEmail[0]) : console.log('hey null!')

kind of confused why doesn't work either it's asking if it exists and provides a case for what to do if it doesn't:

.log('hey null')

[5:24pm]

frankcollins3 commented 1 year ago

browser tools to show it's null. the above console.log() is not commented out to avoid compilation

splitEmail
SignupInput.tsx:77 null
SignupInput.tsx:78 emailStr: null | | | | | object
SignupInput.tsx:87 splitEmail
SignupInput.tsx:88 null
SignupInput.tsx:76 splitEmail
SignupInput.tsx:77 null
SignupInput.tsx:78 emailStr: null | | | | | object
SignupInput.tsx:87 splitEmail
SignupInput.tsx:88 null
SignupInput.tsx:76 splitEmail
SignupInput.tsx:77 null
SignupInput.tsx:78 emailStr: null | | | | | object
SignupInput.tsx:87 splitEmail
SignupInput.tsx:88 null
SignupInput.tsx:76 splitEmail
SignupInput.tsx:77 null
SignupInput.tsx:78 emailStr: null | | | | | object
SignupInput.tsx:87 splitEmail
SignupInput.tsx:88 null
SignupInput.tsx:76 splitEmail
SignupInput.tsx:77 null
SignupInput.tsx:78 emailStr: null | | | | | object
SignupInput.tsx:87 splitEmail
SignupInput.tsx:88 null
SignupInput.tsx:76 splitEmail
SignupInput.tsx:77 null
SignupInput.tsx:78 emailStr: null | | | | | object
SignupInput.tsx:87 splitEmail
SignupInput.tsx:88 null
SignupInput.tsx:76 splitEmail
SignupInput.tsx:77 null
SignupInput.tsx:78 emailStr: null | | | | | object
SignupInput.tsx:87 splitEmail
SignupInput.tsx:88 null

[5:25pm]

frankcollins3 commented 1 year ago

woooooooow chatGPT gave me this code:

if (splitEmail !== null) {
                console.log('aaaye')
                const matchedValue = splitEmail[0];
                console.log(matchedValue); // Output: the matched email string
              }

// splitEmail !== null || splitEmail !== undefined && splitEmail[0] ? console.log(splitEmail[0]) : console.log('hey null!') the ternary operator does the same exact thing ?

[5:28pm]

this seems to show the ratio of coding with chat is just as or nearly as important as coding without it 👍 10 min issue could've kept: [chasing_tail, spinning_tires]

frankcollins3 commented 1 year ago

match is included the characters I thought replaced. Have to escape them. this issue is solved [5:34pm]