diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6b665aa --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} diff --git a/README.md b/README.md index 6a44a8f..cc9d99a 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,15 @@ Feel free to explore, adapt, and contribute to any of these projects! --- -| # | Project Name | Image Preview | -| --- | ------------ | ----------------------- | -| 01 | [Todo List](https://github.com/jovdim/Micro-Projects-Collection/tree/main/to-do-list) | [Image](https://github.com/jovdim/Micro-Projects-Collection/blob/7c2ea2cb3c8a2123cf5dfa759921b17be623a875/to-do-list/preview-image.png) | -| 02 | [Digital Clock](https://github.com/jovdim/Micro-Projects-Collection/tree/main/to-do-list) | [Image](https://github.com/jovdim/Micro-Projects-Collection/blob/939c594a36bbb90880a1fd5e6662d23e6d5ff5d2/digital-clock/preview-image.png) | -| 03 | [Inspirational Quote Generator](https://github.com/jovdim/Micro-Projects-Collection/tree/main/inspirational-quotes-generator) | [Image](https://github.com/jovdim/Micro-Projects-Collection/blob/b280d8913d13e886f3089426177907bdf02838a9/inspirational-quotes-generator/preview-image.png) | -| 04 | [Calculator](https://github.com/jovdim/Micro-Projects-Collection/tree/main/calculator) | [Image](https://github.com/jovdim/Micro-Projects-Collection/blob/3bb05d405dcfa8e08a1bd4692d6b8c24b9273fb1/calculator/preview-image.png) | -| 05 | [Stopwatch](https://github.com/jovdim/Micro-Projects-Collection/tree/main/stopwatch) | [Image](https://github.com/jovdim/Micro-Projects-Collection/blob/dfaf078687f4bc314ce0fef478ce948045a79d62/stopwatch/preview-image.png) | +| # | Project Name | Image Preview | +| --- | ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | +| 01 | [Todo List](https://github.com/jovdim/Micro-Projects-Collection/tree/main/to-do-list) | [Image](https://github.com/jovdim/Micro-Projects-Collection/blob/7c2ea2cb3c8a2123cf5dfa759921b17be623a875/to-do-list/preview-image.png) | +| 02 | [Digital Clock](https://github.com/jovdim/Micro-Projects-Collection/tree/main/to-do-list) | [Image](https://github.com/jovdim/Micro-Projects-Collection/blob/939c594a36bbb90880a1fd5e6662d23e6d5ff5d2/digital-clock/preview-image.png) | +| 03 | [Inspirational Quote Generator](https://github.com/jovdim/Micro-Projects-Collection/tree/main/inspirational-quotes-generator) | [Image](https://github.com/jovdim/Micro-Projects-Collection/blob/b280d8913d13e886f3089426177907bdf02838a9/inspirational-quotes-generator/preview-image.png) | +| 04 | [Calculator](https://github.com/jovdim/Micro-Projects-Collection/tree/main/calculator) | [Image](https://github.com/jovdim/Micro-Projects-Collection/blob/3bb05d405dcfa8e08a1bd4692d6b8c24b9273fb1/calculator/preview-image.png) | +| 05 | [Stopwatch](https://github.com/jovdim/Micro-Projects-Collection/tree/main/stopwatch) | [Image](https://github.com/jovdim/Micro-Projects-Collection/blob/dfaf078687f4bc314ce0fef478ce948045a79d62/stopwatch/preview-image.png) | +| 06 | [Easy Format](https://github.com/syamjir/Micro-Projects-Collection/tree/e1061ed7f2364d1c2b9277435ece354f2244a6fb/easy-format) | [Image](https://github.com/syamjir/Micro-Projects-Collection/blob/e1061ed7f2364d1c2b9277435ece354f2244a6fb/easy-format/preview-image.png) | --- + We welcome contributions to the **Micro Projects** collection! If you'd like to contribute, please check out our [contributing guidelines](https://github.com/jovdim/Micro-Projects-Collection/blob/main/CONTRIBUTING.md) to get started. diff --git a/easy-format/.vscode/settings.json b/easy-format/.vscode/settings.json new file mode 100644 index 0000000..6b665aa --- /dev/null +++ b/easy-format/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} diff --git a/easy-format/app.js b/easy-format/app.js new file mode 100755 index 0000000..3a0a930 --- /dev/null +++ b/easy-format/app.js @@ -0,0 +1,82 @@ +"use strict"; + +// Take elements from the DOM +let inputEl = document.querySelector(".input"); +let resultEl = document.querySelector(".result"); +let allCButtonEl = document.querySelector(".allC"); +let copyButtonEl = document.querySelector(".copy"); +let resetButtonEl = document.querySelector(".reset"); +let allLButtonEl = document.querySelector(".allL"); +let firstCButtonEl = document.querySelector(".firstC"); +let startCButtonEl = document.querySelector(".startC"); +let boldButtonEl = document.querySelector(".bold"); +let italicButtonEl = document.querySelector(".italic"); + +// Space removal function +let spaceRemoveAll = function (word) { + return word.trim().replace(/\s+/g, " "); +}; + +// Function to capitalize all letters +let allCapitalize = function () { + let word = spaceRemoveAll(inputEl.value); + resultEl.value = word.toUpperCase(); +}; + +// Function to convert all letters to lowercase +let allLowercase = function () { + let word = spaceRemoveAll(inputEl.value); + resultEl.value = word.toLowerCase(); +}; + +// Function to capitalize the first letter of each word +let firstLetterCapitalize = function () { + let word = spaceRemoveAll(inputEl.value); + word = word.toLowerCase().split(" "); + let firstUpper = []; + for (let wd of word) { + firstUpper.push(wd.replace(wd[0], wd[0].toUpperCase())); + } + resultEl.value = firstUpper.join(" "); +}; + +// Function to capitalize the first letter of each sentence +let firstLetterOfSentenceCapital = function () { + let word = spaceRemoveAll(inputEl.value); + word = word.toLowerCase().split("."); + console.log(word); + let firstUpper = []; + for (let wd of word) { + wd = wd.trim(); + if (wd.length > 0) { + if (wd === word[0]) { + firstUpper.push(wd[0].toUpperCase() + wd.slice(1)); + } else { + firstUpper.push(" " + wd[0].toUpperCase() + wd.slice(1)); + } + } + } + resultEl.value = firstUpper.join("."); +}; + +// Function to copy the result to clipboard +let copyText = function () { + resultEl.select(); + document.execCommand("copy"); +}; + +// Function to reset all fields and styles +let resetAll = function () { + inputEl.value = ""; + resultEl.value = ""; + resultEl.classList.remove("bold"); + resultEl.classList.remove("italic"); +}; + +// Event handlers for button clicks +allCButtonEl.addEventListener("click", allCapitalize); +copyButtonEl.addEventListener("click", copyText); +resetButtonEl.addEventListener("click", resetAll); +allLButtonEl.addEventListener("click", allLowercase); +firstCButtonEl.addEventListener("click", firstLetterCapitalize); +startCButtonEl.addEventListener("click", firstLetterOfSentenceCapital); diff --git a/easy-format/index.html b/easy-format/index.html new file mode 100755 index 0000000..6d83daa --- /dev/null +++ b/easy-format/index.html @@ -0,0 +1,48 @@ + + +
+ + +