add function to test valid URL
This commit is contained in:
		
							parent
							
								
									4f07cb5b5d
								
							
						
					
					
						commit
						16e57f45fc
					
				
					 1 changed files with 26 additions and 7 deletions
				
			
		|  | @ -3,14 +3,33 @@ URL tools | |||
| */ | ||||
| 
 | ||||
| class URLs { | ||||
|      /* | ||||
|      Remove the protocol from the URL. | ||||
| 	/* | ||||
| 	Remove the protocol from the URL. | ||||
| 
 | ||||
|      @param {string} URL the URL to clean | ||||
|      */ | ||||
|      static clean(URL) { | ||||
|           return((URL.trim().replace(/(^\w+:|^)\/\//, ``).split(`?`))[0]); | ||||
|      } | ||||
| 	@param {string} URL the URL to clean | ||||
| 	*/ | ||||
| 	static clean(URL) { | ||||
| 		return((URL.trim().replace(/(^\w+:|^)\/\//, ``).split(`?`))[0]); | ||||
| 	} | ||||
| 
 | ||||
| 	/* | ||||
| 	Check if the URL is valid through checking its patterns.  | ||||
| 	 | ||||
| 	@param {string} location the URL to check | ||||
| 	@return {boolean} the state | ||||
| 	*/ | ||||
| 	static test(location) { | ||||
| 		let STATE = false; | ||||
| 		 | ||||
| 		// Convert to URL object.
 | ||||
| 		try { | ||||
| 			STATE = !!(new URL(location)); | ||||
| 		} catch(err) { | ||||
| 			STATE = false; | ||||
| 		} | ||||
| 
 | ||||
| 		return STATE; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| export {URLs}; | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue