@mikezimm/fps-library-v2
Version:
Library of reusable typescript/javascript functions, interfaces and constants
79 lines (77 loc) • 3.44 kB
JavaScript
/**
* CodeAnalizerComment: Updated 1 imports on 2024-09-22 14:49:52
* Update:: import { IAnySourceItem } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IAnyContent;'
*/
/**
* CodeAnalizerComment: Updated 2 imports on 2024-09-21 23:07:24
* Update:: import { check4This } to '@mikezimm/fps-core-v7/lib/logic/Links/CheckSearch;'
* Update:: import { IAnySourceItem } to '@mikezimm/fps-core-v7/lib/components/molecules/AnyContent/IAnyContent;'
*/
/**
* Imported from HubCon 2024-07-29 as is.
*/
import { check4This, Check4 } from "@mikezimm/fps-core-v7/lib/logic/Links/CheckSearch";
// import { check4This } from "../../fpsReferences";
import { EasySearchCorp } from "./EasySearchCorp/EasySearchCorp";
/**
* applyRegExpXSearchObject is built to take
* @param items - array of IAnySourceItem
* @param keys - array of item.props you want to search for like ['Title', 'Description'] etc...
* @param Uncategorized
* @param searchKeyX - like 'topSearch' 'leftSearch' 'rightSearch'
* @param EasyRegexSearch
* @returns
*/
export function applyRegExpXSearchObject(items, keys, Uncategorized, searchKeyX, EasyRegexSearch = EasySearchCorp) {
Object.keys(EasyRegexSearch).map(key => {
items = addARegExXSearchArray(items, keys, searchKeyX, EasyRegexSearch[key], key);
});
if (Uncategorized)
items.map(item => { if (item.FPSItem.Search[searchKeyX].length === 0)
item.FPSItem.Search[searchKeyX].push(Uncategorized); });
return items;
}
/**
* addARegExTopSearchArray is built to be called by applyRegExpXSearchObject ^^^^^^^^^
* addARegExTopSearchArray does the work of adding TopSearch info based on a single array of reg exp.
* it adds a specific label to the Search and topSearch array if any of the regex in the array are found.
* @param items - array of IAnySourceItem
* @param keys - array of item.props you want to search for like ['Title', 'Description'] etc...
* @param ARegex - [key: string]: RegExp [];
* @param label - label value to apply if Regex match is found... typically the key of ICustomRegexSearch
* @returns
*/
export function addARegExXSearchArray(items, keys, searchKeyX, ARegex, label) {
items.forEach(item => {
if (!item.FPSItem.Search[searchKeyX])
item.FPSItem.Search[searchKeyX] = [];
if (isAnyRegexFoundOnKeys(item, ARegex, keys) === true) {
item.FPSItem.Search[searchKeyX].push(label);
item.FPSItem.Search.searchText += ` || ${label}`;
item.FPSItem.Search.searchTextLC += ` || ${label.toLocaleLowerCase()}`;
}
else {
if (label === 'Customer' && check4This(Check4.showAllConsole_Eq_true, true) === true)
console.log('addHubMeta test fail', ARegex, keys, item.Title, item);
}
});
return items;
}
/**
*
* @param item - array of IAnySourceItem
* @param ARegex - [key: string]: RegExp [];
* @param keys - array of item.props you want to search for like ['Title', 'Description'] etc...
* @returns
*/
export function isAnyRegexFoundOnKeys(item, ARegex, keys) {
let found = false;
ARegex.map(filter => {
keys.map(key => {
if (typeof item[key] === 'string' && item[key].match(filter))
found = true;
});
});
return found;
}
//# sourceMappingURL=applyRegExpXSearchObject.js.map