import { ArrayOrSingle, StringOrStringArray } from '../models/types.mjs'; /** * Adds obj to the list of objects, creating the list if it doesn't exist. * If obj is an array, loops through the array. * @param listObjects An array of objects. * @param obj Array of items to add to listObjects. * @returns listObjects. If null, was passed, it is a new array. */ export declare function addObjectToList(listObjects: T[], obj: T[]): T[]; /** * Deep clones an object using the JSON.parse(JSON.stringify(obj)) method. * Suppresses any exceptions, but still writes to the console.log. * @param obj The object to copy. * @param fname The function name of the caller. Not required. * @returns A JSON stringify and parsed copy of the obj. */ export declare function deepCloneJson(obj: object, fname?: string): T | undefined; /** * Method to wrap deep object comparison. The changes are mapped and returned. * Generally used for checking in real-time form data changes. * i.e., isDirty = deepDiffMapper().anyChanges(formOriginalValues, formCurrentValues); * @returns An object that wraps varying levels of comparison information. */ export declare function deepDiffMapper(): { VALUE_CREATED: string; VALUE_UPDATED: string; VALUE_DELETED: string; VALUE_UNCHANGED: string; /** * Checks if there are any changes between two objects. * @param obj1 First object to compare. * @param obj2 Second object to compare. * @returns True if any changes between the objects. */ anyChanges(obj1: unknown, obj2: unknown): boolean; /** * Checks if there are any changes between two objects and returns the changes. * @param obj1 First object to compare. * @param obj2 Second object to compare. * @returns The changed items between the two objects. */ getChanges(obj1: unknown, obj2: unknown): boolean | [string, any] | undefined; /** * Looks for an object with key value pairs and returns if it found changes. * @param param0 A key value pair to look for changes. Deep inspection * @returns True if an object with type and data is found with changes present. */ findTypeData([, value]: [string, unknown]): boolean; /** * Maps all changes between two objects. * @param obj1 The first object to compare. * @param obj2 The second object to compare. * @returns A {type: string, value: object} object with all changes. */ map(obj1: any, obj2: any): object; /** * Returns a comparison string defining the type of change, or unchanged. * @param value1 The first value to compare. * @param value2 The second value to compare. * @returns A this.VALUE_xxx string describing the change or unchanged. */ compareValues(value1: any, value2: any): string; isFunction(x: unknown): boolean; isArray(x: unknown): boolean; isDate(x: unknown): x is Date; isObject(x: unknown): x is object; isValue(x: unknown): boolean; }; /** * Looks for a ret.body object to return. * Throws an Error if the body is not found or not an object. * @param ret The object to get the ret.body object. * @returns The existing ret.body object of the ret object.. */ export declare function getBody(ret: unknown): any; /** * Gets a comma separated list of unique items. * @param stringOrArray The {@link StringOrStringArray} to flatten then separate by commas. * @returns The flattened, comma-separated string. */ export declare function getCommaSeparatedList(stringOrArray: StringOrStringArray): string; /** * Gets a comma separated list of unique items in uppercase. * @param stringOrArray The {@link StringOrStringArray} to uppercase and separate by commas. * @returns The flattened, comma-separated string in uppercase. */ export declare function getCommaUpperList(stringOrArray: StringOrStringArray): string; /** * Returns a number from a string. A number is allowed too in case you don't know if the value is a number already. * If a null or undefined value is passed in, 0 is returned. * @param stringOrNumber The string or number to return as a number. * @returns The number representation of the stringOrNumber. If it is a number, just returns the number. */ export declare function getAsNumber(stringOrNumber: string | number | null | undefined): number; /** * Returns a number from a string. A number is allowed too in case you don't know if the value is a number already. * If a null or undefined is passed in, then undefined is returned. * @param stringOrNumber The string or number to return as a number. Or undefined if a null or undefined is passed in. * @param maxDecimalPlaces The maximum number of decimal places to show. * @param minDecimalPlaces The minimum number of required decimal places to show. * @returns The number representation of the stringOrNumber. If it is a number, just returns the number. */ export declare function getAsNumberOrUndefined(stringOrNumber: string | number | null | undefined, maxDecimalPlaces?: number, minDecimalPlaces?: number): number | undefined; /** * When getting form data from a UI, the textbox data is always a string. * Use this method to convert any string, number or boolean to its boolean value; * @param b Any object to test if it can be converted to a boolean. */ export declare function getBoolean(b: unknown): boolean; /** * Returns the mantissa as a whole number. * @param num The decimal number to get the mantissa for. * @returns The whole number value of the mantissa. */ export declare function getMantissa(num: number): number; /** * Gets a formatted number based on a specified number of decimal places. * @param num A number or string representing a number. * @param maxDecimalPlaces The maximum number of decimal places to show. * @param minDecimalPlaces The minimum number of required decimal places to show. * @returns A number with the given decimal places. Or 0 if num was null or undefined. */ export declare function getNumberFormatted(num: any | null | undefined, maxDecimalPlaces?: number, minDecimalPlaces?: number): number; /** * Gets a formatted number based on a specified number of decimal places. * @param num A number or string representing a number. * @param maxDecimalPlaces The maximum number of decimal places to show. * @param minDecimalPlaces The minimum number of required decimal places to show. * @returns A string of the passed in num with the given decimal places. */ export declare function getNumberString(num: any, maxDecimalPlaces?: number, minDecimalPlaces?: number): string; /** * Gets an object from an array at the given index. * Or if it is not an array, just returns the object. * Protects from empty objects and indexes that are out of bounds. * @param arr An object array to get the index item of. * @param index The index of the object array to return. Use negative numbers to start from the end of the array. -1 returns the last item. * @returns The given object at arr[index], or undefined if it does not exist. */ export declare function getObject(arr: T | T[], index?: number): T | undefined; export declare function getObjectWithException(arr: ArrayOrSingle, index?: number): NonNullable; /** * Gets from the object the value from the key that matches find string. * @param obj The object to search for the key. * @param keyToFind The property to look for in the object. * @returns The value from the obj[keyToFind]. undefined if not found. */ export declare function getObjectValue(obj: any, keyToFind: string): any; /** * Gets the percentage change from two numbers. * Can be negative if there is a drop from the previous to the current number. * @param prev The previous number. * @param cur The new current number. * @returns The percentage number from -100 to 100. */ export declare function getPercentChange(prev: number, cur: number): number; /** * Gets the percentage change from two numbers as a string with the % sign appended if desired. * Can be negative if there is a drop from the previous to the current number. * @param prev The previous number. * @param cur The new current number. * @param showPercent Set to true if you want the % sign appended. * @param decimalPlaces The number of decimal places to show. Defaults to 2. * @returns The percentage number from -100 to 100. */ export declare function getPercentChangeString(prev: number, cur: number, showPercent?: boolean, decimalPlaces?: number): string; /** * Checks any object, string or array if it has any data. * The minlength is for requiring more items to be in the object, string or array. * You can pass in a function that must return an object, string or array to be tested as well. * @param o Any object, string or array. If it is a function, the function will be called to get the object, string or array before testing. * @param minlength The required minimum length to consider to have data. If not supplied, defaults to 1. * @returns True if the object meets the minimum length requirements. */ export declare function hasData(o: any | null | undefined, minlength?: number): boolean; /** * Checks an object if it is an array. If so, then tests if there is an optional minimum number of items. * If minLengthOrIncludes is not a number, checks that the array includes the item. * @param arr Any object to test if it is an array. * @param minLengthOrIncludes If a number, specifies the minimum number of items to be in the array. If not a number, the array must include the item. * @returns True if arr is an array and meets any minimum requirements. */ export declare function isArray(arr: T | T[], minLengthOrIncludes?: T | number): arr is Array; /** * Tests an object to determine if it is a type boolean. * @param obj Any object to test if it is a boolean value. * @returns True if the object is a boolean. */ export declare function isBoolean(obj: unknown): obj is boolean; export declare function isEmptyObject(obj: unknown): boolean; /** * Checks a variable to see if it is empty. * If it is a string, then checks for "". * @param s A variable to test if it is a string and is empty. * @param allowFunction True if s is a function and you want to call the function to get s. * @returns True if the object s is an empty string. */ export declare function isEmptyString(s: any, allowFunction?: boolean): boolean; /** * Tests an object to determine if it is a function. * @param obj Any object to test if it is a function. * @returns True if the object is a function. */ export declare function isFunction(obj: unknown): obj is Function; /** * Tests an object to determine if it is a number. * Additionally, will test if the number is greater than or equal to a minimum value and/or less than or equal to a maximum value. * @param obj Any object to test if it is a number. * @param minValue The minimum value the number must be. * @param maxValue The maximum value the number can be. * @returns True if the object is a number and if provided, >= to the minValue and/or <= to the maxValue. */ export declare function isNumber(obj: unknown, minValue?: number | null, maxValue?: number | null): obj is number; export declare function isNumeric(value?: string | number): boolean; /** * Tests if a variable is null or undefined. * @param obj Any variable to test if it is null or undefined. * @returns True if the object passed in is null or undefined. */ export declare function isNullOrUndefined(obj: unknown): obj is undefined | null; /** * Checks if the variable passed in is a JavaScript object that is not an array. * Optionally can test for a minimum number of member objects, or if a member of the object is a named by the minLengthOrContainsField parameter. * @param obj The object to test if it is indeed a JavaScript object. * @param minLengthOrContainsField The minimum number of items that must be in the object. Or if a string, the object must contain a member named the string provided. * @returns True if the obj variable is a JavaScript object, and meets an optional minimum length or contains a member with the given name. */ export declare function isObject(obj: unknown, minLengthOrContainsField?: number | string): obj is object; /** * Tests an object to determine if it is a string. * Additionally, will test if the string if it has a minimum length. * @param obj Any object to test if it is a string. * @param minlength The minimum length the string must be. * @returns True if the object is a string and meets an optional minimum length if provided. */ export declare function isString(obj: unknown, minlength?: number): obj is string; /** * Returns a new global unique identifier (GUID). * @returns A global unique identifier as a 16 character string. */ export declare function newGuid(): string; /** * Tests an object to see if it is empty. If so returns null, otherwise just returns the object. * @param obj The object to test if it is empty. * @returns Null if the object is empty, otherwise the object is returned. */ export declare function getNullObject(obj: T): T | null; /** * Tests if the passed in arr is in fact an array that is not undefined or null. * If it is, the ifNull value is used. If there is no ifNull passed in, an empty array is returned. * @param arr An array to test for not being null or undefined. If it is an object, it is wrapped in an array. * @param ifNull If the array is null or undefined, return this value. Defaults to []. * @returns A guaranteed array to be nonNull. Returns ifNull when the array does not have data. Or [] if ifNull is not declared. */ export declare function safeArray(arr?: T | T[], ifNull?: T[]): T[]; /** * Wraps JSON.stringify in a try/catch so that exceptions are not bubbled up. * @param json The JSON object to convert to a string. * @param fname The optional function name that is the source of the operation. Used for exception logging. * @returns A the JSON.stringify(ed) string or empty string if there was an exception. */ export declare function safeJsonToString(json: object, fname?: string, replacer?: (number | string)[], space?: string | number): string; /** * Tests if the passed in obj is in fact an object that is not undefined or null. * If it is, the ifNull value is used. If there is no ifNull passed in, an empty object with no members is returned. * @param obj An object to test for not being null or undefined. * @param ifNull If the object is null or undefined, return this value. Defaults to {}. * @returns A guaranteed object to be nonnull. Returns ifNull if the object does not have data. */ export declare function safeObject(obj?: object, ifNull?: object): object; /** * Tests if a string has data (is not undefined, null or empty string). * If the string is empty, the ifNull value is returned. * @param s A string to check for data. * @param ifNull If the string is null, return this value. Defaults to "". * @returns A guaranteed string to be nonnull. Returns ifNull if the string does not have data. */ export declare function safestr(s?: string, ifNull?: string): string; /** * Returns a guaranteed valid string to be lowercase. * @param s A string to set to lowercase. If null or undefined, empty string is returned. * @param trim Optionally trim the string also. * @returns A guaranteed string to be nonnull and lowercase. */ export declare function safestrLowercase(s?: string, trim?: boolean): string; /** * Wraps JSON.parse in a try/catch so that exceptions are not bubbled up. * @param strjson The string converted to be converted to a JSON object. * @param fname The optional function name that is the source of the operation. Used for exception logging. * @returns A the JSON.parsed object or undefined if there was an exception. */ export declare function safestrToJson(strjson?: string, fname?: string): T | undefined; /** * Returns a guaranteed valid string to be trimmed. * @param s A string to set to lowercase. If null or undefined, empty string is returned. * @returns A guaranteed string to be nonnull and trimmed. */ export declare function safestrTrim(s?: string): string; /** * Returns a guaranteed valid string to be uppercase. * @param s A string to set to uppercase. If null or undefined, empty string is returned. * @param trim Optionally trim the string also. * @returns A guaranteed string to be nonnull and uppercase. */ export declare function safestrUppercase(s?: string, trim?: boolean): string; /** * Returns an s if the number passed in should be pluralized. * @param isPlural A number that is used to determine if the plural suffix is added. * @param suffix The suffix to add if the number should be pluralized. * @returns The suffix string if the number is not 1. */ export declare const pluralSuffix: (num: number, suffix?: string) => string; /** * Returns an s if the number passed in should be pluralized. * @param num A number that is used to determine if the plural suffix is added. * @param suffix The suffix to add if the number should be pluralized. * @returns The suffix string if the number is not 1. */ export declare function pluralize(num: number, textIfSingle?: string, textIfPlural?: string): string; /** * Returns the prefix for a number if it positive + or negative -. * @param num The number to check for negative or positive. * @returns Empty string is num is 0, + if positive, or - if negative. */ export declare function plusMinus(num: number): string; /** * Returns the prefix if the given string s has a value (not empty). * Generally used in loops so that the prefix is not prepended on the first pass. * @param s A string to prefix with a value if the string has data. * @param prefix The prefix if the string is not empty. * @returns The prefix if the string is not empty. */ export declare function prefixIfHasData(s: string, prefix?: string): string; /** * Renames a property of an object with a new key name. * @param obj The object to rename the key. * @param oldKey The original key to rename. * @param newKey The new name of the key. * @returns The original object with the renamed key. */ export declare function renameProperty(obj: any, oldKey: any, newKey: any): object; /** * Runs a given function on all members of an object. * @param obj The object to run func() on all members. * @param func A function that receives each string property key and its value * @param mustHaveValue If true, the property must have a value in order for func() to be called. * @returns The original object with function having been run on each property. */ export declare function runOnAllMembers(obj: T, func: (key: string, value: unknown) => unknown, mustHaveValue?: boolean): T; /** * Searches the object looking for the first array it finds. * If the object passed in is already an array, it is returned. * @param obj The object to look for the array. * @returns Returns obj if it is an array, or if obj is an object, the first array found is returned. [] if none found. */ export declare function searchObjectForArray(obj: object): T[]; /** * Compares two objects and returns a value for use in the JavaScript sort() method. * @param a The first object to compare with. * @param b The second object to compare with. * @param isAsc True if you want to sort ascending. * @param compareStringsLowercase True if you want to do a lowercase compare on strings. * @returns -1, 0 or 1 depending on the sort direction. */ export declare function sortFunction(a: any, b: any, isAsc?: string | boolean, compareStringsLowercase?: boolean): number; /** * Takes a string or array of strings, iterates over each string and splits them according to the splitter provided. * Each split string is then added to an array and the array of split strings is returned. * @param strOrArray A {@link StringOrStringArray} to push all items split with the splitter provided. * @param splitter A string of what to split every string by. * @param removeEmpties If true, remove all empty strings. * @param trimStrings True if you want to remove any surrounding spaces on every string. * @returns An array of every string split by splitter. */ export declare function splitToArray(strOrArray: StringOrStringArray, splitter?: string, removeEmpties?: boolean, trimStrings?: boolean): string[]; /** * Calls splitToArray and if only one string is the array is returned, just that string is returned. * Otherwise the array returned from splitToArray is returned intact. * @param strOrArray A {@link StringOrStringArray} to push all items split with the splitter provided. * @param splitter A string of what to split every string by. * @param removeEmpties If true, remove all empty strings. * @param trimStrings True if you want to remove any surrounding spaces on every string. * @returns An array of every string split by splitter, of if only 1 string is the result of splitToArray, the string itself is returned. */ export declare function splitToArrayOrStringIfOnlyOne(strOrArray: StringOrStringArray, splitter?: string, removeEmpties?: boolean, trimStrings?: boolean): StringOrStringArray; /** * Calls splitToArray and if only one string is the array is returned, just that string is returned uppercase. * Otherwise the array returned from splitToArray is returned with each string uppercased. * @param strOrArray A {@link StringOrStringArray} to push all items split with the splitter provided. * @param splitter A string of what to split every string by. * @param removeEmpties If true, remove all empty strings. * @param trimStrings True if you want to remove any surrounding spaces on every string. * @returns An array of every string split by splitter, of if only 1 string is the result of splitToArray with every string uppercased, the string itself is returned uppercase. */ export declare function splitToArrayOrStringIfOnlyOneToUpper(strOrArray: StringOrStringArray, splitter?: string, removeEmpties?: boolean, trimStrings?: boolean): StringOrStringArray; /** * Creates a string with a name=value. Optional wrapping of the value is provided. * @param name The name. * @param value The value to set the name. * @param valueWrapper An optional wrapper around the value. Usually a quote or double quote. * @returns The name=value string. */ export declare function stringEquals(name: string, value: string, valueWrapper?: string): string; /** * Creates a string with a name='value' or name="value" depending on useSingleQuote. * @param name The name. * @param value The value to set the name. * @param useSingleQuote True if you want to use a single quote, otherwise a double quote is used. * @returns The name="value" or name='value' string. */ export declare function stringEqualsQuoted(name: string, value: string, useSingleQuote?: boolean): string; /** * Wraps a given string str with a prefix and suffix. * @param left The prefix to put in front of the str. * @param str The string to be wrapped. * @param right The suffix to put after str. * @returns A string of left + str + right. Guaranteed to be a safe string. */ export declare function stringWrap(left: string, str: string, right: string): string; /** * Creates a string as "str". * @param str The string to wrap in double quotes. * @returns The "str" wrapped string. */ export declare function stringWrapDoubleQuote(str: string): string; /** * Creates a string as (str) wrapped in parentheses. * @param str The string to wrap in parentheses. * @returns The (str) wrapped string. */ export declare function stringWrapParen(str: string): string; /** * Creates a string as 'str'. * @param str The string to wrap in single quotes. * @returns The 'str' wrapped string. */ export declare function stringWrapSingleQuote(str: string): string; /** * Returns the number of milliseconds between two times. * @param startTime The time to begin the diff with. * @param endTime The ending time for the diff. If none provided, the current time is used. * @returns The absolute value of milliseconds difference between the two times. */ export declare function timeDifference(startTime: Date, endTime?: Date): number; /** * Returns the number of seconds between two times. * @param startTime The time to begin the diff with. * @param endTime The ending time for the diff. If none provided, the current time is used. * @returns The absolute value of seconds difference between the two times rounded down (even if milliseconds is > 500) */ export declare function timeDifferenceInSeconds(startTime: Date, endTime?: Date): number; /** * Returns the number of seconds or optionally milliseconds, between two times as a string representation. * i.e., 5 days 21 hours 59 minutes 35 seconds 889ms, or 5d 21h 59m 35s 889ms. Used mostly for log messages. * @param startTime The time to begin the diff with. Usually from a new Date() * @param endTime The ending time for the diff. If none provided, the current time is used. * @param longFormat True if you want day, hour, minute, and second to be spelled out. False if you want the dhms abbreviations only. * @param showMilliseconds True if you want the milliseconds included in the time difference. * @returns The absolute value of seconds or milliseconds difference between the two times as a string. */ export declare function timeDifferenceString(startTime: Date, endTime?: Date, longFormat?: boolean, showMilliseconds?: boolean): string; /** * Returns the number of seconds or optionally milliseconds, between two times as a string representation. * i.e., 5 days 21 hours 59 minutes 35 seconds 889ms, or 5d 21h 59m 35s 889ms. Used mostly for log messages. * @param millis The time in milliseconds. Usually from new Date().getTime() * @param longFormat True if you want day, hour, minute, and second to be spelled out. False if you want the dhms abbreviations only. * @param showMilliseconds True if you want the milliseconds included in the time difference. * @returns The absolute value of seconds or milliseconds difference between the two times as a string. */ export declare function timeDifferenceStringFromMillis(millis: number, longFormat?: boolean, showMilliseconds?: boolean, showMillisecondsIfUnderASecond?: boolean): string; /** * Takes a number and converts to its uppercase hexadecimal string value. * @param decimal The number to convert to hexadecimal. * @param chars Number of chars to pad for leading zeros. * @returns */ export declare function toHex(decimal: number, chars?: number): string; /** * Joins two strings to make a full URL. This method guards against trailing and leading /'s and always well forms the URL. * If a trailing / is desired, urlJoin checks to ensure there is not already trailing / and variables have not already been added to the URL. * @param baseUrl The URL base path to start the joining by /. * @param relativePath The URL's relative path to be joined. * @param addTrailingSlash Set to true to append a trailing / if this is a pure URL without variables. * @returns A safely constructed URL joined with a /. */ export declare function urlJoin(baseUrl: string, relativePath?: string, addTrailingSlash?: boolean): string; //# sourceMappingURL=general.d.mts.map