{"id":975,"date":"2017-12-19T14:00:12","date_gmt":"2017-12-19T13:00:12","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=975"},"modified":"2022-07-25T08:35:45","modified_gmt":"2022-07-25T07:35:45","slug":"javascript-capitalize-all-lines","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/javascript-capitalize-all-lines\/","title":{"rendered":"Javascript: Capitalize all lines"},"content":{"rendered":"<pre lang=\"javascript\">       function capitalizeFirstLetters(str) {\r\n            var reEachLine = \/.*?\\s[^\\s\\.]+\\.\\s\/gi;\r\n            var reFirstLetter = \/^[^a-z]*?([a-z])\/gi;\r\n            var match = null;\r\n            var lines = [], line;\r\n            var from = 0, till = 0;\r\n            while(match = reEachLine.exec(str))\r\n            {\r\n                from = till;\r\n                till = match.index + match[0].length;\r\n                line = str.slice(from, till);\r\n                if (line.length &gt; 0)\r\n                    lines.push(line);\r\n            }\r\n\r\n            line = str.slice(till);\r\n            if (line.length &gt; 0)\r\n                lines.push(line);\r\n\r\n            for (var i = 0; i &lt; lines.length; i++) {\r\n                lines[i] = lines[i].replace(reFirstLetter, function(letter) {\r\n                        return letter.toUpperCase();\r\n                    });\r\n            }\r\n\r\n            var result = lines.join('');\r\n            if (result.length === str.length) {\r\n                return result;\r\n            }\r\n            return str;\r\n        }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>function capitalizeFirstLetters(str) { var reEachLine = \/.*?\\s[^\\s\\.]+\\.\\s\/gi; var reFirstLetter = \/^[^a-z]*?([a-z])\/gi; var match = null; var lines = [], line; var from = 0, till = 0; while(match = reEachLine.exec(str)) { from = till; till = match.index + match[0].length; line = str.slice(from, till); if (line.length &gt; 0) lines.push(line); } line = str.slice(till); if (line.length &gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[5,4],"tags":[],"class_list":["post-975","post","type-post","status-publish","format-standard","hentry","category-javascript","category-programming"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/975","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=975"}],"version-history":[{"count":1,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/975\/revisions"}],"predecessor-version":[{"id":976,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/975\/revisions\/976"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}