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,184 lines (1,131 loc) 40.9 kB
var __defProp = Object.defineProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; // src/any/_any.functions.ts var any_functions_exports = {}; __export(any_functions_exports, { check: () => any_check_functions_exports, compare: () => any_compare_functions_exports, configure: () => any_configure_functions_exports, get: () => any_get_functions_exports }); // src/any/any.check.functions.ts var any_check_functions_exports = {}; __export(any_check_functions_exports, { valueIsNull: () => isAnyValueNull }); function isAnyValueNull(value) { return value === null || value === void 0; } // src/any/any.compare.functions.ts var any_compare_functions_exports = {}; __export(any_compare_functions_exports, { twoValues: () => compareTwoAnyValues }); function compareTwoAnyValues(value_01, value_02) { if (value_01 === null || value_01 === void 0 || value_02 === null || value_02 === void 0) { return false; } return value_01 === value_02; } // src/any/any.configure.functions.ts var any_configure_functions_exports = {}; __export(any_configure_functions_exports, { fallback: () => configureFallbackIfAnyValueIsNull, fallbackIfValueIsNull: () => configureFallbackIfAnyValueIsNull, fallbackValue: () => configureFallbackIfAnyValueIsNull }); function configureFallbackIfAnyValueIsNull(value, fallbackValue = null) { const fallback = fallbackValue === null || fallbackValue === void 0 ? null : fallbackValue; return value === null || value === void 0 ? fallback : value; } // src/any/any.get.functions.ts var any_get_functions_exports = {}; __export(any_get_functions_exports, { trueFlag: () => placeholder }); function placeholder() { return true; } // src/array/_array.functions.ts var array_functions_exports = {}; __export(array_functions_exports, { check: () => array_check_functions_exports, compare: () => array_compare_functions_exports, configure: () => array_configure_functions_exports, get: () => array_get_functions_exports }); // src/array/array.check.functions.ts var array_check_functions_exports = {}; __export(array_check_functions_exports, { isValidArrayObject: () => checkIfValidArrayObject, valueIsNull: () => checkIfArrayObjectIsNull }); function checkIfArrayObjectIsNull(value) { return value === null || value === void 0 || !checkIfValidArrayObject(value) || value.length < 1; } function checkIfValidArrayObject(value) { return Array.isArray(value); } // src/array/array.compare.functions.ts var array_compare_functions_exports = {}; __export(array_compare_functions_exports, { twoValues: () => compareTwoArrayObjects }); function compareTwoArrayObjects(array_01, array_02) { if (checkIfArrayObjectIsNull(array_01) || !checkIfArrayObjectIsNull(array_02)) { return false; } if (array_01.length !== array_02.length) { return false; } for (let i = 0; i < array_01.length; i++) { if (array_01[i] !== array_02[i]) { return false; } } return true; } // src/array/array.configure.functions.ts var array_configure_functions_exports = {}; __export(array_configure_functions_exports, { fallbackValue: () => configureNullFallbackValue, nullFallbackValue: () => configureNullFallbackValue }); function configureNullFallbackValue(value, fallbackValue = [], splice = false) { return checkIfArrayObjectIsNull(value) ? splice ? [...fallbackValue] : fallbackValue : splice ? [...value] : value; } // src/array/array.get.functions.ts var array_get_functions_exports = {}; __export(array_get_functions_exports, { find: () => findRecordFromArray, findRecord: () => findRecordFromArray }); // src/text/text.compare.functions.ts var text_compare_functions_exports = {}; __export(text_compare_functions_exports, { twoValues: () => compareTwoTextValues }); // src/text/text.configure.functions.ts var text_configure_functions_exports = {}; __export(text_configure_functions_exports, { fallbackValue: () => configureTextFallbackValue, nullString: () => configureTextFallbackValue, nullText: () => configureTextFallbackValue, replace: () => replaceText, textForSearch: () => configureTextForSearch, textMultiply: () => configureTextMultiply }); // src/text/text.check.functions.ts var text_check_functions_exports = {}; __export(text_check_functions_exports, { isValid: () => checkIfValidString, valueIsNull: () => checkIfTextIsNull }); function checkIfTextIsNull(value, nullValue = "") { try { return value === null || value === void 0 || !checkIfValidString(value) || value === "" || value === nullValue; } catch (err) { console.log("ERROR FOUND: ", err); return true; } } function checkIfValidString(value) { return typeof value === "string"; } // src/text/text.configure.functions.ts function configureTextForSearch(value, makeUpperCase = false) { if (value === void 0 || value === null) return ""; const trimmedValue = value.trim(); return (makeUpperCase ? trimmedValue.toUpperCase() : trimmedValue.toLowerCase()).replace(/\s/g, ""); } function configureTextFallbackValue(value, fallbackValue = "") { return checkIfTextIsNull(value) ? fallbackValue : value; } function configureTextMultiply(valueToMultiply, multiplyAmount = 1) { if (multiplyAmount > 0) { return valueToMultiply.repeat(multiplyAmount); } return ""; } function replaceText(originalText, textToReplace, textToReplaceWith, replaceAllOccurences = false, ignoreCase = false) { if (checkIfTextIsNull(originalText) || checkIfTextIsNull(textToReplace)) { return originalText; } let flags = ""; if (replaceAllOccurences) { flags += "g"; } ; if (ignoreCase) { flags += "i"; } ; const regex = new RegExp(textToReplace.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), flags); return originalText.replace(regex, textToReplaceWith); } // src/text/text.compare.functions.ts function compareTwoTextValues(text_01, text_02, normalize = true) { try { let methText_01 = configureTextFallbackValue(text_01); let methText_02 = configureTextFallbackValue(text_02); if (checkIfTextIsNull(methText_01) && checkIfTextIsNull(methText_02)) { return true; } if (normalize) { methText_01 = configureTextForSearch(methText_01); methText_02 = configureTextForSearch(methText_02); } return methText_01 === methText_02; } catch (err) { console.log("ERROR ENCOUNTERED!", err); return false; } } // src/array/array.get.functions.ts function findRecordFromArray(array, searchValue, shouldNormalize = false, returnMode = "") { if (checkIfArrayObjectIsNull(array)) { return null; } const foundIndex = array.findIndex((item) => { return compareTwoTextValues(item + "", searchValue + "", shouldNormalize); }); switch (returnMode) { case "check": return foundIndex !== -1; case "index": return foundIndex; default: return foundIndex !== -1 ? array[foundIndex] : null; } } // src/boolean/_boolean.functions.ts var boolean_functions_exports = {}; __export(boolean_functions_exports, { check: () => boolean_check_functions_exports, compare: () => boolean_compare_functions_exports, configure: () => boolean_configure_functions_exports, get: () => boolean_get_functions_exports }); // src/boolean/boolean.check.functions.ts var boolean_check_functions_exports = {}; __export(boolean_check_functions_exports, { isValid: () => checkIfValidBooleanFlag, valueIsNull: () => checkIfBooleanIsNull }); function checkIfBooleanIsNull(value) { try { return value === null || value === void 0 || !checkIfValidBooleanFlag(value); } catch (err) { console.log("ERROR FOUND: ", err); return true; } } function checkIfValidBooleanFlag(value) { return compareTwoTextValues(typeof value, "boolean", true); } // src/boolean/boolean.compare.functions.ts var boolean_compare_functions_exports = {}; __export(boolean_compare_functions_exports, { twoValues: () => compareTwoBooleanValues }); function compareTwoBooleanValues(boolean_01, boolean_02) { if (!checkIfBooleanIsNull(boolean_01) && !checkIfBooleanIsNull(boolean_02)) { return boolean_01 === boolean_02; } return false; } // src/boolean/boolean.configure.functions.ts var boolean_configure_functions_exports = {}; __export(boolean_configure_functions_exports, { fallbackValue: () => configureBooleanFallbackValue }); function configureBooleanFallbackValue(value, fallbackValue = false) { return checkIfBooleanIsNull(value) ? fallbackValue : value; } // src/boolean/boolean.get.functions.ts var boolean_get_functions_exports = {}; __export(boolean_get_functions_exports, { trueFlag: () => placeholder2 }); function placeholder2() { return true; } // src/date/_date.functions.ts var date_functions_exports = {}; __export(date_functions_exports, { check: () => date_check_functions_exports, compare: () => date_compare_functions_exports, configure: () => date_configure_functions_exports, get: () => date_get_functions_exports }); // src/date/date.check.functions.ts var date_check_functions_exports = {}; __export(date_check_functions_exports, { isValid: () => checkIfValidDate, valueIsNull: () => checkIfDateIsNull }); function checkIfDateIsNull(value) { try { return value === null || value === void 0 || !checkIfValidDate(value); } catch (err) { console.log("ERROR FOUND: ", err); return true; } } function checkIfValidDate(value) { try { return value instanceof Date && !isNaN(value.getTime()); } catch (err) { return false; } } // src/date/date.compare.functions.ts var date_compare_functions_exports = {}; __export(date_compare_functions_exports, { ifDateIsNull: () => compareIfDateIsNull, twoValues: () => compareTwoDateValues }); function compareTwoDateValues(date_01, date_02) { if (!checkIfDateIsNull(date_01) && !checkIfDateIsNull(date_02)) { return date_01.getTime() === date_02.getTime(); } return false; } function compareIfDateIsNull(value, nullValue = null) { try { return !checkIfDateIsNull(nullValue) ? checkIfDateIsNull(value) : checkIfDateIsNull(value) || compareTwoDateValues(value, nullValue); } catch (err) { console.log("ERROR FOUND: ", err); return true; } } // src/date/date.configure.functions.ts var date_configure_functions_exports = {}; __export(date_configure_functions_exports, { addSpecificTimeToDate: () => setSpecificTimeToDate, addTimePeriod: () => addTimePeriodToDate, dateForBackend: () => getPeriodDateForBackend, fallbackValue: () => configureDateFallbackValue, formatDate: () => formatDate, mongoDBDate: () => getPeriodDateForBackend, monthPeriod: () => getMonthPeriod, setSpecificTimeToDate: () => setSpecificTimeToDate }); // src/date/date.get.functions.ts var date_get_functions_exports = {}; __export(date_get_functions_exports, { basedOnDays: () => getDateBasedOnDays, beginningOfTheMonth: () => getBeginningOfMonth, beginningOfTheYear: () => getBeginningOfTheYear, dateArrayMonths: () => getDateArrayMonths, dateArrayYears: () => getDateArrayYears, dateBasedOnDays: () => getDateBasedOnDays, endOfTheMonth: () => getEndOfMonth, endOfTheYear: () => getEndOfTheYear, findDaysToNextMonday: () => findDaysToNextMonday, findDaysToPreviousMonday: () => findDaysToPreviousMonday, firstDayOfTheMonth: () => getBeginningOfMonth, firstDayOfTheYear: () => getBeginningOfTheYear, lastDayOfTheMonth: () => getEndOfMonth, lastDayOfTheYear: () => getEndOfTheYear, months: () => getDateArrayMonths, monthsList: () => getDateArrayMonths, nextDay: () => getNextDay, previousDay: () => getPreviousDay, tomorrow: () => getNextDay, years: () => getDateArrayYears, yearsList: () => getDateArrayYears, yesterday: () => getPreviousDay }); function getBeginningOfTheYear(date = /* @__PURE__ */ new Date(), evening = false) { let returnValue = new Date(date.getTime()); returnValue.setDate(1); returnValue.setMonth(0); returnValue.setHours(evening ? 23 : 0, evening ? 59 : 0, evening ? 59 : 0); return returnValue; } function getBeginningOfMonth(date = /* @__PURE__ */ new Date(), evening = false) { let returnValue = new Date(date.getTime()); returnValue.setDate(1); returnValue.setHours(evening ? 23 : 0, evening ? 59 : 0, evening ? 59 : 0); return returnValue; } function getEndOfTheYear(date = /* @__PURE__ */ new Date(), evening = false) { let returnValue = new Date(date.getTime()); returnValue.setMonth(12, 0); returnValue.setHours(evening ? 23 : 0, evening ? 59 : 0, evening ? 59 : 0); return returnValue; } function getEndOfMonth(date = /* @__PURE__ */ new Date(), evening = false) { let returnValue = new Date(date.getTime()); returnValue.setMonth(returnValue.getMonth() + 1, 0); returnValue.setHours(evening ? 23 : 0, evening ? 59 : 0, evening ? 59 : 0); return returnValue; } function findDaysToPreviousMonday(date = /* @__PURE__ */ new Date(), makeNegativeFlag = false) { const dayOfWeek = date.getDay(); const makeNegativeNumber = (value) => { return value * (makeNegativeFlag ? -1 : 1); }; switch (dayOfWeek) { case 0: return makeNegativeNumber(6); case 1: return makeNegativeNumber(0); case 2: return makeNegativeNumber(1); case 3: return makeNegativeNumber(2); case 4: return makeNegativeNumber(3); case 5: return makeNegativeNumber(4); case 6: return makeNegativeNumber(5); default: return makeNegativeNumber(0); } } function findDaysToNextMonday(date = /* @__PURE__ */ new Date(), makeNegativeFlag = false) { const dayOfWeek = date.getDay(); const makeNegativeNumber = (value) => { return value * (makeNegativeFlag ? -1 : 1); }; switch (dayOfWeek) { case 0: return makeNegativeNumber(8); case 1: return makeNegativeNumber(7); case 2: return makeNegativeNumber(6); case 3: return makeNegativeNumber(5); case 4: return makeNegativeNumber(4); case 5: return makeNegativeNumber(3); case 6: return makeNegativeNumber(2); default: return makeNegativeNumber(0); } } function getDateArrayYears(oldestYear = 2018, latestYear = (/* @__PURE__ */ new Date()).getFullYear()) { return Array.from({ length: latestYear - oldestYear + 1 }, (_, i) => oldestYear + i); } function getDateArrayMonths(getMonthsAsString = true, monthLength = 0) { const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; if (getMonthsAsString) { return monthNames.map((monthName) => monthLength > 0 ? monthName.substring(0, monthLength) : monthName); } else { return Array.from({ length: 12 }, (_, i) => monthLength > 0 ? String(i + 1).padStart(monthLength, "0") : i + 1); } } function getDateBasedOnDays(date, days = 0, evening = false) { const nextDay = new Date(date.getTime()); nextDay.setDate(nextDay.getDate() + days); nextDay.setHours(evening ? 23 : 0, evening ? 59 : 0, evening ? 59 : 0); return nextDay; } function getPreviousDay(date, evening = false) { return getDateBasedOnDays(date, -1, evening); } function getNextDay(date, evening = false) { return getDateBasedOnDays(date, 1, evening); } // src/number/number.configure.functions.ts var number_configure_functions_exports = {}; __export(number_configure_functions_exports, { fallbackValue: () => configureNullNumber, numberLength: () => configureNumberLength }); // src/number/number.check.functions.ts var number_check_functions_exports = {}; __export(number_check_functions_exports, { isValidNumber: () => checkIfValidNumber, valueIsNull: () => checkIfNumberIsNull }); function checkIfNumberIsNull(value, minValue) { try { let returnValue = value === null || value === void 0 || !checkIfValidNumber(value); if (minValue !== null && minValue !== void 0) { returnValue = returnValue || value <= minValue; } return returnValue; } catch (err) { console.log("ERROR FOUND: ", err); return true; } } function checkIfValidNumber(value) { return compareTwoTextValues(typeof value, "number", true) && !isNaN(value); } // src/number/number.configure.functions.ts function configureNullNumber(value, fallbackValue = 0) { return checkIfNumberIsNull(value) ? fallbackValue : value; } function configureNumberLength(value, digitLength = 0, characterToPadWith = "0") { if (checkIfNumberIsNull(value, -1)) { return value + ""; } const methValue = configureNullNumber(value, 0); const methDigitLength = configureNullNumber(digitLength, 0); return methValue.toString().padStart(methDigitLength, characterToPadWith); } // src/date/date.configure.functions.ts function configureDateFallbackValue(value, fallbackValue = /* @__PURE__ */ new Date(), evening = false) { return addTimePeriodToDate(checkIfDateIsNull(value) ? fallbackValue : value, evening); } function getPeriodDateForBackend(date, evening = false) { const pad = (num) => { return configureNumberLength(num, 2); }; const constDay = pad(date.getDate()); const constMonth = pad(date.getMonth() + 1); const constYear = date.getFullYear(); const dateFormatted = `${constYear}-${constMonth}-${constDay}T`; const constHours = pad(date.getHours()); const constMinutes = pad(date.getMinutes()); const constSeconds = pad(date.getSeconds()); const constTimeFormatted = `${constHours}:${constMinutes}:${constSeconds}${evening ? ".999Z" : ".000Z"}`; return dateFormatted + constTimeFormatted; } function getMonthPeriod(date = /* @__PURE__ */ new Date(), isBeginning = false, evening = false) { let returnValue = new Date(date.getTime()); if (isBeginning) { returnValue.setDate(1); } else { returnValue.setMonth(returnValue.getMonth() + 1, 0); } returnValue.setHours(evening ? 23 : 0, evening ? 59 : 0, evening ? 59 : 0); return returnValue; } function addTimePeriodToDate(date, evening = false) { let returnValue = new Date(date.getTime()); returnValue.setHours(evening ? 23 : 0, evening ? 59 : 0, evening ? 59 : 0); return returnValue; } function setSpecificTimeToDate(date, hour = 8, minute = 0, second = 0) { let returnValue = new Date(date.getTime()); returnValue.setHours(hour, minute, second); return returnValue; } function formatDate(date, format = "DD MMMM YYYY HH:MM:SS") { const configureTextForSearch2 = (value) => { return configureTextForSearch(value); }; switch (configureTextForSearch2(format)) { case configureTextForSearch2("YYYY-MM-DD"): return date.getFullYear() + "-" + getDateArrayMonths(true, 3)[date.getMonth()] + "-" + configureNumberLength(date.getDate(), 2); case configureTextForSearch2("YYYY-MM-DD HH:MM:SS"): return date.getFullYear() + "-" + getDateArrayMonths(true, 3)[date.getMonth()] + "-" + configureNumberLength(date.getDate(), 2) + " " + configureNumberLength(date.getHours(), 2) + ":" + configureNumberLength(date.getMinutes(), 2) + ":" + configureNumberLength(date.getSeconds(), 2); case configureTextForSearch2("DD MMM YYYY HH:MM:SS"): return configureNumberLength(date.getDate(), 2) + " " + getDateArrayMonths(true, 3)[date.getMonth()] + " " + date.getFullYear() + " " + configureNumberLength(date.getHours(), 2) + ":" + configureNumberLength(date.getMinutes(), 2) + ":" + configureNumberLength(date.getSeconds(), 2); case configureTextForSearch2("DD MMM YYYY"): return configureNumberLength(date.getDate(), 2) + " " + getDateArrayMonths(true, 3)[date.getMonth()] + " " + date.getFullYear(); case configureTextForSearch2("DD MMMM YYYY"): return configureNumberLength(date.getDate(), 2) + " " + getDateArrayMonths(true, 0)[date.getMonth()] + " " + date.getFullYear(); // case configureTextForSearch('DD MMMM YYYY HH:MM:SS'): default: return configureNumberLength(date.getDate(), 2) + " " + getDateArrayMonths(true, 0)[date.getMonth()] + " " + date.getFullYear() + " " + configureNumberLength(date.getHours(), 2) + ":" + configureNumberLength(date.getMinutes(), 2) + ":" + configureNumberLength(date.getSeconds(), 2); } } // src/json/_json.functions.ts var json_functions_exports = {}; __export(json_functions_exports, { array: () => json_array_functions_exports, check: () => json_check_functions_exports, compare: () => json_compare_functions_exports, configure: () => json_configure_functions_exports, get: () => json_get_functions_exports }); // src/json/array/_json.array.functions.ts var json_array_functions_exports = {}; __export(json_array_functions_exports, { check: () => json_array_check_functions_exports, compare: () => json_array_compare_functions_exports, configure: () => json_array_configure_functions_exports, get: () => json_array_get_functions_exports }); // src/json/array/json.array.check.functions.ts var json_array_check_functions_exports = {}; __export(json_array_check_functions_exports, { findRecord: () => findRecordInArray }); function findRecordInArray(array, fieldName, searchValue, shouldNormalize = true, returnMode = "") { let result = returnMode === "check" ? false : returnMode === "index" ? -1 : null; if (Array.isArray(array) && array.length > 0) { for (let index = 0; index < array.length; index++) { const item = array[index]; let itemFieldValue = item[fieldName]; let comparisonValue = searchValue; if (shouldNormalize && typeof itemFieldValue === "string" && typeof comparisonValue === "string") { itemFieldValue = itemFieldValue.toLowerCase(); comparisonValue = comparisonValue.toLowerCase(); } if (itemFieldValue === comparisonValue) { switch (returnMode) { case "check": return true; case "index": return index; default: return item; } } } } return result; } // src/json/array/json.array.compare.functions.ts var json_array_compare_functions_exports = {}; __export(json_array_compare_functions_exports, { trueFlag: () => placeholder3 }); function placeholder3() { return true; } // src/json/array/json.array.configure.functions.ts var json_array_configure_functions_exports = {}; __export(json_array_configure_functions_exports, { sortField: () => jsonArraySortField }); // src/json/json.get.functions.ts var json_get_functions_exports = {}; __export(json_get_functions_exports, { fieldValue: () => getJSONFieldValue, fieldValueAny: () => getJSONFieldValueAny, fieldValueArray: () => getJSONFieldValueArray, fieldValueBoolean: () => getJSONFieldValueBoolean, fieldValueDate: () => getJSONFieldValueDate, fieldValueJSON: () => getJSONFieldValueObject, fieldValueNumber: () => getJSONFieldValueNumber, fieldValueObject: () => getJSONFieldValueObject, fieldValueString: () => getJSONFieldValueText, fieldValueText: () => getJSONFieldValueText }); // src/json/json.check.functions.ts var json_check_functions_exports = {}; __export(json_check_functions_exports, { hasField: () => checkJSONHasField, hasFieldAndNullCheck: () => checkJSONHasFieldAndFieldValueIsNotNull, valueIsNull: () => checkIfJSONIsNull, valueIsValid: () => checkIsValidJSON }); function checkIsValidJSON(valueIn) { const confirmIsAnObject = (objectIn) => { if (valueIn !== null && valueIn !== void 0 && typeof objectIn === "object") { return !Array.isArray(objectIn) && !(objectIn instanceof Date) && !(objectIn instanceof RegExp); } return false; }; confirmIsAnObject(valueIn); if (typeof valueIn === "string") { try { const parsed = JSON.parse(valueIn); return confirmIsAnObject(parsed); } catch (e) { return false; } } return false; } function checkIfJSONIsNull(valueIn) { if (checkIsValidJSON(valueIn) === true) { return Object.keys(valueIn).length === 0; } return true; } function checkJSONHasField(jsonObject, fieldName) { return !checkIfJSONIsNull(jsonObject) && Object.prototype.hasOwnProperty.call(jsonObject, fieldName); } function checkJSONHasFieldAndFieldValueIsNotNull(jsonObject, fieldName, fieldDataType = "text") { if (!checkJSONHasField(jsonObject, fieldName)) { return false; } ; const methFieldValue = jsonObject[fieldName]; const methFieldDataType = configureTextForSearch(fieldDataType); switch (methFieldDataType) { case "array": return !checkIfArrayObjectIsNull(methFieldValue); case "boolean": case "flag": case "switch": return !checkIfBooleanIsNull(methFieldValue); case "date": return !checkIfDateIsNull(methFieldValue); case "json": case "object": case "json-object": return !checkIfJSONIsNull(methFieldValue); case "number": case "digit": return !checkIfNumberIsNull(methFieldValue); case "string": case "text": return !checkIfTextIsNull(methFieldValue); default: return !isAnyValueNull(methFieldValue); } } // src/json/json.get.functions.ts function getJSONFieldValue(jsonObject, fieldName, fieldDataType, nullValue = null) { return checkJSONHasFieldAndFieldValueIsNotNull(jsonObject, fieldName, fieldDataType) ? jsonObject[fieldName] : nullValue; } function getJSONFieldValueAny(jsonObject, fieldName, nullValue = null) { return getJSONFieldValue(jsonObject, fieldName, "any", nullValue); } function getJSONFieldValueArray(jsonObject, fieldName, nullValue = []) { return getJSONFieldValue(jsonObject, fieldName, "array", nullValue); } function getJSONFieldValueBoolean(jsonObject, fieldName, nullValue = false) { return getJSONFieldValue(jsonObject, fieldName, "boolean", nullValue); } function getJSONFieldValueDate(jsonObject, fieldName, nullValue = null) { return getJSONFieldValue(jsonObject, fieldName, "date", nullValue); } function getJSONFieldValueObject(jsonObject, fieldName, nullValue = null) { return getJSONFieldValue(jsonObject, fieldName, "json", nullValue); } function getJSONFieldValueNumber(jsonObject, fieldName, nullValue = null) { return getJSONFieldValue(jsonObject, fieldName, "number", nullValue); } function getJSONFieldValueText(jsonObject, fieldName, nullValue = "") { return getJSONFieldValue(jsonObject, fieldName, "string", nullValue); } // src/json/array/json.array.configure.functions.ts function jsonArraySortField(array, fieldName, fieldNameDataType, descendingOrderFlag = false, considerAllFlag = false, considerAllValue = ["Select All"], normalize = true) { const methFieldNameDataType = configureTextForSearch(fieldNameDataType); const methConsiderAllValue = []; switch (methFieldNameDataType) { case "boolean": considerAllValue.forEach((forEachItem) => { methConsiderAllValue.push(checkIfBooleanIsNull(forEachItem) ? false : forEachItem); }); break; case "date": considerAllValue.forEach((forEachItem) => { methConsiderAllValue.push(checkIfDateIsNull(forEachItem) ? 0 : forEachItem.getTime()); }); break; case "number": considerAllValue.forEach((forEachItem) => { methConsiderAllValue.push(checkIfNumberIsNull(forEachItem) ? 0 : forEachItem); }); break; case "string": case "text": considerAllValue.forEach((forEachItem) => { methConsiderAllValue.push(checkIfTextIsNull(forEachItem) ? "" : normalize ? configureTextForSearch(forEachItem) : forEachItem); }); break; default: considerAllValue.forEach((forEachItem) => { methConsiderAllValue.push(isAnyValueNull(forEachItem) ? null : forEachItem); }); break; } const methArrayConsiderAllValue = []; const methArrayTopRecords = []; const mathArray = array.map( (item) => { const methFieldValue = getJSONFieldValue(item, fieldName, fieldNameDataType); let sortMeFieldValue; switch (methFieldNameDataType) { case "boolean": sortMeFieldValue = checkIfBooleanIsNull(methFieldValue) ? false : methFieldValue; break; case "date": sortMeFieldValue = checkIfDateIsNull(methFieldValue) ? 0 : methFieldValue.getTime(); break; case "number": sortMeFieldValue = checkIfNumberIsNull(methFieldValue) ? 0 : methFieldValue; break; case "string": case "text": sortMeFieldValue = checkIfTextIsNull(methFieldValue) ? "" : normalize ? configureTextForSearch(methFieldValue) : methFieldValue; break; default: sortMeFieldValue = isAnyValueNull(methFieldValue) ? null : methFieldValue; break; } return { ...item, sortMe: sortMeFieldValue + "" }; } ); let mathArraySorted = []; switch (methFieldNameDataType) { case "string": case "text": mathArraySorted = mathArray.sort((a, b) => { return a.sortMe.localeCompare(b.sortMe); }); break; default: mathArraySorted = mathArray.sort((a, b) => { return descendingOrderFlag ? b["sortMe"] - a["sortMe"] : a["sortMe"] - b["sortMe"]; }); break; } const returnValue = mathArraySorted.map((item) => { if (considerAllFlag && methConsiderAllValue.includes(item["sortMe"])) { methArrayConsiderAllValue.push(item); return null; } delete item["sortMe"]; return { ...item }; }).filter((item) => item !== null); for (let index = 0; index < methConsiderAllValue.length; index++) { const forItem = methConsiderAllValue[methConsiderAllValue.length - (index + 1)]; if (forItem) { const forTopRecord = findRecordInArray(methArrayConsiderAllValue, "sortMe", forItem + "", true); if (forTopRecord) { delete forTopRecord["sortMe"]; methArrayTopRecords.push(forTopRecord); } } } if (!checkIfArrayObjectIsNull(methArrayTopRecords)) { methArrayTopRecords.forEach((argTopRecord) => { returnValue.unshift({ ...argTopRecord }); }); } return returnValue; } // src/json/array/json.array.get.functions.ts var json_array_get_functions_exports = {}; __export(json_array_get_functions_exports, { filter: () => jsonArrayFilter, filterFromString: () => jsonArrayFilterFromString, find: () => jsonArrayFindRecord, findRecord: () => jsonArrayFindRecord, removeDuplicates: () => jsonArrayRemoveDuplicates }); function jsonArrayFindRecord(argArray, argField, argSearchValue, argNormalizeSearchValues = false, argFindAttribute = "") { let returnValue = null; let methRecord; const methArray = argArray; const methField = configureTextFallbackValue(argField); const methSearchValue = configureTextFallbackValue(argSearchValue); const methNormalizeSearchValues = configureBooleanFallbackValue( argNormalizeSearchValues ); const methFindAttribute = configureTextFallbackValue(argFindAttribute); const configureTextForSearch2 = (value) => { return configureTextForSearch(value); }; switch (configureTextForSearch2(methFindAttribute)) { case configureTextForSearch2("check"): returnValue = false; break; case configureTextForSearch2("index"): returnValue = -1; break; default: returnValue = null; break; } if (!checkIfArrayObjectIsNull(methArray)) { methRecord = methArray.find((argItem, argIndex) => { if (compareTwoTextValues( argItem[methField], methSearchValue, methNormalizeSearchValues )) { switch (configureTextForSearch2(methFindAttribute)) { case configureTextForSearch2("check"): returnValue = true; break; case configureTextForSearch2("index"): returnValue = argIndex; break; case configureTextForSearch2("record"): returnValue = argItem; break; default: returnValue = argItem; break; } return argItem; } }); } return returnValue; } function jsonArrayRemoveDuplicates(argOriginalArray, argField) { const methLookupObject = {}; let returnValue = []; returnValue = Object.keys( argOriginalArray.reduce((prev, next) => { if (!methLookupObject[next[argField]]) { methLookupObject[next[argField]] = next; } return methLookupObject; }, methLookupObject) ).map((i) => methLookupObject[i]); return returnValue; } function jsonArrayFilter(argOriginalArray, argFieldName, argFilterValue, argFilterFor, argNormalizeSearch) { let returnValue = []; const methFilterFor = configureBooleanFallbackValue( argFilterFor, false ); returnValue = argOriginalArray.filter((argRecord) => { if (methFilterFor) { return compareTwoTextValues( argRecord[argFieldName], argFilterValue, argNormalizeSearch ); } else { return !compareTwoTextValues( argRecord[argFieldName], argFilterValue, argNormalizeSearch ); } }); return returnValue; } function jsonArrayFilterFromString(originalArray, filterCondition, startDate = /* @__PURE__ */ new Date(), endDate = /* @__PURE__ */ new Date()) { if (!Array.isArray(originalArray) || originalArray.length === 0) { return []; } let sanitizedCondition = filterCondition.replace(/{|}/g, "").trim(); if (sanitizedCondition.length === 0) { return originalArray; } sanitizedCondition = `return (${sanitizedCondition});`; let dynamicFilter; try { dynamicFilter = new Function("item", "startDate", "endDate", sanitizedCondition); } catch (error) { console.error("Error creating dynamic filter function:", error); return []; } try { return originalArray.filter((item) => dynamicFilter(item, startDate, endDate)); } catch (error) { console.error("Error executing dynamic filter:", error); return []; } } // src/json/json.compare.functions.ts var json_compare_functions_exports = {}; __export(json_compare_functions_exports, { fieldAgainstValue: () => compareJSONFieldAgainstValue, twoValues: () => compareTwoJSONObjects }); // src/number/number.compare.functions.ts var number_compare_functions_exports = {}; __export(number_compare_functions_exports, { twoValues: () => compareTwoNumbers }); function compareTwoNumbers(number_01, number_02) { try { if (!checkIfNumberIsNull(number_01) && !checkIfNumberIsNull(number_02)) { return number_01 === number_02; } return false; } catch (err) { console.log("ERROR ENCOUNTERED - compareTwoNumbers!", err); return false; } } // src/json/json.compare.functions.ts function compareTwoJSONObjects(object_01, object_02) { try { if (!checkIfJSONIsNull(object_01) && !checkIfJSONIsNull(object_02)) { const keys1 = Object.keys(object_01); const keys2 = Object.keys(object_02); if (keys1.length !== keys2.length) { return false; } for (const key of keys1) { if (!keys2.includes(key) || !compareTwoJSONObjects(object_01[key], object_02[key])) { return false; } } return true; } else { return object_01 === object_02; } } catch (err) { console.log("ERROR ENCOUNTERED!", err); return false; } } function compareJSONFieldAgainstValue(jsonObject, fieldName, againstValue, dataType = "string", normalise = true) { try { const methDataType = configureTextForSearch(dataType); const methJSONFieldValue = getJSONFieldValue(jsonObject, fieldName, dataType); switch (methDataType) { case "array": return compareTwoArrayObjects(methJSONFieldValue, againstValue); case "boolean": return compareTwoBooleanValues(methJSONFieldValue, againstValue); case "date": return compareTwoDateValues(methJSONFieldValue, againstValue); case "json": return compareTwoJSONObjects(methJSONFieldValue, againstValue); case "number": return compareTwoNumbers(methJSONFieldValue, againstValue); case "string": case "text": return compareTwoTextValues(methJSONFieldValue + "", againstValue + "", normalise); default: return compareTwoAnyValues(methJSONFieldValue, againstValue); } } catch (err) { console.log("ERROR ENCOUNTERED - compareJSONFieldAgainstValue!", err); return false; } } // src/json/json.configure.functions.ts var json_configure_functions_exports = {}; __export(json_configure_functions_exports, { fallbackIfJSONValueIsNull: () => configureFallbackIfJSONValueIsNull, fallbackValue: () => configureFallbackIfJSONValueIsNull }); function configureFallbackIfJSONValueIsNull(value, fallbackValue = null) { try { const methFallbackValue = checkIfJSONIsNull(fallbackValue) ? null : fallbackValue; return checkIfJSONIsNull(value) ? methFallbackValue : value; } catch (err) { console.log("ERROR FOUND: ", value); return null; } } // src/number/_number.functions.ts var number_functions_exports = {}; __export(number_functions_exports, { check: () => number_check_functions_exports, compare: () => number_compare_functions_exports, configure: () => number_configure_functions_exports, get: () => number_get_functions_exports }); // src/number/number.get.functions.ts var number_get_functions_exports = {}; __export(number_get_functions_exports, { trueFlag: () => placeholder4 }); function placeholder4() { return true; } // src/text/_text.functions.ts var text_functions_exports = {}; __export(text_functions_exports, { check: () => text_check_functions_exports, compare: () => text_compare_functions_exports, configure: () => text_configure_functions_exports, get: () => text_get_functions_exports }); // src/text/text.get.functions.ts var text_get_functions_exports = {}; __export(text_get_functions_exports, { trueFlag: () => placeholder5 }); function placeholder5() { return true; } // src/universal/_universal.functions.ts var universal_functions_exports = {}; __export(universal_functions_exports, { check: () => universal_check_functions_exports, compare: () => universal_compare_functions_exports, configure: () => universal_configure_functions_exports, get: () => universal_get_functions_exports }); // src/universal/universal.check.functions.ts var universal_check_functions_exports = {}; __export(universal_check_functions_exports, { valueIsNull: () => checkIfValueIsNull }); function checkIfValueIsNull(value, dataType = "", minOrNullValue = null) { dataType = configureTextForSearch(dataType); switch (dataType) { case "array": return checkIfArrayObjectIsNull(value); case "boolean": case "flag": case "switch": return checkIfBooleanIsNull(value); case "date": return checkIfDateIsNull(value); case "json": case "object": case "json-object": return checkIfJSONIsNull(value); case "number": case "digit": return checkIfNumberIsNull(value, minOrNullValue); case "string": case "text": return checkIfTextIsNull(value, minOrNullValue); default: return isAnyValueNull(value); } } // src/universal/universal.compare.functions.ts var universal_compare_functions_exports = {}; __export(universal_compare_functions_exports, { twoValues: () => compareTwoValues }); function compareTwoValues(value_01, value_02, dataType = "string", normalise = true) { try { const methDataType = configureTextForSearch(dataType); switch (methDataType) { case "array": return compareTwoArrayObjects(value_01, value_02); case "boolean": return compareTwoBooleanValues(value_01, value_02); case "date": return compareTwoDateValues(value_01, value_02); case "json": return compareTwoJSONObjects(value_01, value_02); case "number": return compareTwoNumbers(value_01, value_02); case "string": case "text": return compareTwoTextValues(value_01, value_02, normalise); default: return compareTwoAnyValues(value_01, value_02); } } catch (err) { console.log("ERROR ENCOUNTERED - compareTwoValues!", err); return false; } } // src/universal/universal.configure.functions.ts var universal_configure_functions_exports = {}; __export(universal_configure_functions_exports, { trueFlag: () => placeholder6 }); function placeholder6() { return true; } // src/universal/universal.get.functions.ts var universal_get_functions_exports = {}; __export(universal_get_functions_exports, { trueFlag: () => placeholder7 }); function placeholder7() { return true; } export { any_functions_exports as any, array_functions_exports as array, boolean_functions_exports as boolean, date_functions_exports as date, json_functions_exports as json, number_functions_exports as number, json_functions_exports as object, text_functions_exports as string, text_functions_exports as text, universal_functions_exports as universal }; //# sourceMappingURL=index.js.map