This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const copyToClipboard = (text) => navigator.clipboard.writeText(text); | |
copyToClipboard("This Sring is Copied To Clipboard."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rgbToHex = (r, g, b) => "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); | |
rgbToHex(0, 51, 255); | |
// Result: #0033ff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dayDif = (date1, date2) => Math.ceil(Math.abs(date1.getTime() - date2.getTime()) / 86400000) | |
dayDif(new Date("2020-10-21"), new Date("2021-10-22")) | |
// Result: 366 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const randomHex = () => `#${Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, "0")}`; | |
console.log(randomHex()); | |
// Result: #92b008 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isWeekday = (date) => date.getDay() % 6 !== 0; | |
console.log(isWeekday(new Date(2021, 0, 11))); | |
// Result: true (Monday) | |
console.log(isWeekday(new Date(2021, 0, 10))); | |
// Result: false (Sunday) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const celsiusToFahrenheit = (celsius) => celsius * 9/5 + 32; | |
const fahrenheitToCelsius = (fahrenheit) => (fahrenheit - 32) * 5/9; | |
// Examples | |
celsiusToFahrenheit(15); // 59 | |
celsiusToFahrenheit(0); // 32 | |
celsiusToFahrenheit(-20); // -4 | |
fahrenheitToCelsius(59); // 15 | |
fahrenheitToCelsius(32); // 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isAppleDevice = /Mac|iPod|iPhone|iPad/.test(navigator.platform); | |
console.log(isAppleDevice); | |
// Result: will return true if user is on an Apple device |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const timeFromDate = date => date.toTimeString().slice(0, 8); | |
console.log(timeFromDate(new Date(2021, 0, 10, 17, 30, 0))); | |
// Result: "17:30:00" | |
console.log(timeFromDate(new Date())); | |
// Result: will log the current time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const stripHtml = html => (new DOMParser().parseFromString(html, 'text/html')).body.textContent || ''; | |
stripHtml('<h1>Hello <strong>World</strong>!!!</h1>'); | |
// Result: Hello World!!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const toggleElementDisplay = element => element.style.display = (element.style.display === "none" ? "block" : "none"); | |
toggleElementDisplay(document.body) | |
// Result: Page body should be invisible, if it was present before and on executing command again it should be toggled |
OlderNewer