Last active
June 26, 2021 04:02
-
-
Save namikazebadri/360308c7b9ff403c9468ba938fca65a0 to your computer and use it in GitHub Desktop.
This script originally an attempt to test if path is active or not in react app, the case is about similar pat like /finance/invoice and /finance/invoice_landlord.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = '/finance/invoice'; | |
| const pathCorrects = [ | |
| path, | |
| path + '/', | |
| path + '?', | |
| path + '#name', | |
| path + '#name?', | |
| path + '#name?first_name=unis&last_name=badri', | |
| path + '/#name?first_name=unis&last_name=badri', | |
| path + '?first_name=unis&last_name=badri', | |
| path + '/?first_name=unis&last_name=badri', | |
| ] | |
| const pathWrongs = [ | |
| path + '_landlord', | |
| path + '_landlord/', | |
| path + '_landlord?', | |
| path + '_landlord#name', | |
| path + '_landlord#name?', | |
| path + '_landlord#name?first_name=unis&last_name=badri', | |
| path + '_landlord/#name?first_name=unis&last_name=badri', | |
| path + '_landlord?first_name=unis&last_name=badri', | |
| path + '_landlord/?first_name=unis&last_name=badri', | |
| ] | |
| const regexExpression = '(?!\\_)(\\?|\\/|\\#|)(.*?)$'; | |
| console.log('Correct conditions: ') | |
| for(let i = 0; i < pathCorrects.length; i++) { | |
| const regex = new RegExp(path + regexExpression, 'g'); | |
| console.log(regex.test(pathCorrects[i])); | |
| } | |
| console.log('Wrong conditions: ') | |
| for(let i = 0; i < pathWrongs.length; i++) { | |
| const regex = new RegExp(path + regexExpression, 'g'); | |
| console.log(regex.test(pathWrongs[i])); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment