{"version":3,"sources":["hicomExtensions.ts"],"names":["StringExtensions","NullIfEmpty","value","toString","escapeHtml","replace","s","&","<",">","\"","'","/","isValidJSON","jsonString","parsed","JSON","parse","e","getContrastingTextColor","bgColor","contrastRatio","hexToRgb","rgb1","rgb2","l1","luminance","l2","Math","max","min","hex","length","split","map","char","join","parseInt","substr","rgb","r","g","b","pow","isNumeric","isNaN","parseFloat","String","prototype","this","PIPE_DELIM","getArray","val","containsValue","arr","some","arrVal","containsAllValues","every","v","includes","doesNotContainValue","doesNotContainAllValues","containsAnyValue","indexOf","populated","controllerType","doesNotContainAnyValue","is_opera","window","opera","navigator","userAgent","is_Edge","is_chrome","chrome","is_explorer","document","documentMode","is_firefox","test","is_safari","isInputTypeDateTimeLocalSupported"],"mappings":";MAUMA,iBACLC,mBAAmBC,GAClB,MAAa,IAATA,EACI,KAEDA,EAAMC,SAAQ,CACnB,CAgBAC,kBAAkBF,GACd,OAAOA,EAAMG,QAAQ,aAAc,SAAUC,GAUzC,MATgB,CACZC,IAAK,QACLC,IAAK,OACLC,IAAK,OACLC,IAAK,SACLC,IAAK,QACLC,IAAK,Q,EAGQN,EACrB,CAAC,CACL,CAEAO,mBAAmBC,GAEf,IAMI,IAAMC,EAASC,KAAKC,MAAMH,CAAU,EACpC,OAAiB,MAAVC,GAAoC,UAAlB,OAAOA,CAIpC,CAFE,MAAOG,GACL,MAAO,CAAA,CACX,CACJ,C,CAmCJ,SAASC,wBAAwBC,GAQ7B,OAAwB,KAHMC,cAJEC,SAASF,CAAO,EAErB,CAAC,EAAG,EAAG,EAEiC,EAGrC,UAAY,SAC9C,CAcA,SAASC,cAAcE,EAAgBC,GAC7BC,EAAKC,UAAUH,CAAI,EACnBI,EAAKD,UAAUF,CAAI,EACzB,OAAQI,KAAKC,IAAIJ,EAAIE,CAAE,EAAI,MAASC,KAAKE,IAAIL,EAAIE,CAAE,EAAI,IAC3D,CAYA,SAASL,SAASS,GACd,OAAIA,MAAAA,GAA6C,KAARA,EAAmB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aF,GACtC,MAAO,CAACD,SAASG,CAAG,EAAEC,KAAKC,GAAUJ,GAAOI,CAAM,CACtD,CAQA,SAASM,wBAAwBR,EAAaF,GAC1C,MAAO,CAACD,SAASC,CAAG,EAAEM,MAAMC,GAAKR,SAASG,CAAG,EAAEM,SAASD,CAAC,CAAC,CAC9D,CAQA,SAASI,iBAAiBT,EAAaF,GACnC,OAAOD,SAASG,CAAG,EAAEC,KAAKI,GAAkC,CAAC,IAA9BR,SAASC,CAAG,EAAEY,QAAQL,CAAC,CAAQ,CAClE,CASA,SAASM,UAAUC,EAAwBhE,GACvC,MACS,aADDgE,EAKyB,KAAlBnB,OAAO7C,CAAK,EAHM,QAAlB6C,OAAO7C,CAAK,CAK/B,CAQA,SAASiE,uBAAuBb,EAAaF,GACzC,MAAO,CAACD,SAASG,CAAG,EAAEC,KAAKI,GAAkC,CAAC,IAA9BR,SAASC,CAAG,EAAEY,QAAQL,CAAC,CAAQ,CACnE,CAgBA,IAAIS,SAAW,CAAC,CAAEC,OAAeC,OAAiD,GAAxCC,UAAUC,UAAUR,QAAQ,OAAO,EACzES,QAAgD,CAAC,EAAvCF,UAAUC,UAAUR,QAAQ,MAAM,EAC5CU,UAAY,CAAC,CAAEL,OAAeM,QAAU,CAACP,UAAY,CAACK,QACtDG,YAAkC,aAApB,OAAOC,UAA4B,CAAC,CAAEA,SAAiBC,cAAgB,CAACL,QACtFM,WAAa,WAAWC,KAAKT,UAAUC,SAAS,EAChDS,UAAY,iCAAiCD,KAAKT,UAAUC,SAAS,EAQzE,SAASU,oCACL,MAAIH,CAAAA,YAAcE,CAAAA,SAKtB","file":"hicomExtensions.js","sourcesContent":["/// \r\n\r\nimport { } from './Types/hicomGlobalTypes';\r\n\r\n/* ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄\r\n\r\n\t\t\t\t\t\tStrings\r\n\r\n ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ */\r\n\r\nclass StringExtensions {\r\n\tstatic NullIfEmpty(value: string): string {\r\n\t\tif (value == \"\") {\r\n\t\t\treturn null;\r\n\t\t}\r\n\t\treturn value.toString();\r\n }\r\n\r\n /** Mixin to extend the String type with a method to escape unsafe characters\r\n * for use in HTML. Uses OWASP guidelines for safe strings in HTML.\r\n * \r\n * Credit: http://benv.ca/2012/10/4/you-are-probably-misusing-DOM-text-methods/\r\n * https://github.com/janl/mustache.js/blob/16ffa430a111dc293cd9ed899ecf9da3729f58bd/mustache.js#L62\r\n *\r\n * Maintained by stevejansen_github@icloud.com\r\n *\r\n * @license http://opensource.org/licenses/MIT\r\n *\r\n * @version 1.0\r\n *\r\n * @mixin\r\n */\r\n static escapeHtml(value: string): string {\r\n return value.replace(/[&<>\"'\\/]/g, function (s) {\r\n var entityMap = {\r\n \"&\": \"&\",\r\n \"<\": \"<\",\r\n \">\": \">\",\r\n '\"': '"',\r\n \"'\": ''',\r\n \"/\": '/'\r\n };\r\n\r\n return entityMap[s];\r\n });\r\n }\r\n\r\n static isValidJSON(jsonString: string): boolean {\r\n \r\n try {\r\n \r\n // Handle non-exception-throwing cases:\r\n // Neither JSON.parse(false) or JSON.parse(1234) throw errors, hence the type-checking,\r\n // but... JSON.parse(null) returns null, and typeof null === \"object\", \r\n // so we must check for that, too. Thankfully, null is falsey, so this suffices: \r\n const parsed = JSON.parse(jsonString);\r\n return parsed != null && typeof parsed === \"object\";\r\n\r\n } catch (e) {\r\n return false; // If an error is thrown, it's invalid JSON\r\n }\r\n }\r\n}\r\n\r\nString.prototype.NullIfEmpty = function (): string {\r\n\treturn StringExtensions.NullIfEmpty(this);\r\n};\r\n\r\nString.prototype.escapeHtml = function (): string {\r\n return StringExtensions.escapeHtml(this);\r\n};\r\n\r\nString.prototype.isValidJSON = function (): boolean {\r\n return StringExtensions.isValidJSON(this);\r\n};\r\n\r\n/* ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ End Strings ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ */\r\n\r\n\r\n/* ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄\r\n\r\n\t\t\t\t\t\tColors - RGB, HEX\r\n\r\n ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ */\r\n\r\n/**\r\n * Determines the appropriate contrasting text color (black or white) for a given background color.\r\n * \r\n * This function converts the provided hexadecimal background color to its RGB representation,\r\n * calculates the contrast ratio between the background color and both black and white text colors,\r\n * and returns the color with sufficient contrast.\r\n * \r\n * @param {string} bgColor - The background color in hexadecimal format.\r\n * @returns {string} - The contrasting text color in hexadecimal format ('#000000' for black or '#FFFFFF' for white).\r\n */\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nfunction getContrastingTextColor(bgColor: string): string {\r\n const backgroundRgb: number[] = hexToRgb(bgColor);\r\n // Assume black and white as potential text colors\r\n const blackRgb: number[] = [0, 0, 0];\r\n\r\n const blackContrast: number = contrastRatio(backgroundRgb, blackRgb);\r\n\r\n // Return the color with sufficient contrast\r\n return blackContrast >= 4.5 ? '#000000' : '#FFFFFF';\r\n}\r\n\r\n/**\r\n * Calculates the contrast ratio between two colors based on their luminance values.\r\n * \r\n * This function takes two RGB color arrays, computes their luminance values, and then\r\n * calculates the contrast ratio using the formula provided by the WCAG guidelines.\r\n * The contrast ratio is a measure of the difference in perceived brightness between\r\n * the two colors, which is important for ensuring text readability and accessibility.\r\n * \r\n * @param {number[]} rgb1 - The first color as an array of RGB values [r, g, b].\r\n * @param {number[]} rgb2 - The second color as an array of RGB values [r, g, b].\r\n * @returns {number} - The contrast ratio between the two colors.\r\n */\r\nfunction contrastRatio(rgb1: number[], rgb2: number[]): number {\r\n const l1 = luminance(rgb1);\r\n const l2 = luminance(rgb2);\r\n return (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05);\r\n}\r\n\r\n/**\r\n * Converts a hex color code to an RGB array.\r\n * \r\n * This function takes a hex color code as input, removes the leading '#' if present,\r\n * and converts it to an RGB array. If the hex code is in shorthand (3 characters), \r\n * it expands it to the full 6 characters before conversion.\r\n * \r\n * @param {string} hex - The hex color code to convert.\r\n * @returns {number[]} - An array containing the RGB values.\r\n */\r\nfunction hexToRgb(hex: string): number[] {\r\n if (hex === undefined || hex === null || hex === '') return [];\r\n hex = hex.replace(/^#/, '');\r\n if (hex.length === 3) {\r\n hex = hex.split('').map(char => char + char).join('');\r\n }\r\n const r = parseInt(hex.substr(0, 2), 16);\r\n const g = parseInt(hex.substr(2, 2), 16);\r\n const b = parseInt(hex.substr(4, 2), 16);\r\n return [r, g, b];\r\n}\r\n\r\n/**\r\n * Calculate the relative luminance of an RGB color.\r\n * \r\n * This function takes an array of RGB values, normalizes them, and then applies\r\n * the formula for relative luminance as defined by the W3C. The resulting luminance\r\n * value can be used to determine the contrast ratio between colors.\r\n * \r\n * @param {number[]} rgb - An array containing the red, green, and blue color values.\r\n * @returns {number} - The calculated relative luminance.\r\n */\r\nfunction luminance(rgb: number[]): number {\r\n const [r, g, b] = rgb.map(value => {\r\n value /= 255;\r\n return value <= 0.03928 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4);\r\n });\r\n return 0.2126 * r + 0.7152 * g + 0.0722 * b;\r\n}\r\n/* ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ End Colors - RGB, HEX ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ */\r\n\r\n/* ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄\r\n\r\n Numbers\r\n\r\n ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ */\r\n/**\r\n* Checks if the given value is numeric.\r\n* \r\n* This function first attempts to parse the value as a float and then performs \r\n* a check to determine if the parsed value is a valid number. If the value can \r\n* be successfully parsed and is a valid number, it returns true. Otherwise, it returns false.\r\n* \r\n* This is a native JavaScript alternative to jQuery.isNumeric(), which is deprecated.\r\n* \r\n* @param {string | number} value - The value to check if it's numeric.\r\n* @returns {boolean} - Returns true if the value is numeric, false otherwise.\r\n*/\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nfunction isNumeric(value: string | number): boolean {\r\n if (typeof value === 'number') {\r\n return !isNaN(value);\r\n }\r\n if (typeof value === 'string') {\r\n return !isNaN(parseFloat(value));\r\n }\r\n return false;\r\n}\r\n\r\n/* ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ End of numbers ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ */\r\n\r\n\r\n/* ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄\r\n\r\n Array helper methods\r\n\r\n ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ */\r\n\r\nconst PIPE_DELIM: string = \"|\";\r\n\r\n/* eslint-disable @typescript-eslint/no-unused-vars */\r\n/**\r\n * Get array from pipe record delimited text\r\n * @param {string} val\r\n */\r\nfunction getArray(val: string): string[] {\r\n return String(val).split(PIPE_DELIM);\r\n}\r\n\r\n/**\r\n * Array contains single value\r\n * @param {string} arr - The array in string format.\r\n * @param {string} val - The value to check.\r\n * @returns {boolean} - Returns true if the array contains the value, otherwise false.\r\n */\r\nfunction containsValue(arr: string, val: string): boolean {\r\n return getArray(arr).some(arrVal => val == arrVal);\r\n}\r\n\r\n/**\r\n * Array contains all values\r\n * @param {string} arr - The array in string format.\r\n * @param {string} val - The values to check.\r\n * @returns {boolean} - Returns true if the array contains all the values, otherwise false.\r\n */\r\nfunction containsAllValues(arr: string, val: string) {\r\n return getArray(val).every(v => getArray(arr).includes(v));\r\n}\r\n\r\n/**\r\n * Array does not contain the single value\r\n * @param {string} arr - The array in string format.\r\n * @param {string} val - The value to check.\r\n * @returns {boolean} - Returns true if the array does not contain the value, otherwise false.\r\n */\r\nfunction doesNotContainValue(arr: string, val: string): boolean {\r\n return !getArray(arr).some(arrVal => val == arrVal);\r\n}\r\n\r\n/**\r\n * Array does not contain all the values\r\n * @param {string} arr - The array in string format.\r\n * @param {string} val - The values to check.\r\n * @returns {boolean} - Returns true if the array does not contain all the values, otherwise false.\r\n */\r\nfunction doesNotContainAllValues(arr: string, val: string) {\r\n return !getArray(val).every(v => getArray(arr).includes(v));\r\n}\r\n\r\n/**\r\n * Array contains any of the multiple values\r\n * @param {string} arr - The array in string format.\r\n * @param {string} val - The values to check.\r\n * @returns {boolean} - Returns true if the array contains any of the values, otherwise false.\r\n */\r\nfunction containsAnyValue(arr: string, val: string): boolean {\r\n return getArray(arr).some(v => getArray(val).indexOf(v) !== -1);\r\n}\r\n\r\n\r\n/**\r\n * Does the value exist?\r\n * @param {string} controllerType - The type of controller (e.g., 'checkbox').\r\n * @param {any} value - The value to check.\r\n * @returns {boolean} - Returns true if the value exists or is valid, otherwise false.\r\n */\r\nfunction populated(controllerType: string, value: string | number | object): boolean {\r\n switch (controllerType) {\r\n case 'checkbox':\r\n return String(value) !== 'off';\r\n\r\n default:\r\n return String(value) !== '';\r\n }\r\n}\r\n\r\n/**\r\n * Array does not contain any of the multiple values\r\n * @param {string} arr - The array in string format.\r\n * @param {string} val - The values to check.\r\n * @returns {boolean} - Returns true if the array does not contain any of the values, otherwise false.\r\n */\r\nfunction doesNotContainAnyValue(arr: string, val: string): boolean {\r\n return !getArray(arr).some(v => getArray(val).indexOf(v) !== -1);\r\n}\r\n/* eslint-enable @typescript-eslint/no-unused-vars */\r\n\r\n/* ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ End of array helper methods ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ */\r\n\r\n\r\n/* ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄\r\n\r\n Browser support feature detection methods\r\n\r\n ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ */\r\n\r\n//Detect browsers using feature detection and user agent strings\r\n/* eslint-disable @typescript-eslint/no-explicit-any */\r\n/* eslint-disable no-var */\r\n/* eslint-disable @typescript-eslint/no-unused-vars */\r\nvar is_opera = !!(window as any).opera || navigator.userAgent.indexOf(' OPR/') >= 0;\r\nvar is_Edge = navigator.userAgent.indexOf(\"Edge\") > -1;\r\nvar is_chrome = !!(window as any).chrome && !is_opera && !is_Edge;\r\nvar is_explorer = typeof document !== 'undefined' && !!(document as any).documentMode && !is_Edge;\r\nvar is_firefox = /firefox/i.test(navigator.userAgent);\r\nvar is_safari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\r\n\r\n/**\r\n * Check if the browser supports the datetime-local input type.\r\n * @returns {boolean} - Returns true if the browser supports the datetime-local input type, otherwise false.\r\n */\r\n\r\n/* eslint-disable @typescript-eslint/no-unused-vars */\r\nfunction isInputTypeDateTimeLocalSupported(): boolean {\r\n if (is_firefox || is_safari) {\r\n return false;\r\n } else {\r\n return true;\r\n }\r\n}\r\n\r\n/* ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ End of browser support feature detection methods ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ */\r\n"]}