{ "version": 3, "sources": ["../helpers.js"], "sourcesContent": ["\"use strict\"\n\n//////////////////////////////////////////////\n//////////////////////////////////////////////\n// Booleans\n//////////////////////////////////////////////\n//////////////////////////////////////////////\n\n/**\nisEmpty is a helper function to determine if thing is empty. \n\nFunctions are considered always not empty. \n\nArrays: Only if an array has no elements it is empty. isEmpty does not check\nelement contents. (For item contents, do: `isEmpty(array[0])`)\n\nObjects are empty if they have no keys. (Returns len === 0 of object keys.)\n\nNaN returns true. (NaN === NaN is always false, as NaN is never equal to\nanything. NaN is the only JavaScript value unequal to itself.)\n\nDon't use on HTMl elements. For HTML elements, use the !== equality check\n(element !== null). TODO fix this\n\nCannot use CryptoKey with this function since (len === 0) always. \n\n@param {any} thing Thing you wish was empty. \n@returns {boolean} Boolean. \n*/\nfunction isEmpty(thing) {\n\tif (typeof thing === 'function') {\n\t\treturn false\n\t}\n\n\tif (Array.isArray(thing)) {\n\t\tif (thing.length == 0) {\n\t\t\treturn true\n\t\t}\n\t}\n\n\tif (thing === Object(thing)) {\n\t\tif (Object.keys(thing).length === 0) {\n\t\t\treturn true\n\t\t}\n\t\treturn false\n\t}\n\n\tif (!isBool(thing)) {\n\t\treturn true\n\t}\n\treturn false\n}\n\n\n/**\nHelper function to determine boolean. \n\nJavascript, instead of considering everything false except a few key words,\ndecided everything is true instead of a few key words. Why? Because\nJavascript. This function inverts that assumption, so that everything can be\nconsidered false unless true. \n@param {any} bool Thing that you wish was a boolean. \n@returns {boolean} An actual boolean.\n*/\nfunction isBool(bool) {\n\tif (\n\t\tbool === false ||\n\t\tbool === \"false\" ||\n\t\tbool === undefined ||\n\t\tbool === \"undefined\" ||\n\t\tbool === \"\" ||\n\t\tbool === 0 ||\n\t\tbool === \"0\" ||\n\t\tbool === null ||\n\t\tbool === \"null\" ||\n\t\tbool === \"NaN\" ||\n\t\tNumber.isNaN(bool) ||\n\t\tbool === Object(bool) // isObject\n\t) {\n\t\treturn false\n\t}\n\treturn true\n}\n\n/**\nHelper function \"null\" types. Useful on things where there's a difference\nbetween the zero and \"null\" value. \n\nFor example, in Hex conversion \"\" is not equal to 0. Hex \"\" is \"\" while 0 is\nHex 00. \n@param {any} thing Thing that you wish was null. \n@returns {boolean} An actual boolean.\n*/\nfunction isNull(thing) {\n\tif (\n\t\tthing === \"\" ||\n\t\tthing === null ||\n\t\tthing.toLowerCase() === \"null\" ||\n\t\tthing === undefined ||\n\t\tthing.toLowerCase() === \"undefined\"\n\t) {\n\t\treturn true\n\t}\n\treturn false\n}\n\n\n/**\nHelper function to determine true over bool, string, and int types.\n@param {any} thing Thing that you wish was a true. \n@returns {boolean} An actual true. \n*/\nfunction isTrue(thing) {\n\tif (thing === true ||\n\t\t(typeof thing == \"string\" && thing.toLowerCase() === \"true\") ||\n\t\t(parseInt(thing) === 1)) {\n\t\treturn true\n\t}\n\treturn false\n}\n\n\n//////////////////////////////////////////////\n//////////////////////////////////////////////\n// Time\n//////////////////////////////////////////////\n//////////////////////////////////////////////\n\n// Now returns Unix time. \nfunction Now() {\n\treturn (Math.floor(Date.now() / 1000))\n}\n\n\n//////////////////////////////////////////////\n//////////////////////////////////////////////\n// Visibility\n//////////////////////////////////////////////\n//////////////////////////////////////////////\n\n/**\nClear removes innerHTML element. \n@param {string|element} element string id of element or element.\n*/\nfunction Clear(element) {\n\tif (typeof element == \"string\") {\n\t\telement = document.getElementById(element)\n\t}\n\telement.innerHTML = \"\"\n}\n\n\n/**\nSetHTML sets innerHTML of element. \n@param {string|element} element string id of element or element.\n@param {html} html string id of element or element.\n*/\nfunction SetHTML(element, html) {\n\tif (typeof element == \"string\") {\n\t\telement = document.getElementById(element)\n\t}\n\telement.innerHTML = html\n}\n\n\n/**\nShow makes an element Visible.\n@param {string|element} element string id of element or element.\n*/\nfunction Show(element) {\n\tif (typeof element == \"string\") {\n\t\telement = document.getElementById(element)\n\t}\n\tif (element != null) {\n\t\telement.hidden = false\n\t}\n}\n\n\n/**\nHide hides an element.\n@param {string|element} element\n*/\nfunction Hide(element) {\n\tif (typeof element == \"string\") {\n\t\tvar element = document.getElementById(element)\n\t}\n\tif (element != null) {\n\t\telement.hidden = true\n\t}\n}\n\n\n/**\nToggleVisible toggles an element's visibility\n@param {string|element} id String id of element or element.\n@returns {boolean} If the element was hidden.\n*/\nfunction ToggleVisible(element) {\n\tif (typeof element == \"string\") {\n\t\telement = document.getElementById(element)\n\t}\n\t// console.log(\"Hidden: \" + element.hidden)\n\tif (isBool(element.hidden)) {\n\t\telement.hidden = false\n\t\treturn false\n\t}\n\telement.hidden = true\n\treturn true\n}\n\n/**\nToggleVisibleIfExists toggles an element's visibility if the element exists.\n@param {string|element} id String id of element or element.\n@returns {void}\n*/\nfunction ToggleVisibleIfExists(element) {\n\tif (typeof element == \"string\") {\n\t\telement = document.getElementById(element)\n\t}\n\tif (element !== null) {\n\t\tToggleVisible(element)\n\t}\n}\n\n\n/**\nisVisible returns whether or not the given element is visible. Passing in\nan empty element fails and Javascript logs an error trying to access\na null reference.\n@param {string|element} element \n@returns {boolean} If the element was hidden\n*/\nfunction isVisible(element) {\n\tif (typeof element == \"string\") {\n\t\tvar element = document.getElementById(element)\n\t}\n\treturn !element.hidden // hidden is a html boolean.\n}\n\n/**\nDisable marks an element as disabled. \n@param {string|element} id string id of element or element.\n*/\nfunction Disable(element) {\n\tif (typeof element == \"string\") {\n\t\tvar element = document.getElementById(element)\n\t}\n\tif (element != null) {\n\t\telement.disabled = true\n\t}\n}\n\n/**\nEnable marks an element as not disabled.\n@param {string|element} id string id of element or element.\n*/\nfunction Enable(element) {\n\tif (typeof element == \"string\") {\n\t\tvar element = document.getElementById(element)\n\t}\n\tif (element != null) {\n\t\telement.disabled = false\n\t}\n}\n\n//////////////////////////////////////////////\n//////////////////////////////////////////////\n// Clipboard\n//////////////////////////////////////////////\n//////////////////////////////////////////////\n\n/**\nCopyToClipBoardElement copys the contents of an element to the clipboard.\n@param {string|element} element An element from the page.\n@returns {void}\n*/\nfunction ClipboardE(element) {\n\tif (typeof element == \"string\") {\n\t\telement = document.getElementById(element)\n\t}\n\tvar selection = window.getSelection()\n\tvar range = document.createRange()\n\trange.selectNodeContents(element)\n\tselection.removeAllRanges()\n\tselection.addRange(range)\n\tdocument.execCommand('copy') //add to clipboard.\n}\n\n/**\nCopyStringToClipboard accepts a string, creates a hidden element on the page\npopulated with string, and then copies string to the clipboard. Input string\nmay be ID of element or string to copy.\n@param {string} string Literal string to be copied to the clipboard.\n@returns {void}\n*/\nfunction ClipboardS(string) {\n\t// Can only copy elements from DOM. Create DOM element and copy. \n\tlet copyDiv = document.getElementById('copy_to_clipboard')\n\tif (isEmpty(copyDiv)) {\n\t\tlet hiddenElement = document.createElement('div')\n\t\thiddenElement.setAttribute('class', \"hidden\")\n\t\thiddenElement.setAttribute('id', \"copy_to_clipboard\")\n\n\t\tdocument.body.append(hiddenElement)\n\t\tcopyDiv = hiddenElement\n\t}\n\tcopyDiv.textContent = string\n\n\t// Set hidden after copy since cannot copy from hidden.\n\tcopyDiv.hidden = false\n\tClipboardE(copyDiv)\n\tcopyDiv.hidden = true\n}"], "mappings": "aA6BA,SAAS,QAAQA,EAAO,CACvB,OAAI,OAAOA,GAAU,WACb,GAGJ,MAAM,QAAQA,CAAK,GAClBA,EAAM,QAAU,EACZ,GAILA,IAAU,OAAOA,CAAK,EACrB,OAAO,KAAKA,CAAK,EAAE,SAAW,EAM9B,QAAOA,CAAK,CAIlB,CAaA,SAAS,OAAOC,EAAM,CACrB,MACC,EAAAA,IAAS,IACTA,IAAS,SACTA,IAAS,QACTA,IAAS,aACTA,IAAS,IACTA,IAAS,GACTA,IAAS,KACTA,IAAS,MACTA,IAAS,QACTA,IAAS,OACT,OAAO,MAAMA,CAAI,GACjBA,IAAS,OAAOA,CAAI,EAKtB,CAWA,SAAS,OAAOD,EAAO,CACtB,OACCA,IAAU,IACVA,IAAU,MACVA,EAAM,YAAY,IAAM,QACxBA,IAAU,QACVA,EAAM,YAAY,IAAM,WAK1B,CAQA,SAAS,OAAOA,EAAO,CACtB,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