UNPKG

neu-js-functions

Version:

Reusable **JavaScript utility functions** for Angular and similar applications. This package provides a collection of helper functions designed to streamline application development by promoting consistency, reducing duplication, and ensuring best prac

1 lines 178 kB
{"version":3,"sources":["../src/index.ts","../src/any/_any.functions.ts","../src/any/any.check.functions.ts","../src/any/any.compare.functions.ts","../src/any/any.configure.functions.ts","../src/any/any.get.functions.ts","../src/array/_array.functions.ts","../src/array/array.check.functions.ts","../src/array/array.compare.functions.ts","../src/array/array.configure.functions.ts","../src/array/array.get.functions.ts","../src/text/text.compare.functions.ts","../src/text/text.configure.functions.ts","../src/text/text.check.functions.ts","../src/boolean/_boolean.functions.ts","../src/boolean/boolean.check.functions.ts","../src/boolean/boolean.compare.functions.ts","../src/boolean/boolean.configure.functions.ts","../src/boolean/boolean.get.functions.ts","../src/date/_date.functions.ts","../src/date/date.check.functions.ts","../src/date/date.compare.functions.ts","../src/date/date.configure.functions.ts","../src/date/date.get.functions.ts","../src/number/number.configure.functions.ts","../src/number/number.check.functions.ts","../src/json/_json.functions.ts","../src/json/array/_json.array.functions.ts","../src/json/array/json.array.check.functions.ts","../src/json/array/json.array.compare.functions.ts","../src/json/array/json.array.configure.functions.ts","../src/json/json.get.functions.ts","../src/json/json.check.functions.ts","../src/json/array/json.array.get.functions.ts","../src/json/json.compare.functions.ts","../src/number/number.compare.functions.ts","../src/json/json.configure.functions.ts","../src/number/_number.functions.ts","../src/number/number.get.functions.ts","../src/text/_text.functions.ts","../src/text/text.get.functions.ts","../src/universal/_universal.functions.ts","../src/universal/universal.check.functions.ts","../src/universal/universal.compare.functions.ts","../src/universal/universal.configure.functions.ts","../src/universal/universal.get.functions.ts"],"sourcesContent":["/** IMPORTS SECTION\r\n * **************************************** */\r\nimport * as FunctionsAny from './any/_any.functions.js';\r\nimport * as FunctionsArray from './array/_array.functions.js';\r\nimport * as FunctionsBoolean from './boolean/_boolean.functions.js';\r\nimport * as FunctionsDate from './date/_date.functions.js';\r\nimport * as FunctionsJSON from './json/_json.functions.js';\r\nimport * as FunctionsNumber from './number/_number.functions.js';\r\nimport * as FunctionsText from './text/_text.functions.js';\r\nimport * as FunctionsUniversal from './universal/_universal.functions.js';\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n // IMPORTED FUNCTIONS\r\n FunctionsAny as any,\r\n FunctionsArray as array,\r\n FunctionsBoolean as boolean,\r\n FunctionsDate as date,\r\n FunctionsJSON as json,\r\n FunctionsJSON as object,\r\n FunctionsNumber as number,\r\n FunctionsText as text,\r\n FunctionsText as string,\r\n FunctionsUniversal as universal,\r\n}\r\n","/** IMPORTS SECTION\r\n * **************************************** */\r\nimport * as FunctionsCheck from \"./any.check.functions\";\r\nimport * as FunctionsCompare from \"./any.compare.functions\";\r\nimport * as FunctionsConfigure from \"./any.configure.functions\";\r\nimport * as FunctionsGet from \"./any.get.functions\";\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n FunctionsCheck as check,\r\n FunctionsCompare as compare,\r\n FunctionsConfigure as configure,\r\n FunctionsGet as get,\r\n}\r\n","/** LOCAL SECTION\r\n * **************************************** */\r\nfunction isAnyValueNull(value: any): boolean {\r\n return value === null || value === undefined;\r\n}\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n isAnyValueNull as valueIsNull,\r\n}\r\n","/** LOCAL SECTION\r\n * **************************************** */\r\nfunction compareTwoAnyValues(value_01: any, value_02: any): boolean {\r\n if (value_01 === null || value_01 === undefined || value_02 === null || value_02 === undefined) {\r\n return false;\r\n }\r\n\r\n return value_01 === value_02;\r\n}\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n compareTwoAnyValues as twoValues,\r\n}\r\n","/** IMPORT SECTION\r\n * **************************************** */\r\nfunction configureFallbackIfAnyValueIsNull(value: any, fallbackValue: any = null): any {\r\n const fallback = (\r\n fallbackValue === null || fallbackValue === undefined\r\n ? null\r\n : fallbackValue\r\n );\r\n\r\n return (\r\n value === null || value === undefined\r\n ? fallback\r\n : value\r\n );\r\n}\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n configureFallbackIfAnyValueIsNull as fallbackIfValueIsNull,\r\n configureFallbackIfAnyValueIsNull as fallback,\r\n configureFallbackIfAnyValueIsNull as fallbackValue,\r\n}\r\n","function placeholder() { return true; }\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n placeholder as trueFlag,\r\n}\r\n","/** IMPORTS SECTION\r\n * **************************************** */\r\nimport * as FunctionsCheck from \"./array.check.functions\";\r\nimport * as FunctionsCompare from \"./array.compare.functions\";\r\nimport * as FunctionsConfigure from \"./array.configure.functions\";\r\nimport * as FunctionsGet from \"./array.get.functions\";\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n FunctionsCheck as check,\r\n FunctionsCompare as compare,\r\n FunctionsConfigure as configure,\r\n FunctionsGet as get,\r\n}\r\n","/** LOCAL SECTION\r\n * **************************************** */\r\nfunction checkIfArrayObjectIsNull(value: any): boolean {\r\n return value === null || value === undefined || !checkIfValidArrayObject(value) || value.length < 1;\r\n}\r\n\r\nfunction checkIfValidArrayObject(value: any): boolean {\r\n return Array.isArray(value);\r\n}\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n checkIfArrayObjectIsNull as valueIsNull,\r\n checkIfValidArrayObject as isValidArrayObject,\r\n}\r\n","/** IMPORT SECTION\r\n * **************************************** */\r\nimport * as FunctionsArrayCheck from './array.check.functions';\r\n\r\n/** LOCAL SECTION\r\n * **************************************** */\r\nfunction compareTwoArrayObjects(array_01: any[], array_02: any[]): boolean {\r\n if (FunctionsArrayCheck.valueIsNull(array_01) || !FunctionsArrayCheck.valueIsNull(array_02)) { return false; }\r\n\r\n if (array_01.length !== array_02.length) { return false; }\r\n\r\n for (let i = 0; i < array_01.length; i++) { if (array_01[i] !== array_02[i]) { return false; } }\r\n\r\n return true;\r\n}\r\n\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n compareTwoArrayObjects as twoValues,\r\n}\r\n","/** IMPORTS SECTION\r\n * **************************************** */\r\nimport * as FunctionsArrayCheck from './array.check.functions';\r\n\r\n/** LOCAL SECTION\r\n * **************************************** */\r\nfunction configureNullFallbackValue(value: any[], fallbackValue: any[] = [], splice: boolean = false): any[] {\r\n return FunctionsArrayCheck.valueIsNull(value)\r\n ? splice\r\n ? [...fallbackValue]\r\n : fallbackValue\r\n : splice\r\n ? [...value]\r\n : value;\r\n}\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n configureNullFallbackValue as nullFallbackValue,\r\n configureNullFallbackValue as fallbackValue,\r\n}\r\n","/** IMPORTS SECTION\r\n * **************************************** */\r\nimport * as FunctionsArrayCheck from './array.check.functions';\r\nimport * as FunctionsTextCompare from '../text/text.compare.functions';\r\n\r\n/** LOCAL SECTION\r\n * **************************************** */\r\nfunction findRecordFromArray(array: any[], searchValue: string, shouldNormalize: boolean = false, returnMode: string = \"\"): any {\r\n if (FunctionsArrayCheck.valueIsNull(array)) {\r\n return null;\r\n }\r\n\r\n // Find index based on the comparison logic\r\n const foundIndex = array.findIndex(item => {\r\n return FunctionsTextCompare.twoValues(item + '', searchValue + '', shouldNormalize);\r\n });\r\n\r\n // Determine return value based on the findAttribute mode\r\n switch (returnMode) {\r\n case \"check\": return foundIndex !== -1;\r\n case \"index\": return foundIndex;\r\n default: return foundIndex !== -1 ? array[foundIndex] : null;\r\n }\r\n}\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n findRecordFromArray as findRecord,\r\n findRecordFromArray as find,\r\n}\r\n","/** IMPORTS SECTION\r\n * **************************************** */\r\nimport * as FunctionsTextConfigure from '../text/text.configure.functions';\r\nimport * as FunctionsTextCheck from '../text/text.check.functions';\r\n\r\n/** compareTwoTextValues\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Compares two text values for equality, with an option to normalize them before comparison. It first converts null or undefined values to empty strings, checks if both are null, and then optionally normalizes them for a case-insensitive and whitespace-insensitive comparison.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `text_01` {string}: The first text value to be compared.\r\n * * `text_02` {string}: The second text value to be compared.\r\n * * `normalize` {boolean}: Optional. Determines whether to normalize the text values before comparison. Defaults to true.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to provide a flexible and reliable way to compare text values,\r\n * accommodating cases where text formatting might vary, such as different cases or extra spaces.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This function is used in scenarios requiring text comparison,\r\n * such as in data validation, search functionality,\r\n * or input matching, where normalization might be necessary.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns `true` if the text values are equal (considering normalization if enabled); `false` otherwise.\r\n *\r\n * ? - `Example`:\r\n * ****************************************\r\n * * 01: `compareTwoTextValues('hello', 'Hello')` would return `true` when normalized, as it ignores case differences.\r\n * * 02: `compareTwoTextValues('hello', 'world', false)` would return `false`, as the texts are different without normalization.\r\n * **************************************** */\r\nfunction compareTwoTextValues(text_01: string, text_02: string, normalize = true): boolean {\r\n try {\r\n let methText_01 = FunctionsTextConfigure.nullText(text_01);\r\n let methText_02 = FunctionsTextConfigure.nullText(text_02);\r\n\r\n if (FunctionsTextCheck.valueIsNull(methText_01) && FunctionsTextCheck.valueIsNull(methText_02)) { return true; }\r\n\r\n if (normalize) {\r\n methText_01 = FunctionsTextConfigure.textForSearch(methText_01);\r\n methText_02 = FunctionsTextConfigure.textForSearch(methText_02);\r\n }\r\n\r\n return methText_01 === methText_02;\r\n } catch (err) { console.log('ERROR ENCOUNTERED!', err); return false; }\r\n}\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n compareTwoTextValues as twoValues,\r\n}\r\n","/** IMPORTS SECTION\r\n * **************************************** */\r\nimport * as FunctionsTextCheck from '../text/text.check.functions';\r\n\r\n/** configureTextForSearch\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Processes the provided `value` to make it suitable for search operations.\r\n * The function trims the value, converts it to upper or lower case based on the `makeUpperCase` flag,\r\n * and removes all whitespace characters.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `value` {string}: The text to be configured for search.\r\n * * `makeUpperCase` {boolean}: Optional. If true, converts the text to upper case. Defaults to false.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to standardize text formatting for search operations,\r\n * ensuring consistent comparison and indexing of search terms.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This method is typically used in scenarios where text needs to be normalized for searching purposes, like in filters or search queries.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns a string that has been trimmed, case-converted, and stripped of whitespace. Returns an empty string if the input is undefined or null.\r\n *\r\n * ? - `Example`:\r\n * ****************************************\r\n * `configureTextForSearch(' Hello World ', true)` would return 'HELLOWORLD'.\r\n * **************************************** */\r\nfunction configureTextForSearch(value: string, makeUpperCase: boolean = false): string {\r\n if (value === undefined || value === null) return \"\";\r\n\r\n const trimmedValue = value.trim();\r\n return (makeUpperCase ? trimmedValue.toUpperCase() : trimmedValue.toLowerCase()).replace(/\\s/g, \"\");\r\n}\r\n\r\n/** configureTextFallbackValue\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Processes the given `value` to either return it as is or replace it with a `fallback` string if the value is considered 'null'.\r\n * It utilizes `FunctionsCheck.nullValue` to determine the nullness of both `value` and `fallback`.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `value` {any}: The value to be checked and potentially replaced.\r\n * * `fallback` {string}: Optional. The fallback string to use if `value` is 'null'. Defaults to an empty string.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to ensure that a provided value is not 'null', and to offer a controlled fallback option.\r\n * It's useful for handling cases where certain values are required and a default must be provided if they are absent.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This function is commonly used in data processing, rendering UI components, or wherever default values are needed for potentially 'null' inputs.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns the original `value` if it is not 'null', otherwise returns the `fallback` value. If `fallback` is 'null', it defaults to an empty string.\r\n *\r\n * ? - `Example`:\r\n * ****************************************\r\n * `configureTextFallbackValue(null, 'default text')` would return 'default text'.\r\n * **************************************** */\r\nfunction configureTextFallbackValue(value: any, fallbackValue: string = \"\"): string {\r\n return FunctionsTextCheck.valueIsNull(value) ? fallbackValue : value;\r\n}\r\n\r\n/** configureTextMultiply\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Multiplies a given text value by a specified number of times. If the multiplication amount is greater than 0, it repeats the text value that many times; otherwise, it returns an empty string.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `valueToMultiply` {string}: The text value to be multiplied.\r\n * * `multiplyAmount` {number}: The number of times the text value should be repeated. OPTIONAL {default: 1}.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to create a new string by repeating a given text multiple times, which can be useful in string formatting, generating patterns, or visual text displays.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This function is used in scenarios where a string needs to be duplicated a specific number of times, such as in UI elements, data generation, or textual patterns.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns the repeated text if `multiplyAmount` is greater than 0; otherwise, returns an empty string.\r\n *\r\n * ? - `Example`:\r\n * ****************************************\r\n * * 01: `configureTextMultiply('hello', 3)` would return 'hellohellohello', as the text 'hello' is repeated 3 times.\r\n * * 02: `configureTextMultiply('hello', 0)` would return '', as the multiplication amount is 0.\r\n * **************************************** */\r\nfunction configureTextMultiply(valueToMultiply: string, multiplyAmount: number = 1) {\r\n if (multiplyAmount > 0) {\r\n return valueToMultiply.repeat(multiplyAmount);\r\n }\r\n return '';\r\n}\r\n\r\n/** replaceText\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Replaces occurrences of a specified substring within the original text with a new substring. The function allows for case-insensitive replacement and can optionally replace all occurrences of the substring.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `originalText` {string}: The original text in which replacements will be made.\r\n * * `textToReplace` {string}: The text to be replaced.\r\n * * `textToReplaceWith` {string}: The text to replace with.\r\n * * `replaceAllOccurences` {boolean}: Flag to determine whether to replace all occurrences. OPTIONAL {default: false}.\r\n * * `ignoreCase` {boolean}: Flag to determine whether the search is case-insensitive. OPTIONAL {default: false}.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to provide a flexible and efficient way to modify strings by replacing specified parts of the text, which is useful in formatting data, creating user interfaces, or developing text-processing applications.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This function is used in scenarios where parts of a string need to be dynamically replaced with other values, such as templating, user input sanitization, or in response to user interactions in a web application.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns a new string with the specified replacements applied.\r\n *\r\n * ? - `Example`:\r\n * ****************************************\r\n * * 01: `replaceText('Hello World', 'World', 'Universe', false, false)` would return 'Hello Universe'.\r\n * * 02: `replaceText('Hello World', 'world', 'Universe', false, false)` would return 'Hello World', demonstrating case-sensitive replacement.\r\n * * 03: `replaceText('Hello World', 'world', 'Universe', false, true)` would return 'Hello Universe', demonstrating case-insensitive replacement.\r\n * **************************************** */\r\nfunction replaceText(originalText: string, textToReplace: string, textToReplaceWith: string, replaceAllOccurences: boolean = false, ignoreCase: boolean = false) {\r\n if (FunctionsTextCheck.valueIsNull(originalText) || FunctionsTextCheck.valueIsNull(textToReplace)) { return originalText; }\r\n\r\n let flags = '';\r\n if (replaceAllOccurences) { flags += 'g' };\r\n if (ignoreCase) { flags += 'i' };\r\n\r\n const regex = new RegExp(textToReplace.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'), flags);\r\n\r\n return originalText.replace(regex, textToReplaceWith);\r\n}\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n configureTextForSearch as textForSearch,\r\n configureTextFallbackValue as nullText,\r\n configureTextFallbackValue as nullString,\r\n configureTextFallbackValue as fallbackValue,\r\n configureTextMultiply as textMultiply,\r\n replaceText as replace,\r\n}\r\n","/** checkIfTextIsNull\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Determines if a provided value is 'null' by checking for the following.\r\n *\r\n * * Step 01: It checks if the `value` is 'null'.\r\n * * Step 02: It checks if the `value` is 'undefined'.\r\n * * Step 03: It checks if the `value` is a valid string.\r\n * * Step 04: It checks if the `value` is a equal to the `nullValue` provided.\r\n *\r\n * If step 01, 02, 03 or 04 is true, then the value is null and this function returns 'true'.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `value` {any}: The value to be checked, typically expected to be a string.\r\n * * `nullValue` {string}: Optional. A specific string that represents a null value for string. Defaults to an empty string.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to provide a comprehensive check for determining if a string value is effectively 'null' or empty,\r\n * which is essential for validating string data in various contexts.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This function is used when validating string inputs,\r\n * particularly when different conditions might be considered equivalent to a null or empty string.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns `true` if the string value is considered 'null' or empty; `false` otherwise.\r\n *\r\n * ? - `Examples`:\r\n * ****************************************\r\n * * `checkIfTextIsNull('no-data', 'no-data')` would return `true`, indicating that the input string is equivalent to a null value.\r\n * **************************************** */\r\nfunction checkIfTextIsNull(value: any, nullValue: string = ''): boolean {\r\n try {\r\n return value === null || value === undefined || !checkIfValidString(value) || value === '' || value === nullValue;\r\n } catch (err) { console.log('ERROR FOUND: ', err); return true; }\r\n}\r\n\r\n/** checkIfValidString\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Determines if the provided value is a valid string.\r\n * Perform a case-insensitive comparison of the value's type against the string 'string'.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `value` {any}: The value to be evaluated for being a string type.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to ensure that a given value is a string,\r\n * which is crucial for string-specific operations and data validations in various application contexts.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This function is used in scenarios requiring confirmation of a value's data type as a string,\r\n * such as in input validations, text processing, or data formatting.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns `true` if the value is of string type; `false` otherwise.\r\n *\r\n * ? - `Example`:\r\n * ****************************************\r\n * * 01: `checkIfValidString('hello')` would return `true`, confirming that 'hello' is a string.\r\n * * 02: `checkIfValidString(123)` would return `false`, as the input is not a string.\r\n * **************************************** */\r\nfunction checkIfValidString(value: any): boolean {\r\n return typeof value === 'string';\r\n}\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n checkIfTextIsNull as valueIsNull,\r\n checkIfValidString as isValid,\r\n}\r\n","/** IMPORTS SECTION\r\n * **************************************** */\r\nimport * as FunctionsCheck from \"./boolean.check.functions\";\r\nimport * as FunctionsCompare from \"./boolean.compare.functions\";\r\nimport * as FunctionsConfigure from \"./boolean.configure.functions\";\r\nimport * as FunctionsGet from \"./boolean.get.functions\";\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n FunctionsCheck as check,\r\n FunctionsCompare as compare,\r\n FunctionsConfigure as configure,\r\n FunctionsGet as get,\r\n}\r\n","/** IMPORTS SECTION\r\n * **************************************** */\r\nimport * as FunctionsTextCompare from '../text/text.compare.functions';\r\n\r\n/** checkIfBooleanIsNull\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Determines if a provided value is 'null' by checking for the following.\r\n *\r\n * * Step 01: It checks if the `value` is 'null'.\r\n * * Step 02: It checks if the `value` is 'undefined'.\r\n * * Step 03: It checks if the `value` is a valid boolean value.\r\n *\r\n * If With Step 01, 02 or 03 is true, then the value is null and this function returns 'true'.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `value` {any}: The value to be evaluated, expected to be a boolean.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to verify whether a value is a valid boolean or effectively 'null', which is crucial for logical operations and boolean data validation.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This function is used in scenarios where it's necessary to confirm that a value is a legitimate boolean, such as in conditional checks or boolean data processing.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns `true` if the value is not a valid boolean; `false` otherwise.\r\n *\r\n * ? - `Example`:\r\n * ****************************************\r\n * `checkIfBooleanIsNull('not a boolean')` would return `true`, indicating that the input is not a valid boolean value.\r\n * **************************************** */\r\nfunction checkIfBooleanIsNull(value: any): boolean {\r\n try {\r\n return value === null || value === undefined || !checkIfValidBooleanFlag(value);\r\n } catch (err) { console.log('ERROR FOUND: ', err); return true; }\r\n}\r\n\r\n/** checkIfValidBooleanFlag\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Checks if the provided value is a valid boolean. It verifies that the value is of the boolean type.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `value` {any}: The value to be checked for being a valid boolean.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to ensure that a given value is a valid boolean,\r\n * which is critical for boolean calculations and data processing.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This function is used whenever there is a need to validate whether an input or a value is a boolean,\r\n * such as in form validations, mathematical calculations, or data processing.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns `true` if the value is a valid boolean, `false` otherwise.\r\n *\r\n * ? - `Example`:\r\n * ****************************************\r\n * * 01: `checkIfValidBooleanFlag(true)` would return `true`.\r\n * * 02: `checkIfValidBooleanFlag(false)` would return `true`.\r\n * * 03: `checkIfValidBooleanFlag(0)` would return `false`.\r\n * * 04: `checkIfValidBooleanFlag(1)` would return `false`.\r\n * * 05: `checkIfValidBooleanFlag(null)` would return `false`.\r\n * * 06: `checkIfValidBooleanFlag('true')` would return `false`.\r\n * * 07: `checkIfValidBooleanFlag('false')` would return `false`.\r\n * **************************************** */\r\nfunction checkIfValidBooleanFlag(value: any): boolean {\r\n return FunctionsTextCompare.twoValues(typeof value, 'boolean', true);\r\n}\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n checkIfBooleanIsNull as valueIsNull,\r\n checkIfValidBooleanFlag as isValid,\r\n}\r\n","/** IMPORTS SECTION\r\n * **************************************** */\r\nimport * as FunctionsBooleanCheck from './boolean.check.functions';\r\n\r\nfunction compareTwoBooleanValues(boolean_01: any, boolean_02: any): boolean {\r\n if (!FunctionsBooleanCheck.valueIsNull(boolean_01) && !FunctionsBooleanCheck.valueIsNull(boolean_02)) {\r\n return boolean_01 === boolean_02;\r\n }\r\n\r\n return false;\r\n}\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n compareTwoBooleanValues as twoValues,\r\n}\r\n","/** IMPORTS SECTION\r\n * **************************************** */\r\nimport * as FunctionsBooleanCheck from '../boolean/boolean.check.functions';\r\n\r\n/** LOCAL SECTION\r\n * **************************************** */\r\nfunction configureBooleanFallbackValue(value: any, fallbackValue: boolean = false): boolean {\r\n return FunctionsBooleanCheck.valueIsNull(value) ? fallbackValue : value;\r\n}\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n configureBooleanFallbackValue as fallbackValue,\r\n}\r\n","/** LOCAL SECTION\r\n * **************************************** */\r\nfunction placeholder() { return true; }\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n placeholder as trueFlag,\r\n}\r\n","/** IMPORTS SECTION\r\n * **************************************** */\r\nimport * as FunctionsCheck from \"./date.check.functions\";\r\nimport * as FunctionsCompare from \"./date.compare.functions\";\r\nimport * as FunctionsConfigure from \"./date.configure.functions\";\r\nimport * as FunctionsGet from \"./date.get.functions\";\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n FunctionsCheck as check,\r\n FunctionsCompare as compare,\r\n FunctionsConfigure as configure,\r\n FunctionsGet as get,\r\n}\r\n","/** checkIfDateIsNull\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Determines if a provided value is 'null' by checking for the following.\r\n *\r\n * * Step 01: It checks if the `value` is 'null'.\r\n * * Step 02: It checks if the `value` is 'undefined'.\r\n * * Step 03: It checks if the `value` is a valid date.\r\n *\r\n * If With Step 01, 02 or 03 is true, then the value is null and this function returns 'true'.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `value` {any}: The value to be evaluated, expected to be a date.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to verify whether a value is a valid date or effectively 'null',\r\n * which is important for date-related operations and validations in applications.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This function is used in scenarios requiring confirmation of the validity of a date, such as in date manipulations, scheduling applications, or input validations.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns `true` if the value is not a valid date; `false` otherwise.\r\n *\r\n * ? - `Example`:\r\n * ****************************************\r\n * * 01: `checkIfDateIsNull(new Date('invalid-date-string'))` would return `true`, indicating that the input is not a valid date.\r\n * **************************************** */\r\nfunction checkIfDateIsNull(value: any): boolean {\r\n try {\r\n return value === null || value === undefined || !checkIfValidDate(value);\r\n } catch (err) { console.log('ERROR FOUND: ', err); return true; }\r\n}\r\n\r\n/** checkIfValidDate\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Determines if a provided value is a valid date. It checks if the value is an instance of the Date object and that its time value is not NaN.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `value` {any}: The value to be evaluated, expected to be a Date object or convertible to a Date.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to verify whether a given value is a legitimate and valid date,\r\n * which is crucial for operations involving date calculations, comparisons, or formatting.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This function is used in scenarios where confirming the validity of a date is necessary, such as in date manipulations, scheduling applications, or input validations.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns `true` if the value is a valid date; `false` otherwise.\r\n *\r\n * ? - `Example`:\r\n * ****************************************\r\n * * 01: `checkIfValidDate(new Date('2023-03-15'))` would return `true`, indicating that the input is a valid date.\r\n * * 02: `checkIfValidDate('2023-03-15')` would return `false`, indicating that the input is NOT a valid date.\r\n * **************************************** */\r\nfunction checkIfValidDate(value: any): boolean {\r\n try {\r\n return value instanceof Date && !isNaN(value.getTime());\r\n } catch (err) { return false; }\r\n}\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n checkIfDateIsNull as valueIsNull,\r\n checkIfValidDate as isValid,\r\n}\r\n","/** IMPORTS SECTION\r\n * **************************************** */\r\nimport * as FunctionsDateCheck from './date.check.functions';\r\n\r\n/** compareTwoDateValues\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Compares two Date objects to determine if they represent the same moment in time. It checks if both arguments are Date objects and then compares their time values using the `getTime()` method.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `date1` {Date}: The first Date object to be compared.\r\n * * `date2` {Date}: The second Date object to be compared.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to accurately determine if two dates are the same, accounting for the exact time down to the millisecond. This is crucial in contexts where precise time comparison is needed.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This function is used in scenarios where verifying the equivalence of two Date objects is necessary, such as in scheduling applications, event management, or date-related calculations.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns `true` if both Date objects represent the same moment in time; `false` otherwise.\r\n *\r\n * ? - `Example`:\r\n * ****************************************\r\n * * 01: `compareTwoDateValues(new Date('2023-11-28'), new Date('2023-11-28'))` would return `true`, as both dates are the same.\r\n * * 02: `compareTwoDateValues(new Date('2023-11-28'), new Date('2023-11-29'))` would return `false`, as the dates are different.\r\n * **************************************** */\r\nfunction compareTwoDateValues(date_01: Date, date_02: Date) {\r\n if (!FunctionsDateCheck.valueIsNull(date_01) && !FunctionsDateCheck.valueIsNull(date_02)) {\r\n return date_01.getTime() === date_02.getTime();\r\n }\r\n\r\n return false;\r\n}\r\n\r\n/** compareIfDateIsNull\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Determines if a provided value is 'null' by checking for the following.\r\n *\r\n * * Step 01: It checks if the `value` is 'null'.\r\n * * Step 02: It checks if the `value` is 'undefined'.\r\n * * Step 03: It checks if the `value` is a valid date object.\r\n * * Step 04: It compares the `value` to a provided `nullValue`.\r\n *\r\n * If Step 01, 02, 03 or 04 is true, then the value is null and this function returns 'true'.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `value` {any}: The JSON value to be evaluated.\r\n * * `nullValue` {any}: Optional. A specific value to compare against to determine if `value` is effectively null. Defaults to null.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to provide an enhanced check for JSON nullness by considering both traditional nullness and a specific comparison value,\r\n * ensuring comprehensive validation of JSON data.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This function is used in scenarios where it's critical to ascertain not just the traditional nullness of a JSON value but also its equivalence to a predefined null representation.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns `true` if the JSON value is null or equivalent to the specified null value; `false` otherwise.\r\n *\r\n * ? - `Example`:\r\n * ****************************************\r\n * `compareIfDateIsNull({key: 'value'}, {key: 'value'})` would return `true` if `{key: 'value'}` is considered as a null value representation.\r\n * **************************************** */\r\nfunction compareIfDateIsNull(value: any, nullValue: any = null): boolean {\r\n try {\r\n return (\r\n !FunctionsDateCheck.valueIsNull(nullValue)\r\n ? FunctionsDateCheck.valueIsNull(value)\r\n : FunctionsDateCheck.valueIsNull(value) || compareTwoDateValues(value, nullValue)\r\n );\r\n } catch (err) { console.log('ERROR FOUND: ', err); return true; }\r\n}\r\n\r\n/** EXPORT SECTION\r\n * **************************************** */\r\nexport {\r\n compareTwoDateValues as twoValues,\r\n compareIfDateIsNull as ifDateIsNull,\r\n}\r\n","/** IMPORTS SECTION\r\n * **************************************** */\r\nimport { valueIsNull as checkIfDateIsNull } from '../date/date.check.functions';\r\nimport { monthsList } from '../date/date.get.functions';\r\nimport * as FunctionsNumberConfigure from '../number/number.configure.functions';\r\nimport * as FunctionsTextConfigure from '../text/text.configure.functions';\r\n\r\n/** LOCAL SECTION\r\n * **************************************** */\r\n\r\n/** configureDateFallbackValue\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Processes the given `value` to either return it as is or replace it with a `fallback` Date if the value is considered 'null'.\r\n * It utilizes `FunctionsCheck.nullValue` to determine the nullness of both `value` and `fallback`.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `value` {any}: The value to be checked and potentially replaced.\r\n * * `fallback` {Date}: Optional. The fallback Date to use if `value` is 'null'. Defaults to 'new Date()'.\r\n * * `evening` {boolean}: OPTIONAL. Determines whether the time is set to midnight (00:00:00) or just before midnight (23:59:59). { Default: false }.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to ensure that a provided value is not 'null', and to offer a controlled fallback option.\r\n * It's useful for handling cases where certain values are required and a default must be provided if they are absent.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This function is commonly used in data processing, rendering UI components, or wherever default values are needed for potentially 'null' inputs.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns the original `value` if it is not 'null', otherwise returns the `fallback` value. If `fallback` is 'null', it defaults to an empty Date.\r\n *\r\n * ? - `Example`:\r\n * ****************************************\r\n * `configureDateFallbackValue(null, 'default text')` would return 'default text'.\r\n * **************************************** */\r\nfunction configureDateFallbackValue(value: any, fallbackValue: Date = new Date(), evening: boolean = false): Date {\r\n return addTimePeriodToDate(checkIfDateIsNull(value) ? fallbackValue : value, evening);\r\n}\r\n\r\n/** getPeriodDateForBackend\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Formats a given Date object into a standardized string suitable for backend processing. The function outputs the date and time in an ISO-like format with customizable precision for milliseconds based on the evening parameter.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `date` {Date}: The Date object to be formatted.\r\n * * `evening` {boolean}: OPTIONAL. Determines whether the time is set to end of day (.999Z) or start of day (.000Z). { Default: false}.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to provide a consistent and precise date-time format for backend operations, ensuring that the date and time are correctly interpreted regardless of server or client time zone settings.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This function is typically used in scenarios where a JavaScript Date object needs to be sent to a backend service or API that requires a specific date-time format, especially when the precision of time is crucial.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns a string representing the formatted date and time according to the specified parameters.\r\n *\r\n * ? - `Example`:\r\n * ****************************************\r\n * * 01: `getPeriodDateForBackend(new Date('2021-01-01'), false)` would return '2021-01-01T00:00:00.000Z'.\r\n * * 02: `getPeriodDateForBackend(new Date('2021-01-01'), true)` would return '2021-01-01T00:00:00.999Z', indicating the end of the day.\r\n * **************************************** */\r\nfunction getPeriodDateForBackend(date: Date, evening: boolean = false) {\r\n // const pad = (num: any) => String(num).padStart(2, '0');\r\n const pad = (num: number) => { return FunctionsNumberConfigure.numberLength(num, 2); };\r\n\r\n const constDay = pad(date.getDate());\r\n const constMonth = pad(date.getMonth() + 1); // getMonth() is 0-indexed, add 1 for the correct month\r\n const constYear = date.getFullYear();\r\n\r\n const dateFormatted = `${constYear}-${constMonth}-${constDay}T`;\r\n\r\n const constHours = pad(date.getHours());\r\n const constMinutes = pad(date.getMinutes());\r\n const constSeconds = pad(date.getSeconds());\r\n\r\n const constTimeFormatted = `${constHours}:${constMinutes}:${constSeconds}${evening ? '.999Z' : '.000Z'}`;\r\n\r\n return dateFormatted + constTimeFormatted;\r\n}\r\n\r\n/** getMonthPeriod\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Adjusts the provided Date object to either the beginning or the end of the month, with an option to set the time to either the beginning or the end of the day. This function clones the input date to avoid mutating the original object and can be used to get a standardized date for specific monthly periods.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `date` {Date}: OPTIONAL. The Date object to be adjusted. If not provided, the current date is used. { Default: new Date() }.\r\n * * `isBeginning` {boolean}: OPTIONAL. Determines whether the date is set to the first day of the month. { Default: false }.\r\n * * `evening` {boolean}: OPTIONAL. Determines whether the time is set to midnight (00:00:00) or just before midnight (23:59:59). { Default: false }.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to provide a convenient way to get a Date object representing either the start or the end of a month, with time set to a specific point in the day. This is useful in scenarios like generating reports, setting up monthly schedules, or any other use case that requires working with monthly date ranges.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This function is typically used when there is a need to align dates to the start or end of a month, especially in scheduling, reporting, or when interfacing with APIs that require specific monthly date ranges.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns a Date object adjusted to the specified day of the month and time of the day.\r\n *\r\n * ? - `Example`:\r\n * ****************************************\r\n * * 01: `getMonthPeriod(new Date('2024-01-18'), true, false)` would return a Date object for '2024-01-01T00:00:00'.\r\n * * 02: `getMonthPeriod(new Date('2024-01-18'), false, true)` would return a Date object for '2024-01-31T23:59:59'.\r\n * **************************************** */\r\nfunction getMonthPeriod(date: Date = new Date(), isBeginning: boolean = false, evening: boolean = false): Date {\r\n let returnValue = new Date(date.getTime()); // Clone the input date to avoid mutating it\r\n\r\n if (isBeginning) {\r\n // Set to the first day of the month\r\n returnValue.setDate(1);\r\n } else {\r\n // Set to the last day of the month\r\n returnValue.setMonth(returnValue.getMonth() + 1, 0);\r\n }\r\n\r\n // Set time based on the 'evening' flag\r\n returnValue.setHours(evening ? 23 : 0, evening ? 59 : 0, evening ? 59 : 0);\r\n\r\n return returnValue;\r\n}\r\n\r\n/** addTimePeriodToDate\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Adjusts the provided Date object to add a time to either the beginning or the end of the day. This function clones the input date to avoid mutating the original object and can be used to get a standardized date with time added to it.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `date` {Date}: The Date object to be adjusted.\r\n * * `evening` {boolean}: OPTIONAL. Determines whether the time is set to midnight (00:00:00) or just before midnight (23:59:59). { Default: false }.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to provide a convenient way to add time to a Date object representing either the beginning or end of the day.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This function is typically used when there is a need to add time to a date.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns a Date object with the specified time value.\r\n *\r\n * ? - `Example`:\r\n * ****************************************\r\n * * 01: `addTimePeriodToDate(new Date('2024-01-18'), true)` would return a Date object for '2024-01-18T00:00:00'.\r\n * * 02: `addTimePeriodToDate(new Date('2024-01-18'), false)` would return a Date object for '2024-01-18T23:59:59'.\r\n * **************************************** */\r\nfunction addTimePeriodToDate(date: Date, evening: boolean = false): Date {\r\n let returnValue = new Date(date.getTime()); // Clone the input date to avoid mutating it\r\n\r\n // Set time based on the 'evening' flag\r\n returnValue.setHours(evening ? 23 : 0, evening ? 59 : 0, evening ? 59 : 0);\r\n\r\n return returnValue;\r\n}\r\n\r\n/** setSpecificTimeToDate\r\n * ----------------------------------------\r\n * ? - `Description`:\r\n * ****************************************\r\n * Sets a specific time (hour, minute, and second) on the provided Date object. This function clones the input date to avoid mutating the original object and allows setting a precise time of day.\r\n *\r\n * ? - `Parameters`:\r\n * ****************************************\r\n * * `date` {Date}: The Date object whose time is to be set.\r\n * * `hour` {number}: OPTIONAL. The hour to be set on the `date` object. { Default: 8 }.\r\n * * `minute` {number}: OPTIONAL. The minute to be set on the `date` object. { Default: 0 }.\r\n * * `second` {number}: OPTIONAL. The second to be set on the `date` object. { Default: 0 }.\r\n *\r\n * ? - `Purpose`:\r\n * ****************************************\r\n * The purpose of this function is to provide a way to set a specific time of day on a Date object, which is useful for standardizing times or creating specific time points within a day.\r\n *\r\n * ? - `Usage`:\r\n * ****************************************\r\n * This function is useful in scenarios where a date needs to have a specific time of day set, such as the beginning of a work shift, a specific appointment time, or the start of an event.\r\n *\r\n * ? - `Returns`:\r\n * ****************************************\r\n * Returns a new Date object with the specified time set.\r\n *\r\n * ? - `Example`:\r\n * ****************************************\r\n * * 01: `setSpecificTimeToDate(new Date('2024-01-18'))` woul