properly test for matching website, including via RegEx
This commit is contained in:
		
							parent
							
								
									a444ff2d34
								
							
						
					
					
						commit
						5e0d4bb8e4
					
				
					 2 changed files with 20 additions and 6 deletions
				
			
		|  | @ -31,7 +31,7 @@ export default class filters { | ||||||
| 			return filter; | 			return filter; | ||||||
| 		})(); | 		})(); | ||||||
| 
 | 
 | ||||||
| 		if ((SELECTED && SELECTED != null && (typeof SELECTED).includes(`obj`)) ? Object.keys(SELECTED) : false) { | 		if ((SELECTED && SELECTED != null && (typeof SELECTED).includes(`obj`)) ? (Object.keys(SELECTED)).length > 0 : false) { | ||||||
| 			this.one = (Object.entries(SELECTED))[0][1]; | 			this.one = (Object.entries(SELECTED))[0][1]; | ||||||
| 			return (this.one); | 			return (this.one); | ||||||
| 		}; | 		}; | ||||||
|  |  | ||||||
|  | @ -151,17 +151,31 @@ export async function search(SOURCE, TERM, ADDITIONAL_PLACES, STRICT = 0, OPTION | ||||||
| 				for (let DICTIONARY_INDEX = 0; DICTIONARY_INDEX < (Object.keys(DATA)).length; DICTIONARY_INDEX++) { | 				for (let DICTIONARY_INDEX = 0; DICTIONARY_INDEX < (Object.keys(DATA)).length; DICTIONARY_INDEX++) { | ||||||
| 					VALUE[`parent`] = DATA[(Object.keys(DATA))[DICTIONARY_INDEX]]; | 					VALUE[`parent`] = DATA[(Object.keys(DATA))[DICTIONARY_INDEX]]; | ||||||
| 					 | 					 | ||||||
| 					if (((typeof VALUE[`parent`]).includes(`obj`) && !Array.isArray(VALUE[`parent`]) && VALUE[`parent`] != null) ? (Object.keys(VALUE[`parent`])).length > 0 : false ) { | 					/* Test for a valid RegEx.  | ||||||
|  | 					 | ||||||
|  | 					@param {string} item the item to test | ||||||
|  | 					*/ | ||||||
|  | 					function isRegEx(item) { | ||||||
|  | 						let RESULT = {}; | ||||||
|  | 						RESULT[`state`] = false; | ||||||
|  | 						try { | ||||||
|  | 							RESULT[`expression`] = new RegExp(item); | ||||||
|  | 							RESULT[`state`] = true; | ||||||
|  | 						} catch(err) {}; | ||||||
|  | 
 | ||||||
|  | 						return (RESULT[`state`]); | ||||||
|  | 					}; | ||||||
|  | 
 | ||||||
|  | 					if (((typeof VALUE[`parent`]).includes(`obj`) && !Array.isArray(VALUE[`parent`]) && VALUE[`parent`] != null) ? (Object.keys(VALUE[`parent`])).length > 0 : false) { | ||||||
| 						VALUE[`current`] = VALUE[`parent`][ADDITIONAL_PLACES]; | 						VALUE[`current`] = VALUE[`parent`][ADDITIONAL_PLACES]; | ||||||
| 					} | 					} | ||||||
| 
 | 
 | ||||||
| 					if (VALUE[`current`]) { | 					if (VALUE[`current`] ? ((STRICT >= 1) ? VALUE[`current`] == TERM : (((STRICT < 0.5) ? (VALUE[`current`].includes(TERM)) : false) || TERM.includes(VALUE[`current`]) || (isRegEx(VALUE[`current`]) ? (new RegExp(VALUE[`current`])).test(TERM) : false))) : false) { | ||||||
| 						// Add the data. 
 | 						// Add the data. 
 | ||||||
| 						RESULTS[(Object.keys(DATA))[DICTIONARY_INDEX]] = (Object.entries(DATA))[DICTIONARY_INDEX][1]; | 						RESULTS[(Object.keys(DATA))[DICTIONARY_INDEX]] = (Object.entries(DATA))[DICTIONARY_INDEX][1]; | ||||||
| 					} | 					}; | ||||||
| 				}; | 				}; | ||||||
| 			} else { | 			} else { | ||||||
| 				console.log(DATA); |  | ||||||
| 				for (let ELEMENT_INDEX = 0; ELEMENT_INDEX < DATA.length; ELEMENT_INDEX++) { | 				for (let ELEMENT_INDEX = 0; ELEMENT_INDEX < DATA.length; ELEMENT_INDEX++) { | ||||||
| 					if ( | 					if ( | ||||||
| 						((STRICT || (typeof DATA[ELEMENT_INDEX]).includes(`num`)) && DATA[ELEMENT_INDEX] == TERM) || | 						((STRICT || (typeof DATA[ELEMENT_INDEX]).includes(`num`)) && DATA[ELEMENT_INDEX] == TERM) || | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue