UNPKG

@mikezimm/npmfunctions

Version:
142 lines (139 loc) 9.45 kB
/*** * .d8b. d8888b. d8888b. .d8b. db db .d8888. * d8' `8b 88 `8D 88 `8D d8' `8b `8b d8' 88' YP * 88ooo88 88oobY' 88oobY' 88ooo88 `8bd8' `8bo. * 88~~~88 88`8b 88`8b 88~~~88 88 `Y8b. * 88 88 88 `88. 88 `88. 88 88 88 db 8D * YP YP 88 YD 88 YD YP YP YP `8888Y' * * //Checks import { doesObjectExistInArrayInt, doesObjectExistInArray, compareArrays, getMaxPropOfKeyInObjectArray, getNextElementInArray getKeySummary, getKeyChanges } from '@mikezimm/npmfunctions/dist/Services/Arrays/checks'; */ /*** * d888888b d8b db d8888b. d88888b db db .d88b. d88888b .d8b. d8b db db db .o88b. .d8b. .d8888. d88888b * `88' 888o 88 88 `8D 88' `8b d8' .8P Y8. 88' d8' `8b 888o 88 `8b d8' d8P Y8 d8' `8b 88' YP 88' * 88 88V8o 88 88 88 88ooooo `8bd8' 88 88 88ooo 88ooo88 88V8o 88 `8bd8' 8P 88ooo88 `8bo. 88ooooo * 88 88 V8o88 88 88 88~~~~~ .dPYb. 88 88 88~~~ 88~~~88 88 V8o88 88 8b 88~~~88 `Y8b. 88~~~~~ * .88. 88 V888 88 .8D 88. .8P Y8. `8b d8' 88 88 88 88 V888 88 Y8b d8 88 88 db 8D 88. * Y888888P VP V8P Y8888D' Y88888P YP YP `Y88P' YP YP YP VP V8P YP `Y88P' YP YP `8888Y' Y88888P * * */ /** * Based on: https://bobbyhadz.com/blog/javascript-array-contains-string-case-insensitive * Any non-string checks will be considered 'not a match' * @param checkMe * @param inArray */ export declare function indexOfAnyCase(checkMe: string, inArray: string[], consoleLog: boolean, alertMe: boolean): number; /*** * d8888b. .d88b. d88888b .d8888. .d88b. d8888b. d88b d88888b .o88b. d888888b d88888b db db d888888b .d8888. d888888b d888888b d8b db .d8b. d8888b. d8888b. .d8b. db db * 88 `8D .8P Y8. 88' 88' YP .8P Y8. 88 `8D `8P' 88' d8P Y8 `~~88~~' 88' `8b d8' `88' 88' YP `~~88~~' `88' 888o 88 d8' `8b 88 `8D 88 `8D d8' `8b `8b d8' * 88 88 88 88 88ooooo `8bo. 88 88 88oooY' 88 88ooooo 8P 88 88ooooo `8bd8' 88 `8bo. 88 88 88V8o 88 88ooo88 88oobY' 88oobY' 88ooo88 `8bd8' * 88 88 88 88 88~~~~~ `Y8b. 88 88 88~~~b. 88 88~~~~~ 8b 88 88~~~~~ .dPYb. 88 `Y8b. 88 88 88 V8o88 88~~~88 88`8b 88`8b 88~~~88 88 * 88 .8D `8b d8' 88. db 8D `8b d8' 88 8D db. 88 88. Y8b d8 88 88. .8P Y8. .88. db 8D 88 .88. 88 V888 88 88 88 `88. 88 `88. 88 88 88 * Y8888D' `Y88P' Y88888P `8888Y' `Y88P' Y8888P' Y8888P Y88888P `Y88P' YP Y88888P YP YP Y888888P `8888Y' YP Y888888P VP V8P YP YP 88 YD 88 YD YP YP YP * * */ /** * This function checks to see if an element of an array (object) contains a specific property/value pair. * * example call: if ( doesObjectExistInArray(currentFields, 'StaticName', checkField ) ) { * This takes an array of field objects (currentFields), and looks to see if any of the objects has a key of StaticName which has a value of checkField variable. * * @param sourceArray * @param objectProperty * @param propValue */ export declare function doesObjectExistInArrayInt(sourceArray: any[], objectProperty: string, propValue: any, exact?: boolean): number; export declare function doesObjectExistInArray(sourceArray: any[], objectProperty: string, propValue: any, exact?: boolean): string | false; export interface ICompareResult { checkForTheseItems: any[]; inThisArray: any[]; found: any[]; notFound: any[]; result: any[]; message: string; } /*** * .o88b. .d88b. .88b d88. d8888b. .d8b. d8888b. d88888b .d8b. d8888b. d8888b. .d8b. db db .d8888. * d8P Y8 .8P Y8. 88'YbdP`88 88 `8D d8' `8b 88 `8D 88' d8' `8b 88 `8D 88 `8D d8' `8b `8b d8' 88' YP * 8P 88 88 88 88 88 88oodD' 88ooo88 88oobY' 88ooooo 88ooo88 88oobY' 88oobY' 88ooo88 `8bd8' `8bo. * 8b 88 88 88 88 88 88~~~ 88~~~88 88`8b 88~~~~~ 88~~~88 88`8b 88`8b 88~~~88 88 `Y8b. * Y8b d8 `8b d8' 88 88 88 88 88 88 88 `88. 88. 88 88 88 `88. 88 `88. 88 88 88 db 8D * `Y88P' `Y88P' YP YP YP 88 YP YP 88 YD Y88888P YP YP 88 YD 88 YD YP YP YP `8888Y' * * * The original goal of this function, would be to remove objects from one array if it were in another array. * As an example, I have an array of items I want to add to a list (addItemsArray) * Then I run a process which creates another 'result' array of what things were actually added - minus any errors * The function will remove the items in the 'result' array from the 'addItemsArray. * Only the items that were not added (ie the ones that errored out) will be left... or maybe it would add a key with the result. * * * @param checkForTheseItems - this is the array of items you want to check for in the sourceArray ('inThisArray') * @param inThisArray - this is the array where you are looking for items in * @param method - this tells what to do... either flage items in 'inThisArray' with found/not found, or remove the found ones * @param keyToCheck - checkForTheseItems must have a key which has this syntax: checkValue: "Title===Training" * keyToCheck would === 'checkValue' and the value for that key must have the syntax: PropertyKey===ValueOfProperty; * In the example above, it will split Title===Training into ['Title','Training'] * Then look for all items in 'inThisArray' which have the value 'Training' in the key 'Title', and apply the method you want to apply. */ export declare function compareArrays(checkForTheseItems: any[], inThisArray: any[], method: 'AddTag' | 'ReturnNOTFound' | 'ReturnFound', keyToCheck: string, checkDelimiter: string, messsages: 'Console' | 'Alert' | 'Both' | 'None'): ICompareResult; /*** * d888b d88888b d888888b db dD d88888b db db .d8888. db db .88b d88. .88b d88. .d8b. d8888b. db db * 88' Y8b 88' `~~88~~' 88 ,8P' 88' `8b d8' 88' YP 88 88 88'YbdP`88 88'YbdP`88 d8' `8b 88 `8D `8b d8' * 88 88ooooo 88 88,8P 88ooooo `8bd8' `8bo. 88 88 88 88 88 88 88 88 88ooo88 88oobY' `8bd8' * 88 ooo 88~~~~~ 88 88`8b 88~~~~~ 88 `Y8b. 88 88 88 88 88 88 88 88 88~~~88 88`8b 88 * 88. ~8~ 88. 88 88 `88. 88. 88 db 8D 88b d88 88 88 88 88 88 88 88 88 88 `88. 88 * Y888P Y88888P YP YP YD Y88888P YP `8888Y' ~Y8888P' YP YP YP YP YP YP YP YP 88 YD YP * * * * Copied from FoamControl.tsx * @param thisDataObjec * @param compareTypes Tested values = ['string','number','boolean']; * @param ignoreKeys Tested values = ['element']; * @returns */ export declare function getKeySummary(baselineObject: any, compareTypes: string[], ignoreKeys: string[], parseMe: boolean): any; export declare const BaseFieldKeys: string[]; export declare const BaseViewKeys: string[]; export declare const BaseTypeKeys: string[]; export declare const DoesNotExistLabel = "- >> Does NOT Exist << -"; export declare const KeyChangeDelimiter = " >>> "; /*** * d888b d88888b d888888b db dD d88888b db db .o88b. db db .d8b. d8b db d888b d88888b .d8888. * 88' Y8b 88' `~~88~~' 88 ,8P' 88' `8b d8' d8P Y8 88 88 d8' `8b 888o 88 88' Y8b 88' 88' YP * 88 88ooooo 88 88,8P 88ooooo `8bd8' 8P 88ooo88 88ooo88 88V8o 88 88 88ooooo `8bo. * 88 ooo 88~~~~~ 88 88`8b 88~~~~~ 88 8b 88~~~88 88~~~88 88 V8o88 88 ooo 88~~~~~ `Y8b. * 88. ~8~ 88. 88 88 `88. 88. 88 Y8b d8 88 88 88 88 88 V888 88. ~8~ 88. db 8D * Y888P Y88888P YP YP YD Y88888P YP `Y88P' YP YP YP YP VP V8P Y888P Y88888P `8888Y' * * */ /** * getKeyChanges function compares two objects which are similar... and returns the differences. * An example would be versions of a list item. * the keyChanges would compare both arrays to each other and only return the keys which have values that are not equal * This is more for converting changes into single label per key notation that is more easily readable * * baselineObject = { a: 1, b: 2} compareObject = { a: 1, b: 3} => result would be newObject = { b: '2 >>> 3' } * * * POSSIBLE BREAKING CHANGE VVVVV * * 2021-05-18: REVISED TO START USING 2nd Paramter (now called specificKeys ) * * TO AVOID ISSUES (this paramter was received but not used in the past) - pass in null or [] * * @param baselineObject * @param specificKeys ( was keySummary ) - Pass array of specific keys to check, empty or null to use keys in baselineObject * @param compareObject * @param parseMe */ export declare function getKeyChanges(baselineObject: any, specificKeys: string[], compareObject: any, parseMe: boolean): any;