{"ScriptPreparationCode":"var text = \u0060Garena Free Fire\r\n\r\n\uD83D\uDCF1 Sobrevive al mejor Battle Royale dise\u00F1ado para m\u00F3viles.\r\n\uD83E\uDE82 50 jugadores caen en paraca\u00EDdas en un mapa donde deber\u00E1n enfrentarse para ser el \u00FAltimo en pie.\r\n\uD83D\uDC49 Disponible para Android, iOS y para PC y Mac con emulador.\r\n\r\n#FreeFire\r\n\r\nhttps://img.snibits.com/HYCVDi4\u0060","TestCases":[{"Name":"Original","Code":"const parse = (snippet) =\u003E {\r\n const isImage = (word) =\u003E {\r\n const pattern = /https:\\/\\/img\\.snibits\\.com\\/\\w/\r\n return word.match(pattern)\r\n }\r\n const isUrl = (word) =\u003E {\r\n const pattern = /https:\\/\\/\\w/\r\n return word.match(pattern)\r\n }\r\n const isTag = (word) =\u003E {\r\n const pattern = /#\\w/\r\n return word.match(pattern)\r\n }\r\n const isSpace = (word) =\u003E {\r\n const pattern = /https:\\/\\/snibits\\.com\\/space\\/\\w/\r\n return word.match(pattern)\r\n }\r\n const isYoutube = (word) =\u003E word.match(/https:\\/\\/youtu.be\\/\\w/)\r\n\r\n const getCleanedContent = (text) =\u003E {\r\n let imageCount = 0\r\n let url = null\r\n let content = text\r\n .split(\u0027\\n\u0027)\r\n .map((line) =\u003E\r\n line\r\n .split(/\\s/)\r\n .filter((word) =\u003E {\r\n if (isImage(word)) {\r\n imageCount\u002B\u002B\r\n }\r\n return !isImage(word) || imageCount \u003E 4\r\n })\r\n .join(\u0027 \u0027)\r\n )\r\n .join(\u0027\\n\u0027)\r\n .trim()\r\n let words = content.split(/\\s/)\r\n if (words.length \u003E 0) {\r\n const lastWord = words[words.length - 1]\r\n if ((isUrl(lastWord) \u0026\u0026 imageCount === 0) || isSpace(lastWord)) {\r\n const lines = content.split(\u0027\\n\u0027)\r\n let lastLine = lines[lines.length - 1].split(/\\s/)\r\n url = lastLine.pop()\r\n lines[lines.length - 1] = lastLine.join(\u0027 \u0027)\r\n content = lines.join(\u0027\\n\u0027).trim()\r\n }\r\n }\r\n return [content, url]\r\n }\r\n const [cleanedContent, url] = getCleanedContent(snippet.text)\r\n\r\n const getName = (snippet) =\u003E {\r\n let lines = cleanedContent.split(\u0027\\n\u0027)\r\n if (lines.length \u003E 0) {\r\n const line = lines[0].trim()\r\n if (line.length \u003C= 60 \u0026\u0026 ![\u0027.\u0027, \u0027:\u0027].includes(line[line.length - 1])) {\r\n return line\r\n }\r\n }\r\n return \u0027\u0027\r\n }\r\n const name = getName(snippet)\r\n\r\n const getTitle = (snippet) =\u003E {\r\n const limit = 60\r\n if (name) {\r\n return name\r\n }\r\n\r\n if (cleanedContent) {\r\n let title = cleanedContent.split(\u0027\\n\u0027)[0]\r\n if (title.length \u003E limit) {\r\n title = \u0060${title.substring(0, limit - 1)}\u2026\u0060\r\n }\r\n return title\r\n }\r\n\r\n return \u0027\u0027\r\n }\r\n const title = getTitle(snippet)\r\n\r\n const getImages = (snippet) =\u003E {\r\n return snippet.text\r\n .split(/\\s/)\r\n .filter((word) =\u003E isImage(word))\r\n .slice(0, 4)\r\n }\r\n const images = getImages(snippet)\r\n\r\n const getTags = (snippet) =\u003E {\r\n return snippet.text.split(/\\s/).filter((word) =\u003E isTag(word))\r\n }\r\n const tags = getTags(snippet)\r\n\r\n const getHtml = (snippet) =\u003E {\r\n const content = cleanedContent.replace(name, \u0027\u0027).trim()\r\n const limit = 27\r\n\r\n const parseWord = (word) =\u003E {\r\n if (isUrl(word)) {\r\n const url = word\r\n let displayUrl = word.replace(\u0027https://\u0027, \u0027\u0027)\r\n if (displayUrl.length \u003E limit) {\r\n displayUrl = \u0060${displayUrl.substring(0, limit - 1)}\u2026\u0060\r\n }\r\n return \u0060\u003Ca href=\u0022${url}\u0022 target=\u0022_blank\u0022 rel=\u0022nofollow\u0022 class=\u0022content-link\u0022\u003E${displayUrl}\u003C/a\u003E\u0060\r\n } else if (isTag(word)) {\r\n const tag = word.replace(\u0027#\u0027, \u0027\u0027)\r\n return \u0060\u003Ca href=\u0022/tag/${tag}\u0022\u003E#${tag}\u003C/a\u003E\u0060\r\n }\r\n return word\r\n }\r\n\r\n const parseLine = (line) =\u003E {\r\n const parsedLine = line.split(/\\s/).map((word) =\u003E parseWord(word))\r\n return parsedLine.join(\u0027 \u0027)\r\n }\r\n\r\n const lines = content.split(\u0027\\n\u0027)\r\n let parsedLines = lines.map((line) =\u003E parseLine(line))\r\n return parsedLines.join(\u0027\\n\u0027).trim()\r\n }\r\n const html = getHtml(snippet)\r\n\r\n const getCount = (snippet) =\u003E {\r\n const limit = 27\r\n const content = cleanedContent.replace(name, \u0027\u0027).trim()\r\n const lines = content.split(\u0027\\n\u0027)\r\n const parsedContent = lines\r\n .map((line) =\u003E\r\n line\r\n .split(/\\s/)\r\n .map((word) =\u003E {\r\n if (isUrl(word) || isImage(word)) {\r\n return \u0027x\u0027.repeat(limit)\r\n }\r\n return word\r\n })\r\n .join(\u0027 \u0027)\r\n )\r\n .join(\u0027\\n\u0027)\r\n\r\n return [...name].length \u002B [...parsedContent].length \u002B images.length * limit \u002B (url ? limit : 0)\r\n }\r\n const count = getCount(snippet)\r\n\r\n return { name, title, images, html, count, url, tags }\r\n}\r\n\r\n\r\nparse({text})","IsDeferred":false},{"Name":"Improved","Code":"const parse = (snippet) =\u003E {\r\n const isImage = (word) =\u003E {\r\n return word.startsWith(\u0027https://img.snibits.com/\u0027)\r\n }\r\n\r\n const isUrl = (word) =\u003E {\r\n return word.startsWith(\u0027https://\u0027)\r\n }\r\n\r\n const isTag = (word) =\u003E {\r\n return word.startsWith(\u0027#\u0027)\r\n }\r\n\r\n const isSpace = (word) =\u003E {\r\n return word.startsWith(\u0027https://snibits.com/space/\u0027)\r\n }\r\n\r\n const isLineName = (line) =\u003E {\r\n const words = line.split(/\\s/)\r\n const firstWord = words[0]\r\n const lastChar = line[line.length - 1]\r\n const isValidFirstWord =\r\n !isImage(firstWord) \u0026\u0026 !isUrl(firstWord) \u0026\u0026 !isTag(firstWord) \u0026\u0026 !isSpace(firstWord)\r\n if (isValidFirstWord \u0026\u0026 line.length \u003C= 60 \u0026\u0026 ![\u0027.\u0027, \u0027:\u0027].includes(lastChar)) {\r\n return true\r\n }\r\n return false\r\n }\r\n\r\n const extract = (text) =\u003E {\r\n const lines = text.trim().split(\u0027\\n\u0027)\r\n let name = null\r\n let url = null\r\n const images = []\r\n const processedLines = []\r\n const tags = []\r\n\r\n lines.forEach((line, indexLine) =\u003E {\r\n const words = line.trim().split(/\\s/)\r\n const resultLine = []\r\n words.forEach((word, indexWord) =\u003E {\r\n const isLastWord = indexLine === lines.length - 1 \u0026\u0026 indexWord === words.length - 1\r\n if (isImage(word) \u0026\u0026 images.length \u003C 4) {\r\n images.push(word)\r\n } else if (isLastWord \u0026\u0026 (isSpace(word) || (isUrl(word) \u0026\u0026 images.length === 0))) {\r\n url = word\r\n } else {\r\n resultLine.push(word)\r\n }\r\n\r\n if (isTag(word)) {\r\n tags.push(word)\r\n }\r\n })\r\n const processedLine = resultLine.join(\u0027 \u0027).trim()\r\n if (processedLines.length === 0 \u0026\u0026 processedLine.length \u003E 0 \u0026\u0026 isLineName(processedLine)) {\r\n name = processedLine\r\n } else {\r\n processedLines.push(processedLine)\r\n }\r\n })\r\n const content = processedLines.join(\u0027\\n\u0027).trim()\r\n return {\r\n images,\r\n url,\r\n name,\r\n tags,\r\n content,\r\n }\r\n }\r\n\r\n return extract(snippet.text)\r\n}\r\n\r\nparse({ text })\r\n","IsDeferred":false},{"Name":"With HTML","Code":"var text = \u0060Garena Free Fire\r\n\r\n\uD83D\uDCF1 Sobrevive al mejor Battle Royale dise\u00F1ado para m\u00F3viles.\r\n\uD83E\uDE82 50 jugadores caen en paraca\u00EDdas en un mapa donde deber\u00E1n enfrentarse para ser el \u00FAltimo en pie.\r\n\uD83D\uDC49 Disponible para Android, iOS y para PC y Mac con emulador.\r\n\r\n#FreeFire\r\n\r\nhttps://img.snibits.com/HYCVDi4\u0060\r\n\r\nconst parse = (snippet) =\u003E {\r\n const ULR_LIMIT = 27\r\n\r\n const isImage = (word) =\u003E {\r\n return word.startsWith(\u0027https://img.snibits.com/\u0027)\r\n }\r\n\r\n const isUrl = (word) =\u003E {\r\n return word.startsWith(\u0027https://\u0027)\r\n }\r\n\r\n const isTag = (word) =\u003E {\r\n return word.startsWith(\u0027#\u0027)\r\n }\r\n\r\n const isSpace = (word) =\u003E {\r\n return word.startsWith(\u0027https://snibits.com/space/\u0027)\r\n }\r\n\r\n const isLineName = (line) =\u003E {\r\n const words = line.split(/\\s/)\r\n const firstWord = words[0]\r\n const lastChar = line[line.length - 1]\r\n const isValidFirstWord =\r\n !isImage(firstWord) \u0026\u0026 !isUrl(firstWord) \u0026\u0026 !isTag(firstWord) \u0026\u0026 !isSpace(firstWord)\r\n if (isValidFirstWord \u0026\u0026 line.length \u003C= 60 \u0026\u0026 ![\u0027.\u0027, \u0027:\u0027].includes(lastChar)) {\r\n return true\r\n }\r\n return false\r\n }\r\n\r\n const parseHtmlWord = (word) =\u003E {\r\n if (isUrl(word)) {\r\n const url = word\r\n let displayUrl = word.replace(\u0027https://\u0027, \u0027\u0027)\r\n if (displayUrl.length \u003E limit) {\r\n displayUrl = \u0060${displayUrl.substring(0, limit - 1)}\u2026\u0060\r\n }\r\n return\r\n } else if (isTag(word)) {\r\n }\r\n return word\r\n }\r\n\r\n const extract = (text) =\u003E {\r\n const lines = text.trim().split(\u0027\\n\u0027)\r\n let name = null\r\n let url = null\r\n const images = []\r\n const processedLines = []\r\n const processedLinesHtml = []\r\n const tags = []\r\n\r\n lines.forEach((line, indexLine) =\u003E {\r\n const words = line.trim().split(/\\s/)\r\n const resultLine = []\r\n const resultLineHtml = []\r\n words.forEach((word, indexWord) =\u003E {\r\n const isLastWord = indexLine === lines.length - 1 \u0026\u0026 indexWord === words.length - 1\r\n if (isImage(word) \u0026\u0026 images.length \u003C 4) {\r\n images.push(word)\r\n } else if (isLastWord \u0026\u0026 (isSpace(word) || (isUrl(word) \u0026\u0026 images.length === 0))) {\r\n url = word\r\n } else {\r\n resultLine.push(word)\r\n }\r\n })\r\n\r\n const processedLine = resultLine.join(\u0027 \u0027).trim()\r\n if (processedLines.length === 0 \u0026\u0026 processedLine.length \u003E 0 \u0026\u0026 isLineName(processedLine)) {\r\n name = processedLine\r\n } else {\r\n processedLines.push(processedLine)\r\n resultLine.forEach((word, index) =\u003E {\r\n // HTML and tag detection\r\n if (isUrl(word)) {\r\n let displayUrl = word.replace(\u0027https://\u0027, \u0027\u0027)\r\n if (displayUrl.length \u003E ULR_LIMIT) {\r\n displayUrl = \u0060${displayUrl.substring(0, limit - 1)}\u2026\u0060\r\n }\r\n resultLineHtml.push(\r\n \u0060\u003Ca href=\u0022${word}\u0022 target=\u0022_blank\u0022 rel=\u0022nofollow\u0022 class=\u0022content-link\u0022\u003E${displayUrl}\u003C/a\u003E\u0060\r\n )\r\n } else if (isTag(word)) {\r\n tags.push(word)\r\n const slug = word.replace(\u0027#\u0027, \u0027\u0027)\r\n resultLineHtml.push(\u0060\u003Ca href=\u0022/tag/${slug}\u0022\u003E${word}\u003C/a\u003E\u0060)\r\n } else {\r\n resultLineHtml.push(word)\r\n }\r\n })\r\n processedLinesHtml.push(resultLineHtml)\r\n }\r\n })\r\n const content = processedLines.join(\u0027\\n\u0027).trim()\r\n const html = processedLinesHtml.join(\u0027\\n\u0027).trim()\r\n return {\r\n images,\r\n url,\r\n name,\r\n tags,\r\n content,\r\n html,\r\n }\r\n }\r\n\r\n return extract(snippet.text)\r\n}\r\n\r\nparse({ text })\r\n","IsDeferred":false}]}