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,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,eAAe,GAAC,CAAC,CAAC,CAAC,GAAG,aAAa,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,eAAe,GAAG,2BAA2B,CAAC,CAAC;AACrI,CAAC","file":"truncate-smart.js","sourcesContent":["/**\n * Date: 2015-10-05\n * Author: Kasper Søfren (https://github.com/kafoso)\n *\n * A truncation feature, where the ellipsis will be placed at a section within\n * the URL making it still somewhat human readable.\n *\n * @param {String} url\t\t\t\t\t\t A URL.\n * @param {Number} truncateLen\t\t The maximum length of the truncated output URL string.\n * @param {String} ellipsisChars\t The characters to place within the url, e.g. \"...\".\n * @return {String} The truncated URL.\n */\nexport function truncateSmart( url: string, truncateLen: number, ellipsisChars?: string ) {\n\n\tlet ellipsisLengthBeforeParsing: number;\n\tlet ellipsisLength: number;\n\n\tif(ellipsisChars == null) {\n\t\tellipsisChars = '…';\n\t\tellipsisLength = 3;\n\t\tellipsisLengthBeforeParsing = 8;\n\t} else {\n\t\tellipsisLength = ellipsisChars.length;\n\t\tellipsisLengthBeforeParsing = ellipsisChars.length;\n\t}\n\n\tlet parse_url = function(url: string) { // Functionality inspired by PHP function of same name\n\t\tlet urlObj: UrlObject = {};\n\t\tlet urlSub = url;\n\t\tlet match = urlSub.match(/^([a-z]+):\\/\\//i);\n\t\tif (match) {\n\t\t\turlObj.scheme = match[1];\n\t\t\turlSub = urlSub.substr(match[0].length);\n\t\t}\n\t\tmatch = urlSub.match(/^(.*?)(?=(\\?|#|\\/|$))/i);\n\t\tif (match) {\n\t\t\turlObj.host = match[1];\n\t\t\turlSub = urlSub.substr(match[0].length);\n\t\t}\n\t\tmatch = urlSub.match(/^\\/(.*?)(?=(\\?|#|$))/i);\n\t\tif (match) {\n\t\t\turlObj.path = match[1];\n\t\t\turlSub = urlSub.substr(match[0].length);\n\t\t}\n\t\tmatch = urlSub.match(/^\\?(.*?)(?=(#|$))/i);\n\t\tif (match) {\n\t\t\turlObj.query = match[1];\n\t\t\turlSub = urlSub.substr(match[0].length);\n\t\t}\n\t\tmatch = urlSub.match(/^#(.*?)$/i);\n\t\tif (match) {\n\t\t\turlObj.fragment = match[1];\n\t\t\t//urlSub = urlSub.substr(match[0].length); -- not used. Uncomment if adding another block.\n\t\t}\n\t\treturn urlObj;\n\t};\n\n\tlet buildUrl = function(urlObj: UrlObject){\n\t\tlet url = \"\";\n\t\tif (urlObj.scheme && urlObj.host) {\n\t\t\turl += urlObj.scheme + \"://\";\n\t\t}\n\t\tif (urlObj.host) {\n\t\t\turl += urlObj.host;\n\t\t}\n\t\tif (urlObj.path) {\n\t\t\turl += \"/\" + urlObj.path;\n\t\t}\n\t\tif (urlObj.query) {\n\t\t\turl += \"?\" + urlObj.query;\n\t\t}\n\t\tif (urlObj.fragment) {\n\t\t\turl += \"#\" + urlObj.fragment;\n\t\t}\n\t\treturn url;\n\t};\n\n\tlet buildSegment = function(segment: string, remainingAvailableLength: number){\n\t\tlet remainingAvailableLengthHalf = remainingAvailableLength/ 2,\n\t\t\t\tstartOffset = Math.ceil(remainingAvailableLengthHalf),\n\t\t\t\tendOffset = (-1)*Math.floor(remainingAvailableLengthHalf),\n\t\t\t\tend = \"\";\n\t\tif (endOffset < 0) {\n\t\t\tend = segment.substr(endOffset);\n\t\t}\n\t\treturn segment.substr(0, startOffset) + ellipsisChars + end;\n\t};\n\tif (url.length <= truncateLen) {\n\t\treturn url;\n\t}\n\tlet availableLength = truncateLen - ellipsisLength;\n\tlet urlObj = parse_url(url);\n\t// Clean up the URL\n\tif (urlObj.query) {\n\t\tlet matchQuery = urlObj.query.match(/^(.*?)(?=(\\?|\\#))(.*?)$/i);\n\t\tif (matchQuery) {\n\t\t\t// Malformed URL; two or more \"?\". Removed any content behind the 2nd.\n\t\t\turlObj.query = urlObj.query.substr(0, matchQuery[1].length);\n\t\t\turl = buildUrl(urlObj);\n\t\t}\n\t}\n\tif (url.length <= truncateLen) {\n\t\treturn url;\n\t}\n\tif (urlObj.host) {\n\t\turlObj.host = urlObj.host.replace(/^www\\./, \"\");\n\t\turl = buildUrl(urlObj);\n\t}\n\tif (url.length <= truncateLen) {\n\t\treturn url;\n\t}\n\t// Process and build the URL\n\tlet str = \"\";\n\tif (urlObj.host) {\n\t\tstr += urlObj.host;\n\t}\n\tif (str.length >= availableLength) {\n\t\tif ((urlObj.host as string).length == truncateLen) {\n\t\t\treturn ((urlObj.host as string).substr(0, (truncateLen - ellipsisLength)) + ellipsisChars).substr(0, availableLength + ellipsisLengthBeforeParsing);\n\t\t}\n\t\treturn buildSegment(str, availableLength).substr(0, availableLength + ellipsisLengthBeforeParsing);\n\t}\n\tlet pathAndQuery = \"\";\n\tif (urlObj.path) {\n\t\tpathAndQuery += \"/\" + urlObj.path;\n\t}\n\tif (urlObj.query) {\n\t\tpathAndQuery += \"?\" + urlObj.query;\n\t}\n\tif (pathAndQuery) {\n\t\tif ((str+pathAndQuery).length >= availableLength) {\n\t\t\tif ((str+pathAndQuery).length == truncateLen) {\n\t\t\t\treturn (str + pathAndQuery).substr(0, truncateLen);\n\t\t\t}\n\t\t\tlet remainingAvailableLength = availableLength - str.length;\n\t\t\treturn (str + buildSegment(pathAndQuery, remainingAvailableLength)).substr(0, availableLength + ellipsisLengthBeforeParsing);\n\t\t} else {\n\t\t\tstr += pathAndQuery;\n\t\t}\n\t}\n\tif (urlObj.fragment) {\n\t\tlet fragment = \"#\"+urlObj.fragment;\n\t\tif ((str+fragment).length >= availableLength) {\n\t\t\tif ((str+fragment).length == truncateLen) {\n\t\t\t\treturn (str + fragment).substr(0, truncateLen);\n\t\t\t}\n\t\t\tlet remainingAvailableLength2 = availableLength - str.length;\n\t\t\treturn (str + buildSegment(fragment, remainingAvailableLength2)).substr(0, availableLength + ellipsisLengthBeforeParsing);\n\t\t} else {\n\t\t\tstr += fragment;\n\t\t}\n\t}\n\tif (urlObj.scheme && urlObj.host) {\n\t\tlet scheme = urlObj.scheme + \"://\";\n\t\tif ((str+scheme).length < availableLength) {\n\t\t\treturn (scheme + str).substr(0, truncateLen);\n\t\t}\n\t}\n\tif (str.length <= truncateLen) {\n\t\treturn str;\n\t}\n\tlet end = \"\";\n\tif (availableLength > 0) {\n\t\tend = str.substr((-1)*Math.floor(availableLength/2));\n\t}\n\treturn (str.substr(0, Math.ceil(availableLength/2)) + ellipsisChars + end).substr(0, availableLength + ellipsisLengthBeforeParsing);\n}\n\n\ninterface UrlObject {\n\tscheme?: string;\n\thost?: string;\n\tpath?: string;\n\tquery?: string;\n\tfragment?: string\n}"]}