{"version":3,"file":"string_utils-CC1Qc9ax.js","sources":["../../app/javascript/utils/string_utils.jsx"],"sourcesContent":["import _ from \"lodash\";\n\n/**\n * Note: This will return an unsigned \"0\" if the number is 0.\n * @param {Number}\n * @return {String}\n */\nfunction signedNumber(n) {\n if (n > 0) {\n return \"+\" + n;\n } else {\n return n.toString();\n }\n}\n\n/**\n * Splits a chunk of text into lines, such that 1) we don't break words, and 2) no line exceeds a\n * given number of characters.\n * @param {String} A chunk of text without newlines, where words are separated by spaces.\n * @param {Number} How many characters to allow on each line.\n * @return {Array}\n */\nfunction wrapText(text, characterLimit) {\n const result = [];\n const words = text.split(\" \");\n\n let currentLine = [];\n _.forEach(words, (word) => {\n if (currentLine.concat(word).join(\" \").length > characterLimit) {\n // If adding this word would make the line too long, deposit what we have (if anything) in the\n // results and move on to a new line.\n\n if (currentLine.length > 0) {\n result.push(currentLine.join(\" \"));\n }\n currentLine = [];\n }\n\n currentLine.push(word);\n });\n\n // Tack on the words that were hanging around in currentLine when we finished.\n result.push(currentLine.join(\" \"));\n\n return result;\n}\n\n/**\n * Sorts an array of strings alphabetically, except for certain enumerated strings which are put at\n * the end. An example use case: alphabetically sorting an array that contains 'Other', but you want\n * 'Other' to be at the end.\n * @param {Array} The strings to sort.\n * @param {Array} The list of exceptional strings to put at the end of the sorted array.\n * @return {Array} Most strings sorted alphabetically, exceptional strings sorted according\n * to the order they appear in the exceptions array.\n */\nfunction sortedAlphabeticalWithExceptions(strings, exceptions) {\n const unexceptionalStrings = strings.filter((string) => !exceptions.includes(string));\n const exceptionalStrings = strings.filter((string) => exceptions.includes(string));\n\n const sortedUnexceptionalStrings = [...unexceptionalStrings].sort();\n const sortedExceptionalStrings = [...exceptionalStrings].sort(\n (a, b) => exceptions.indexOf(a) - exceptions.indexOf(b)\n );\n return sortedUnexceptionalStrings.concat(sortedExceptionalStrings);\n}\n\n/**\n * @param {String} The first name of the user.\n * @param {String} The last name of the user.\n * @return {String} The combined and formatted name of the user.\n */\nfunction fullDisplayNameFor(firstName, lastName) {\n return _.upperFirst(firstName) + \" \" + _.upperFirst(lastName);\n}\n\n/**\n * @param {String} The phrase to parameterize.\n * @return {String} The parameterized phrase.\n */\nfunction parameterize(phrase) {\n return phrase\n .trim()\n .toLowerCase()\n .replace(/[^a-zA-Z0-9 -]/, \"\")\n .replace(/\\s/g, \"-\");\n}\n\nconst emailRegex = /^\\w+([.-]?\\w+)*(\\+([.-]?\\w+)*)?@\\w+([.-]?\\w+)*(\\.\\w{2,3})+/;\n\n// 10 or more characters and contain at least 1 uppercase character, 1 number, and 1 special character.\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nconst passwordRegex =\n /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[`~!@#$%^&*()\\-=_+{}\\[\\]|\\\\;:'\",<.>\\/?])(?=.{10,})/;\nconst passwordRegexMismatchMessage =\n \"Must be 10 or more characters and contain at least 1 uppercase character, 1 number, and 1 special character.\";\n\nexport {\n signedNumber,\n wrapText,\n sortedAlphabeticalWithExceptions,\n fullDisplayNameFor,\n parameterize,\n emailRegex,\n passwordRegex,\n passwordRegexMismatchMessage,\n};\n"],"names":["fullDisplayNameFor","firstName","lastName","_","parameterize","phrase","emailRegex","passwordRegex","passwordRegexMismatchMessage"],"mappings":"qaAwEA,SAASA,EAAmBC,EAAWC,EAAU,CAC/C,OAAOC,EAAE,WAAWF,CAAS,EAAI,IAAME,EAAE,WAAWD,CAAQ,CAC9D,CAMA,SAASE,EAAaC,EAAQ,CACrB,OAAAA,EACJ,OACA,cACA,QAAQ,iBAAkB,EAAE,EAC5B,QAAQ,MAAO,GAAG,CACvB,CAEA,MAAMC,EAAa,6DAKbC,EACJ,4FACIC,EACJ"}